dvwa靶场

dvwa靶场

Brute Force

(Low)

Brute Force,即暴力(破解),是指黑客利用密码字典,使用穷举法猜解出用户口令,是现在最为广泛使用的攻击手法之一。

法一:暴力破解

先随便输一个账号密码不能通过

此时我们进行抓包

通过BP利用字典爆破,得出密码

img

img

img
根据长度的不同可得知password为密码

(medium)

源码分析:
<?php
if( isset( $_GET[ 'Login' ] ) ) {
   
   
    // Sanitise username input
    $user = $_GET[ 'username' ];
    $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)) ? "" : ""));	
	//mysqli_real_escape_string()函数转义 SQL 语句中使用的字符串中的特殊字符(\x00、\n、\r、\、'、"、\x1a)
    // Sanitise password input
    $pass = $_GET[ 'password' ];
    $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 );	//md5加密

    // Check the 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
        echo "<p>Welcome to the password protected area {
     
     $user}</p>";
        echo "<img src=\"{
     
     $avatar}\" />";
    }
    else {
   
   
        // Login failed
        sleep( 2 );		//休眠2秒
        echo "<pre><br />Username and/or password incorrect.</pre>";
    }
    ((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}
?>

方法:

使用burpsuite抓包爆破

image-20220226220842994

image-20220226221214846

(high)

源码分析:
<?php
if( isset( $_GET[ 'Login' ] ) ) {
   
   
    // Check Anti-CSRF token
    checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );	//检查token值

    // 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 );	//md5加密

    // 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
        echo "<p>Welcome to the password protected area {
     
     $user}</p>";
        echo "<img src=\"{
     
     $avatar}\" />";
    }
    else {
   
   
        // Login failed
        sleep( rand( 0, 3 ) );	//随机休眠
        echo "<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();		//产生新token值
?>

方法:

使用burpsuite抓包爆破

image-20220226221458172

image-20220226221547202

Command Injection(命令执行)

用户可以执行恶意代码语句,在实战中危害比较高,也称作命令执行,一般属于高危漏洞。

打开页面是这样,框中让填入IP地址

(low)

命令连接符

command1 && command2 先执行command1后执行command2

command1 | command2 只执行command2

command1 & command2 先执行command2后执行command1

img
我们可以先ping一下 127.0.0.1

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xQzJexfc-1645887696877)(data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==)]

乱码

img[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uOgmSKT3-1645887696878)(data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==)]

img

查看源码

img

ip字段如果在IP后面加 ‘|’ 再添加一个命令,则会直接执行该命令。

此时输入windows命令即可

eg:

127.0.0.1 && dir  

img
DOS中符号总结
l & 组合命令

语法:第一条命令 & 第二条命令 [& 第三条命令…]

&、&&、||为组合命令,顾名思义,就是可以把多个命令组合起来当一个命令来执行。这在批处理脚本里是允许的,而且用的非常广泛。因为批处理认行不认命令数目。

这个符号允许在一行中使用 2 个以上不同的命令,当第一个命令执行失败了,也不影响后边的命令执行。

这里&两边的命令是顺序执行的,从前往后执行。

比如:

dir z:\ & dir y:\ & dir c:\

以上命令会连续显示 z,y,c 盘的内容,不理会该盘是否存在

l Command 1 | Command 2

“|”是管道符,表示将Command 1的输出作为Command 2的输入,并且只打印Command 2执行的结果。

l ; 分号

分号,当命令相同时,可以将不同目标用;来隔离,但执行效果不变,如执行过程中发生错误,则只返回错误报告,但程序仍会执行。

比如:

dir c:;d:;e:;z:\

以上命令相当于

dir c:\

dir d:\

dir e:\

dir f:\

如果其中 z 盘不存在,运行显示:系统找不到指定的路径。然后终止命令的执行。

例:dir c:;d:;e:\1.txt

以上命令相当于

dir c:\

dir d:\

dir e:\1.txt

其中文件 e:\1.txt 不存在,但 e 盘存在,有错误提示,但命令仍会执行。

为什么?如果目标路径不存在,则终止执行;如果路径存在,仅文件不存在,则继续执行。

(medium)

img

查看源码:

<?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>";
}

?>

DOS中&用法
这里需要注意的是”&&”与” &”的区别:

Command 1&&Command 2

先执行Command 1,执行成功后执行Command 2,否则不执行Command 2

Command 1&Command 2

先执行Command 1,不管是否成功,都会执行Command 2

分析:

服务器端对ip参数做了一定过滤,即把”&&” 、”;”删除,本质上采用的是黑名单机制,因此依旧存在安全问题。

因为被过滤的只有”&&”与” ;”,所以”&”不会受影响。

所以,我们输入

127.0.0.1&ipconfig

img

