文章更新於:2020-04-15
文件包含 File Inclusion
一、安全級別:Low
1.1、源碼
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
?>
1.2、攻擊
可以看出,源碼中沒有做任何防護,這意味着我們有可能能讀取到任意文件。
當我們在地址欄構造如下地址時:
http://home.cc/dvwa/vulnerabilities/fi/?page=../../../../../../etc/passwd
可以獲得密碼文件的內容:
包含遠程文件:
二、安全級別:Medium
2.1、源碼
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
// Input validation
$file = str_replace( array( "http://", "https://" ), "", $file );
$file = str_replace( array( "../", "..\"" ), "", $file );
?>
2.2、攻擊
從源碼可以看出,對 http
等字符進行了替換。
但大小寫卻沒有校驗。
所以我們可以:
三、安全等級:High
3.1、源碼
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
// Input validation
if( !fnmatch( "file*", $file ) && $file != "include.php" ) {
// This isn't the page we want!
echo "ERROR: File not found!";
exit;
}
?>
3.2、攻擊
源碼可以看出,
文件要麼是 file
開頭,
要麼是 include,php
,
否則報文件未找到錯誤。
那麼:
四、安全等級:Impossible
4.1、源碼
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
// Only allow include.php or file{1..3}.php
if( $file != "include.php" && $file != "file1.php" && $file != "file2.php" && $file != "file3.php" ) {
// This isn't the page we want!
echo "ERROR: File not found!";
exit;
}
4.2、攻擊
白名單過濾機制,
攻擊沒戲。