Command Injection(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
$html .= "<pre>{$cmd}</pre>";
}
?>
語句
if( stristr( php_uname( 's' ), 'Windows NT' ) )
PHP stristr() 函數
php_uname
函數 | 表達 |
---|---|
php_uname(‘s’) | 獲取服務器的操作環境 |
php_uname(‘n’) | 返回主機名 |
php_uname(‘r’) | 返回版本名稱 |
php_uname(‘v’) | 返回版本信息 |
php_uname(‘m’) | 返回機器類型 |
服務器通過判斷操作系統執行不同ping命令,但是對ip參數並未做任何的過濾,導致了嚴重的命令注入漏洞。
$cmd = shell_exec( 'ping ' . $target );
shell_exec
通過 shell 環境執行命令,並且將完整的輸出以字符串的方式返回。也就是說, PHP先運行一個shell環境, 然後讓shell進程運行你的命令, 並且把所有輸出已字符串形式返回, 如果程序執行有錯誤或者程序沒有任何輸出, 則返回null。
//函數用法
shell_exec ( string $cmd ) : string
漏洞利用
功能ping我們提供的IP,一般可用
;
|
||
&
&&
來連接命令執行
window和linux系統都可以用&&來執行多條命令
輸入 127.0.0.1&&net user