zoukankan      html  css  js  c++  java
  • 跟bWAPP学WEB安全(PHP代码)--XPath注入

    XML/Xpath注入



    看了下,A2里面是认证与会话管理的破坏或称之为绕过,没有特别要写的,很多就是小问题,可能会将这类问题放在最后写一下。一篇博客,这里还是更多的着重在能够获取信息或者服务器权限的漏洞上。还是来讲讲Xpath注入吧,其本质与SQL注入一致,但是其注入拼接的语言不是SQL而是Xpath,仅此而已。防御也很简单,我以前博客里面也提到过,过滤关键字或特殊字符即可。

    黑盒测试



    burp的scanner扫描



    Payload:harry' or true() or ''='o (不严格依照图片)

    Payload分析


    假设XML组织结构如下:

    <users>
        <user>
    
            <firstname>Tom</firstname>
    
            <lastname>Riddle</lastname>
    
            <loginID>voldemort</loginID>
    
            <password>harrypotter</password>
    
        </user>
        ...
    <users>
    

    我们先来看下正常的一个登陆过程//users/user1[loginID/text()='voldemort'and password/text()='harrypotter'] 这样检索才能登陆成功,但是

    #注入的情况
    //users/user1[loginID/text()='voldemort' and password/text()='harry’ or true() or ''='o'] 
    password的判断成为0 or 1 or 0  或运算一真则真,所以认证通过。
    

    搜索的情况


    Horror'or'1'='1
    Horror'or'1'='2
    


    bWAPP源码分析:



    function xmli($data)
    {
    
        if(isset($_COOKIE["security_level"]))
        {
    
            switch($_COOKIE["security_level"])
            {
    
                case "0" :
    
                    $data = no_check($data);
                    break;
    
                case "1" :
    
                    $data = xmli_check_1($data);
                    break;
    
                case "2" :
    
                    $data = xmli_check_1($data);
                    break;
    
                default :
    
                    $data = no_check($data);
                    break;
    
            }
    
        }
    
        return $data;
    
    }
    
    
    function xmli_check_1($data)
    {
    
        // Replaces dangerous characters: ( ) = ' [ ] : , * / WHITESPACE
        $input = str_replace("(", "", $data);
        $input = str_replace(")", "", $input);
        $input = str_replace("=", "", $input);
        $input = str_replace("'", "", $input);
        $input = str_replace("[", "", $input);
        $input = str_replace("]", "", $input);
        $input = str_replace(":", "", $input);
        $input = str_replace(",", "", $input);
        $input = str_replace("*", "", $input);
        $input = str_replace("/", "", $input);
        $input = str_replace(" ", "", $input);
    
        return $input;
    
    }
    //当然搜索的时候还有其他防御方法
    $result = $xml->xpath("//hero[contains(genre, '$genre')]/movie");
    

    做好过滤就可以防御了

  • 相关阅读:
    Python-dict与set
    Python-实现对表插入百万条数据
    Python—元组tuple
    数据库查询
    python-操作MySQL数据库
    Python-类的继承
    Python-内置类属性
    Python-类的概念及使用1
    Python异常处理
    了解dto概念,什么是DTO
  • 原文地址:https://www.cnblogs.com/KevinGeorge/p/10299607.html
Copyright © 2011-2022 走看看