解题思路
打开网页,发现是一个博客,基本寻找博客挂载信息,源码等无果后,扫描后台。发现.git泄露
.git泄露
发现.git泄露后,使用Git Extract这款工具,可自动将源码clone到本地
发现flag.php和index.php
代码审计
<?php
include 'flag.php';
$yds = "dog";
$is = "cat";
$handsome = 'yds';
foreach($_POST as $x => $y){
$$x = $y;
}
foreach($_GET as $x => $y){
$$x = $$y;
}
foreach($_GET as $x => $y){
if($_GET['flag'] === $x && $x !== 'flag'){
exit($handsome);
}
}
if(!isset($_GET['flag']) && !isset($_POST['flag'])){
exit($yds);
}
if($_POST['flag'] === 'flag' || $_GET['flag'] === 'flag'){
exit($is);
}
echo "the flag is: ".$flag;
进行代码审计,共有三个结束条件,此时思路是构造其中一个结束条件,使其满足if中的内容。最后exit($flag),输出flag内容
第一个if
if($_GET['flag'] === $x && $x !== 'flag'){
exit($handsome);
判断get传过来键为flag的值是否等于flag,如果不等于,结束输出$handsome
第二个if
if(!isset($_GET['flag']) && !isset($_POST['flag'])){
exit($yds);
}
判断get和post都没有传输键为flag的内容,则结束输出$yds
第三个if
if($_POST['flag'] === 'flag' || $_GET['flag'] === 'flag'){
exit($is);
}
判断get和post都传输了键值都为flag的内容,则结束输出$is
解题
选取一个结束条件,这里选第二个if。
结束的参数为yds,所以这里我们get传入yds的键,值为flag
那么经过foreach后,$yds=$flag。即打到变量覆盖,yds的值覆盖为flag的内容,获取flag
总结思路
核心思路:
- 发现存在.git泄露
- 发现存在经典的foreach 和 $$ 变量覆盖漏洞
- 通过变量覆盖获取flag
知识点
- .git泄露
- 变量覆盖