ThinkPHP v5.0 rce 分析
ThinkPHP 5.*存在一处由于路由解析缺陷导致的代码执行漏洞。该漏洞危害程度非常高,默认环境配置即可导致远程代码执行。
- 本次测试环境
ThinkPHP 5.0.20
RCE复现
![image-20200221124859301](C:\Users\Mr. j\AppData\Roaming\Typora\typora-user-images\image-20200221124859301.png)
代码分析
首先看取路由的函数
pathinfo,path
漏洞文件
/thinkphp/library/think/Request.php:384
1 | /** |
这里获取pathinfo
后只进行了简单的字符串操作。又由于
下图
![image-20200221171234408](C:\Users\Mr. j\AppData\Roaming\Typora\typora-user-images\image-20200221171234408.png)
所以s-->var_pathinfo-->pathinfo
。
又pathinfo
函数被library/think/Request.php:416
中的path函数调用:
1 | /** |
由于
$this->path
源自pathinfo
,因此可以被攻击者控制。继续分析该变量的传递,在/thinkphp/library/think/App.php:619
中被引用:
1 | /** |
我们可以看到调用parseUrl函数处理传入的path参数
/thinkphp/library/think/App.php:166
1 |
|
最后分割为 模块---控制器---操作
的格式。
然后参数传递。
/thinkphp/library/think/App.php:553
1 | // 获取控制器名 |
/thinkphp/library/think/Loader.php:580
1 | /** |
这里通过invokeMethod
函数动态调用方法,可以看到$controller
是控制器\think\app
,$actionName
是invokefunction
1 | public static function action($url, $vars = [], $layer = 'controller', $appendSuffix = false) |
实例化控制器
/thinkphp/library/think/Loader.php:474
1 | /** |
POC分析
http://192.168.222.131/www/public/?s=/Index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=-1
- 分析
pathinfo()
函数的时候了解到可以用s
来获取路由信息 parseUrl
方法分割url为[模块/控制器/操作]
格式- 传入
$controller
的时候,就是开始我们获取到路由的值,但是用反斜杠就开头,就是想要实例化的类 - 最后是反射函数,调用了
invokefunction
方法执行phpinfo()