我使用DVWA是为了了解安全漏洞。在命令注入的部分,如下所示,后端代码是:

<?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,那么代码应该用''代替||,这样注入就不能工作了。尽管令我惊讶的是,注入产生了文件的输出,如下所示:

发布于 2016-12-25 22:12:22
只有一个小陷阱和你的替代阵列..。您需要在单字符之前定义双字符的替换,而需要在单字符之前定义双字符。这是个有趣的小怪事!
所以你的数组
// Set blacklist
$substitutions = array(
'&' => '',
';' => '',
'| ' => '',
'-' => '',
'$' => '',
'(' => '',
')' => '',
'`' => '',
'||' => '',
); 应该是
// Set blacklist
$substitutions = array(
'&' => '',
';' => '',
'||' => '',
'| ' => '',
'-' => '',
'$' => '',
'(' => '',
')' => '',
'`' => '',
);https://stackoverflow.com/questions/41319561
复制相似问题