跟bWAPP学WEB安全(PHP代码)--PHP代码注入

时间:2021-06-03 08:46:20

---恢复内容开始---

# 背景
***
***
今天我们换一个方式来分析这个漏洞,从渗透的角度去搞。

渗透过程



测试漏洞


先来看看,观察URL是:http://192.168.195.195/bWAPP/phpi.php

跟bWAPP学WEB安全(PHP代码)--PHP代码注入

message像是有链接,点击看看

跟bWAPP学WEB安全(PHP代码)--PHP代码注入

在查看url是http://192.168.195.195/bWAPP/phpi.php?message=test,GET型参数,burp扫一下

跟bWAPP学WEB安全(PHP代码)--PHP代码注入

感觉不对,怎么可能只有Flash跨域红红的,目测这个地方是echo xxxx,猜测代码:

<?php
echo $_GET["message"];
?>

可是这样哪里来的代码注入啊,难道message有问题,测试phpinfo(),果然有问题

跟bWAPP学WEB安全(PHP代码)--PHP代码注入

那就可以看代码了,执行message=system("cat phpi.php > phpi.txt") ,请求一下phpi.txt

跟bWAPP学WEB安全(PHP代码)--PHP代码注入

我们来看代码:

代码设计


<?php

if(isset($_REQUEST["message"]))
{ // If the security level is not MEDIUM or HIGH
if($_COOKIE["security_level"] != "1" && $_COOKIE["security_level"] != "2")
{ ?>
<p><i><?php @eval ("echo " . $_REQUEST["message"] . ";");?></i></p> <?php } // If the security level is MEDIUM or HIGH
else
{
?>
<p><i><?php echo htmlspecialchars($_REQUEST["message"], ENT_QUOTES, "UTF-8");;?></i></p> <?php } } ?>

卧槽,什么鬼竟然用了eval,这个可是执行代码内容的函数,类似的还有asset、preg_replace、call_user_func, call_user_func_array,array_map等等,这其中还包括thinkphp5-RCE的罪魁祸首函数哈哈。中级和高级过滤了,使用了htmlspecialchars函数就OK了