赞
踩
打开题目,是一道PHP的代码审计。代码如下:
<?php highlight_file(__FILE__); include "./flag.php"; include "./result.php"; if(isset($_GET['aaa']) && strlen($_GET['aaa']) < 20){ $aaa = preg_replace('/^(.*)level(.*)$/', '${1}<!-- filtered -->${2}', $_GET['aaa']); if(preg_match('/pass_the_level_1#/', $aaa)){ echo "here is level 2"; if (isset($_POST['admin']) and isset($_POST['root_pwd'])) { if ($_POST['admin'] == $_POST['root_pwd']) echo '<p>The level 2 can not pass!</p>'; // START FORM PROCESSING else if (sha1($_POST['admin']) === sha1($_POST['root_pwd'])){ echo "here is level 3,do you kown how to overcome it?"; if (isset($_POST['level_3'])) { $level_3 = json_decode($_POST['level_3']); if ($level_3->result == $result) { echo "success:".$flag; } else { echo "you never beat me!"; } } else{ echo "out"; } } else{ die("no"); } // perform validations on the form data } else{ echo '<p>out!</p>'; } } else{ echo 'nonono!'; } echo '<hr>'; } ?>
分析代码,需要过三关,才能拿到flag。
/^(.*)level(.*)$/
得到$aaa
,再对$aaa
正则匹配,需匹配到pass_the_level_1#
;$_POST['admin'] == $_POST['root_pwd']
,且要通过判断sha1($_POST['admin']) === sha1($_POST['root_pwd'])
level_3
参数,经过json_decode()之后与内置的$result
变量弱类型比较相等(==)bypass:
(?s)
下 ,.
号将匹配所有字符,包括换行符;但默认情况下点号不匹配换行符,因此给了绕过(.*)
的可能。payload:%0apass_the_level_1%23
,%0a、%23分别是换行符、井号的URL编码。$_POST['admin'] == $_POST['root_pwd']
,再sha1($_POST['admin']) === sha1($_POST['root_pwd'])
时,null===null从而绕过。<?php
$key = "JsonTest";
if (isset($_GET['data'])) {
$data = json_decode($_GET['data']);
if ($data->key == $key) {
echo "Bypass json_decode()!";
} else {
echo "No...";
}
}
?>
因此最终payload:
.
https://johnfrod.top/ctf/2021-%E9%B9%A4%E5%9F%8E%E6%9D%AF/
https://www.mi1k7ea.com/2019/06/21/PHP%E5%BC%B1%E7%B1%BB%E5%9E%8B%E5%B0%8F%E7%BB%93/#0x09-json-decode
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。