之前看了两天WAHH,看各种漏洞原理,但是渗透水平还是不知道怎么提高。干脆从代码审计开始,先从DVWA看起,看看有没有什么其它漏洞。
先看了主体架构,然后看各个子功能模块,在view_help.php中扫到如下代码:
$id = $_GET[ 'id' ];
$security = $_GET[ 'security' ];
ob_start();
eval( '?>' . file_get_contents( DVWA_WEB_PAGE_TO_ROOT . "vulnerabilities/{$id}/help/help.php" ) . '<?php ' );
$help = ob_get_contents();
ob_end_clean();
总觉得像是个可以注入的地方,但注了半天也没注出来。
后来发现file_get_contents总是先于eval执行,所以这地方根本不存在注入。
网上搜了下,搜到一篇发掘DVWA的其它漏洞的文章:
https://www.paulosyibelo.com/2014/09/dvwa-unintended-security-issues.html
原来这个地方最初版本的代码时这样的
这里存在一个任意文件读取漏洞:
id没有过滤,所以可以遍历路径,随后用00截断将后面的help都去除,那么就可以读取任意文件的代码了。
GitLens插件发现这行代码是这个人加的:
加了这几行代码就完美解决了这个文件读取漏洞。
ob_start();
eval( '?>' . file_get_contents( DVWA_WEB_PAGE_TO_ROOT . "vulnerabilities/{$id}/help/help.php" ) . '<?php ' );
$help = ob_get_contents();
ob_end_clean();
因为读取的php文件会被eval执行,执行的结果会用help缓存并输出,这样就不会暴露执行前的代码内容了。