- 本篇文章主要是记录 DVWA靶场中的 Medium和High难度的通关记录。
Brute Force
Medium
把它这个数据包看看,这个也没有啥,直接爆破。
字典太大了,难得等。根据它的lenth值确定对应账号和密码,正确的账号和密码它的lenth和其他的length长度不一样。
High
- High关卡就不一样了,观察下面的数据包,加上了user_token。
- 解决办法:
pikachu中的暴力破解关卡有这样一关,详解点击-> pikachu靶场中的token防爆破
Command Injection
Medium
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = $_REQUEST[ 'ip' ];
// Set blacklist
$substitutions = array(
'&&' => '',
';' => '',
);
// Remove any of the charactars in the array (blacklist).
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
echo "<pre>{$cmd}</pre>";
}
?>
分析:这个代码对 "&&"和";" 进行了过滤,但是像"&" 和 "||"并没有过滤
127.0.0.1&net user-->效果如下:
High
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = trim($_REQUEST[ 'ip' ]);
// Set blacklist
$substitutions = array(
'&' => '',
';' => '',
'| ' => '',
'-' => '',
'$' => '',
'(' => '',
')' => '',
'`' => '',
'||' => '',
);
// Remove any of the characters in the array (blacklist).
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
echo "<pre>{$cmd}</pre>";
}
?>
High关卡对于输入的符号过滤的比较充分,像 '&' , ';' , '| ', '-' , '$', '(' , ')', '`', '||'
等等这些符号都过滤了
解决办法:
- 1.刚开始我以为&&符号未被过滤,但是结果显示已经过滤。我认为原因应该是&&符号会被过滤,因为上面提示过会过滤"&"符号
- 2.仔细查看上述过滤代码,发现过滤的是'| '而不是'|',所以可以绕过。
- 127.0.0.1|net user 或者 127.0.0.1|calc
CSRF
Medidum
<?php
if( isset( $_GET[ 'Change' ] ) ) {
// Checks to see where the request came from
if( stripos( $_SERVER[ 'HTTP_REFERER' ] ,$_SERVER[ 'SERVER_NAME' ]) !== false ) {
// Get input
$pass_new = $_GET[ 'password_new' ];
$pass_conf = $_GET[ 'password_conf' ];
// Do the passwords match?
if( $pass_new == $pass_conf ) {
// They do!
$pass_new = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $pass_new ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
$pass_new = md5( $pass_new );
// Update the database
$insert = "UPDATE `users` SET password = '$pass_new' WHERE user = '" . dvwaCurrentUser() . "';";
$result = mysqli_query($GLOBALS["___mysqli_ston"], $insert ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' );
// Feedback for the user
echo "<pre>Password Changed.</pre>";
}
else {
// Issue with passwords matching
echo "<pre>Passwords did not match.</pre>";
}
}
else {
// Didn't come from a trusted source
echo "<pre>That request didn't look correct.</pre>";
}
((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);\
}
?>
可以看到,Medium级别的代码检查了保留变量 HTTP_REFERER(http包头的Referer参数的值,表示来源地址)中是否包含SERVER_NAME(http包头的Host参数,及要访问的主机名,这里是127.0.0.1),希望通过这种机制抵御CSRF攻击。
- 像上面所分析的那样,referer中必须包含主机名,这样 if条件判断才 !== ,执行if条件里面的内容。
High
high关卡主要是增加了token验证,(Token:保证用户每次的请求都是唯一的,Token随机生成,一段时间后便会失效)
File Inclusion
Medidum
`<?php
// 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,../,..\ 过滤,在一定程度上起到了防御作用。
绕过方法:
1.虽然过滤了上述符号,一定程度上起到了防御作用,但是可以通过双写的方式绕过过滤
2.如果知道网站的绝对路径,那么上述的代码过滤根本就没有作用了。
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;
}
?>
我们可以看到该代码写法还是过滤的比较严格,用户输入部分使用fnmatch()函数过滤,规定包含的文件名仅可以file开头,那么我们可以考虑通过伪协议 file 协议进行一个绕过
http://127.0.0.1/dvwa/vulnerabilities/fi/?page=file:////G:/user.txt
//注意dvwa很可能会报错:
//**Fatal error**: Call to undefined function fnmatch() in **E:\phpstudy\WWW\dvwa\vulnerabilities\fi\source\high.php** on line **9**
//解决办法:将下段代码加入high.php的首行
if(!function_exists('fnmatch')) {
function fnmatch($pattern, $string) {
return preg_match("#^".strtr(preg_quote($pattern, '#'),array('\*' => '.*', '\?'=> '.'))."$#i", $string);
} // end
} // end if
携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第1天,点击查看活动详情 >>