2.4 File Inclusion 文件包含
2.4.1 low难度
源代码:
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
?>
可以看到low等级没有做任何过滤。首先尝试一下包含一个不存在的文件。
通过返回结果可以看到已经把网站的绝对路径给爆出来了。
利用文件上传加文件包含的组合拳来进行进一步操作。通过文件上传个图片马,然后通过文件包含执行该图片。
http://192.168.88.224/dvwa/vulnerabilities/fi/?page=/www/admin/localhost_80/wwwroot/phpinfo.php
2.4.2 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 );
?>
增加了str_replace函数,对page参数中的字符串进行了处理,但并不能进行有效的阻止,本地文件包含时使用绝对路径依然没有任何影响;远程文件包含时我们可以使用双写绕过这个替换规则,例如:hthttp://tp://,中间的http://被替换后依然保留了一个http://。当然我这里直接使用绝对路径,http的双写都不需要。
构造url:
http://192.168.88.224/dvwa/vulnerabilities/fi/page=/www/admin/localhost_80/wwwroot/phpinfo.php
2.4.3 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;
}
?>
从代码可以读出High级别使用了fnmatch函数检查page参数,只有 include.php 以及 file 开头的文件才会被包含。
因此,我们依然可以利用file协议绕过,进行本地文件包含:
http://192.168.88.224/vulnerabilities/fi/?page=file:///www/admin/localhost_80/wwwroot/phpinfo.php
2.5 File Upload 文件上传
2.5.1 low难度
核心源码:
<?php
if( isset( $_POST[ 'Upload' ] ) ) {
// Where are we going to be writing to?
$target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/";
$target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] );
// Can we move the file to the upload folder?
if( !move_uploaded_file( $_FILES[ 'uploaded' ][ 'tmp_name' ], $target_path ) ) {
// No
echo '<pre>Your image was not uploaded.</pre>';
}
else {
// Yes!
echo "<pre>{
$target_path} succesfully uploaded!</pre>";
}
}
?>
上传成功
用“菜刀”连接成功
2.5.2 Medium难度
核心源码:
<?php
if( isset( $_POST[ 'Upload' ] ) ) {
// Where are we going to be writing to?
$target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/";
$target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] );
// File information
$uploaded_name = $_FILES[ 'uploaded' ][ 'name' ];
$uploaded_type = $_FILES[ 'uploaded' ][ 'type' ];
$uploaded_size = $_FILES[ 'uploaded' ][ 'size' ];
// Is it an image?
if