High Level
查看源碼
<?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>"; } ?>
相比Medium級別的代碼,High級別的代碼進一步完善了黑名單,但由於黑名單機制的局限性,我們依然可以繞過。
漏洞利用
黑名單看似過濾了所有的非法字符,但仔細觀察到是把”| ”(注意這里|后有一個空格)替換為空字符,於是 ”|”成了“漏網之魚”。
127.0.0.1|net user
Command 1 | Command 2
“|”是管道符,表示將Command 1的輸出作為Command 2的輸入,並且只打印Command 2執行的結果。
總結
本等級漏洞的成因是開發人員在寫黑名單代碼時,由於粗心,在|后面多打了一個空格,致使|成為漏網之魚。
可用trim()函數解決這個問題,因為 trim(str) 可以刪除字符串左右兩邊的空格。
參考:https://www.freebuf.com/articles/web/116714.html