法二:由于使用的是str_replace把”&&” 、”;”替换为空字符,因此可以采用以下方式绕过:

127.0.0.1&;&ipconfig

经黑名单过滤后变成

127.0.0.1&&ipconfig尝试用以上两种方式执行dos命令:

127.0.0.1&dir

img

(high)

分析源码:
<?php

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

方法:

构造Poc验证利用

127.0.0.1 |ipconfig

image-20220226221937746

**代码审计:**增加了黑名单过滤的特殊符号,但是仍然可以通过等效符号进行代替绕过黑名单,达到命令执行的效果
**漏洞利用:**构造Poc与low安全级别一致,区别在于用等效的符号绕过黑名单(源码黑名单过滤|,却没有过滤|),同样达到命令执行的效果,拿webshell,连webshell管理工具,操作服务器

Cross Site Request Forgery (CSRF)

CSRF攻击是指利用受害者尚未失效的身份认证信息(cookie、会话等),诱骗其点击恶意链接或者访问包含攻击代码的页面,在受害人不知情的情况下以受害者的身份向(身份认证信息所对应的)服务器发送请求,从而完成非法操作(如转账、改密等)。

危害:

  1. 修改用户信息,如用户头像、发货地址等
  2. 个人隐私泄露,机密资料泄露
  3. 执行恶意操作,如修改密码,购买商品,转账等(盗用受害者身份,受害者能做什么攻击者就能以受害者身份)

(LOW)

1.查看源码img

$pass_new  = $_GET[ 'password_new' ];
$pass_conf = $_GET[ 'password_conf' ];
 
if( $pass_new == $pass_conf ):
    $insert = "UPDATE `users` SET password = '$pass_new' WHERE user = '" .     dvwaCurrentUser() . "';";

通过GET方式获取密码,两次密码一致的话,然后直接代入数据中修改密码。属于最基础的GET型CSRF。

http://127.0.0.1:8888/vulnerabilities/csrf/?password_new=admin&password_conf=admin&Change=Change#

img

img

此时我们再次用原密码登陆,发现密码错误

用新密码:admin

img

登陆成功

(medium)

分析源码:
<?php

if( isset( $_GET[ 'Change' ] ) ) {
   
   
    // Checks to see where the request came from
    if( stripos( $_SERVER[ 'HTTP_REFERER' ] ,$_SERVER[ 'SERVER_NAME' ]) !== false ) {
   
   	//stripos() 函数查找字符串(REFERER)在另一字符串中第一次出现的位置(不区分大小写)
        // 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 );	//md5加密

            // 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);
}
?>

加上了对用户请求头的中的Referer字段进行验证 即用户的请求头中的Referer字段必须包含了服务器的名字

if( stripos( $_SERVER
### 关于DVWA靶场的相关信息 #### DVWA简介 DVWA(Damn Vulnerable Web Application)是一个用于学习Web安全漏洞的PHP程序,旨在提供一个易受攻击的应用环境供用户测试和研究各种常见的Web应用漏洞[^1]。 #### DVWA模块与功能 DVWA包含了多个不同类型的漏洞模块,例如SQL注入、命令执行、跨站脚本攻击(XSS)、文件包含等。这些模块可以帮助使用者了解每种漏洞的工作原理以及防御方法[^2]。 #### 安装教程 为了搭建DVWA靶场,可以按照以下流程操作: 1. **下载并安装phpStudy** phpStudy是一款集成化的开发工具包,能够快速部署PHP运行环境。通过它来支持DVWA所需的服务器环境是非常方便的选择之一[^3]。 2. **获取DVWA源码** 可以从官方GitHub仓库下载最新版本的DVWA压缩包,具体地址如下: ```plaintext https://github.com/ethicalhack3r/DVWA/archive/v1.9.zip ``` 将其解压到本地指定路径,比如`D:\phpstudy_pro\WWW`目录下。 3. **数据库初始化** 启动phpMyAdmin界面,在其中创建一个新的MySQL数据库名为`dvwa`,并将下载好的DVWA项目中的SQL文件导入进去完成表结构建立工作[^4]。 4. **配置访问权限** 修改config.inc.php文件里的默认管理员密码以及其他必要的设置项以便顺利登录管理后台页面。 5. **启动服务端口监听** 打开浏览器输入类似这样的URL即可进入初始登陆页: ```plaintext http://localhost/DVWA/ ``` 以下是部分代码片段展示如何调整配置文件参数示例: ```php <?php // config.inc.php example configuration file. $DBMS = 'mysql'; // Database management system to use $db_server = '127.0.0.1'; $db_username = 'root'; $db_password = ''; // Set your own password here if needed $db_database = 'dvwa'; $_DVWA['db_user'] = $db_username; $_DVWA['db_password'] = $db_password; ?> ``` --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值