2016-12-25 16 views
0

私は、セキュリティ上の脆弱性について学ぶためにDVWAを使用しています。私の理解からコマンドインジェクションDVWA難易度

enter image description here

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

?> 

私が入力|| lsとして与える場合、コードは''||を置き換える必要がありますので、注射はいけない:コマンドインジェクションの一部には以下に示すように、バックエンドのコードがあります作業。下図のように私の驚きに、注射は、ファイルの出力を生成働いたものの:

After

+0

ただ一つの小さなトラップであるべき||前|単一の文字の前に二重の文字を置き換える必要があるためです。それは面白い小さな変わったものです! – TimBrownlaw

+0

@TimBrownlaw答えとして入力して喜んで受け入れるならば:) –

+0

私は答えを作成しました:)乾杯 – TimBrownlaw

答えて

0

ただ一つの小さなトラップを交換用のアレイで...あなたは定義する必要があります||前|単一の文字の前に二重の文字を置き換える必要があるためです。それは面白い小さな変わったものです!

だからあなたの配列は

// Set blacklist 
$substitutions = array(
    '&' => '', 
    ';' => '', 
    '| ' => '', 
    '-' => '', 
    '$' => '', 
    '(' => '', 
    ')' => '', 
    '`' => '', 
    '||' => '', 
); 

は...あなたが定義する必要があなたの交換アレイに

// Set blacklist 
$substitutions = array(
    '&' => '', 
    ';' => '', 
    '||' => '', 
    '| ' => '', 
    '-' => '', 
    '$' => '', 
    '(' => '', 
    ')' => '', 
    '`' => '', 
);