ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

DVWA之命令注入

2022-04-13 23:04:17  阅读:223  来源: 互联网

标签:target cmd ping DVWA 命令 Command && 执行 注入


DVWA之命令注入

 

LOW

老规矩先看下源码

<?php

if( isset( $_POST[ 'Submit' ]  ) ) {
    // Get input
    $target = $_REQUEST[ 'ip' ];

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

?>

 

ip参数没有做任何的过滤就直接放在shell_exec函数中执行了,执行语句为shell_exec( 'ping 127.0.0.1 && whami ')。(linux下使用whoami查看用户命令,windows使用net user)

这里对用户输入的ip并没有进行任何的过滤,所以我们可以进行命令执行漏洞

由于是在windows系统下的cmd中进行,所以我们一开始便用dir列出所有文件

利用| ipconfig获得本机的IP地址

利用dir列出所有文件

 

 

tips:

win10不支持通过ping用net user来查看用户

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

?>

查看源码,发现把”&&” 、”;”转为空,即删除
”&&”与” &”的区别:

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

输入” 192.168.2.3& dir”时,同样可以攻击,表明没有对”&”过滤,”&&”和”&”是有区别的,”&&”是短路运算符,只有前一步执行成功才会执行后一步,而”&”则两个表达式都会执行。

由以上waf可知,此waf只是过滤了 “&&”和”;”这两个特殊字符,所以,可以通过使用”&“,”|”,”||”绕过

可以用命令&dir查看

 

可以用命令&;&dir查看

 原理:在经过对;的过滤后,自动拼接成&&

High

先看源码

 1 <?php
 2 
 3 if( isset( $_POST[ 'Submit' ]  ) ) {
 4     // Get input
 5     $target = trim($_REQUEST[ 'ip' ]);
 6 
 7     // Set blacklist
 8     $substitutions = array(
 9         '&'  => '',
10         ';'  => '',
11         '| ' => '',    //仔细看|后有空字符,过滤不完全
12         '-'  => '',
13         '$'  => '',
14         '('  => '',
15         ')'  => '',
16         '`'  => '',
17         '||' => '',
18     );
19 
20     // Remove any of the characters in the array (blacklist).
21     $target = str_replace( array_keys( $substitutions ), $substitutions, $target );
22 
23     // Determine OS and execute the ping command.
24     if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
25         // Windows
26         $cmd = shell_exec( 'ping  ' . $target );
27     }
28     else {
29         // *nix
30         $cmd = shell_exec( 'ping  -c 4 ' . $target );
31     }
32 
33     // Feedback for the end user
34     echo "<pre>{$cmd}</pre>";
35 }
36 
37 ?>

此waf将”&”,”;”,”| ”,”-”,”$”,”(”,”)”,”`”,”||”这些字符直接全部转换成空格
仔细观察,可以发现”| ”中,| 后面有一个空字符,因此,可以使用”|”进行绕过

用命令“|dir"查询文件

想要对管道符有更多了解,请看这篇博客:管道符_夜飛雪的博客-CSDN博客_管道符

Impossible

先看源码

 1 <?php
 2 
 3 if( isset( $_POST[ 'Submit' ]  ) ) {
 4     // Check Anti-CSRF token
 5     checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );
 6 
 7     // Get input
 8     $target = $_REQUEST[ 'ip' ];
 9     $target = stripslashes( $target );
10 
11     // Split the IP into 4 octects
12     $octet = explode( ".", $target );
13 
14     // Check IF each octet is an integer
15     if( ( is_numeric( $octet[0] ) ) && ( is_numeric( $octet[1] ) ) && ( is_numeric( $octet[2] ) ) && ( is_numeric( $octet[3] ) ) && ( sizeof( $octet ) == 4 ) ) {
16         // If all 4 octets are int's put the IP back together.
17         $target = $octet[0] . '.' . $octet[1] . '.' . $octet[2] . '.' . $octet[3];
18 
19         // Determine OS and execute the ping command.
20         if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
21             // Windows
22             $cmd = shell_exec( 'ping  ' . $target );
23         }
24         else {
25             // *nix
26             $cmd = shell_exec( 'ping  -c 4 ' . $target );
27         }
28 
29         // Feedback for the end user
30         echo "<pre>{$cmd}</pre>";
31     }
32     else {
33         // Ops. Let the user name theres a mistake
34         echo '<pre>ERROR: You have entered an invalid IP.</pre>';
35     }
36 }
37 
38 // Generate Anti-CSRF token
39 generateSessionToken();
40 
41 ?>

stripslashes(string) : 该函数会删除字符串string中的反斜杠,返回已剥离反斜杠的字符串。
explode(separator,string,limit): 该函数把字符串打散为数组,返回字符串的数组。参数separator规定在哪里分割字符串,参数string是要分割的字符串,可选参数limit规定所返回的数组元素的数目。
is_numeric(string): 该检测string是否为数字或数字字符串,如果是返回TRUE,否则返回FALSE。
可以看到,Impossible级别的代码加入了Anti-CSRF token,同时对参数ip进行了严格的限制,只有诸如“数字.数字.数字.数字”的输入才会被接收执行,因此不存在命令注入漏洞。

标签:target,cmd,ping,DVWA,命令,Command,&&,执行,注入
来源: https://www.cnblogs.com/Rammstein-and-rock/p/16138287.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有