DVWA 靶场全通关

爆破

low等级

image-20251206100231318

在burp中选择集群炸弹攻击

image-20251206102504882

给需要爆破的参数添加payload

image-20251206104029714

配置爆破需要的字典

image-20251206102611487

可以看到爆破成功,账号密码为admin password

image-20251206105237038

image-20251206105329411

比较有意思的是,这里爆破的时候在里面插入了万能密码 admin'or''=',不管你密码输入什么都是成功登录的。

image-20251206105431111

medium

将难度调为medium image-20251206105457876

账号密码都是一样的

image-20251206105555534

阅读源码可知

  • 作用:当登录失败时,服务器会强制暂停 2 秒。
  • 影响:这极大地降低了暴力破解的速度。如果攻击者尝试爆破 1000 个密码,原本可能只需要几秒钟,现在至少需要 2000 秒(约 33 分钟)。这使得在线暴力破解变得非常低效。
<?php
else {
    // Login failed
    sleep( 2 ); // <--- 关键点
    $html .= "<pre><br />Username and/or password incorrect.</pre>";
}

high

image-20251206110626001

<?php

if( isset( $_GET[ 'Login' ] ) ) {
	// Check Anti-CSRF token
	checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );

	// Sanitise username input
	$user = $_GET[ 'username' ];
	$user = stripslashes( $user );
	$user = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $user ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));

	// Sanitise password input
	$pass = $_GET[ 'password' ];
	$pass = stripslashes( $pass );
	$pass = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"],  $pass ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
	$pass = md5( $pass );

	// Check database
	$query  = "SELECT * FROM `users` WHERE user = '$user' AND password = '$pass';";
	$result = mysqli_query($GLOBALS["___mysqli_ston"],  $query ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' );

	if( $result && mysqli_num_rows( $result ) == 1 ) {
		// Get users details
		$row    = mysqli_fetch_assoc( $result );
		$avatar = $row["avatar"];

		// Login successful
		$html .= "<p>Welcome to the password protected area {$user}</p>";
		$html .= "<img src=\"{$avatar}\" />";
	}
	else {
		// Login failed
		sleep( rand( 0, 3 ) );
		$html .= "<pre><br />Username and/or password incorrect.</pre>";
	}

	((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}

// Generate Anti-CSRF token
generateSessionToken();

?>

阅读完源码发现high等级会检查登录用户的token和网站生成的 session-token是不是一样的,且每次登陆服务端都会生成一个新的token以防止csrf攻击。

想要爆破token的话,就得先从上一个请求的响应中提取token(因为验证机制就是先验证token后在响应中更换token)

服务器 Session 里先有 token_A(此时有效)
        ↓
用户提交请求(带 token_A)
        ↓
服务器验证:token_A 是否匹配? → 通过
        ↓
服务器生成 token_B,并放在响应页面里(但暂时不生效)
        ↓
Burp 提取 token_B
        ↓
用户下一次提交请求(带 token_B)
        ↓
服务器“此时”才把 token_B 视为当前有效 token

使用草叉攻击(不同的payload用不同的字典),将passwordanti-token设置payload

image-20251206112852734

给密码配置字典文件

image-20251206113124968

配置anti-token的payload时先勾选检索提取,设置参数提取,即每次都要提取数据包中的token值

image-20251206113107734

image-20251206114103252

一定要选择总是跟随重定向,不跟随重定向的话burp只能看到302页面,无法获取到新的token值

image-20251206114136543

设置第二个payload参数,选择payload类型为递归查找,也就是找每次的token值作为这个payload,然后点开始攻击

image-20251206114323416

找到那个唯一不同的长度点开响应看看发现成功爆破

image-20251206123522063

dvwa 命令执行

low等级

首先学习一下linux命令连接符

& :前面一个命令无论是否执行,后面的命令都能执行,两个命令都执行
&&:前面一个命令执行成功后,才能执行后面一个命令,两个命令都执行
|:前面一个命令无论是否执行,后面的命令都能执行且只执行后面一个
||:前面一个命令不能正常执行后,才能执行后面一个命令
127.0.0.1 && ls

可以看到命令成功执行

image

medium等级

首先看一下源码,可以看到给 &&;置空了,那么就得想办法绕过

<?php

if( isset( $_POST[ 'Submit' ]  ) ) {
	// Get input
	$target = $_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
	$html .= "<pre>{$cmd}</pre>";
}

?>

这里我们就用 |连接符号绕过

127.0.0.1 | ls

image

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
	$html .= "<pre>{$cmd}</pre>";
}

?>

127.0.0.1 |ls
posted @ 2025-12-06 12:38  朱迪Judy  阅读(0)  评论(0)    收藏  举报