代码的解释
源代码
<?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>"
本文详细解析了DVWA中Command Injection high难度级别的PHP代码,涉及$_POST变量、isset()、trim()、array数组、str_replace()、php_uname()和stristr()函数的使用。讲解了如何检查用户输入、过滤非法字符、执行系统命令以及判断操作系统以防止无限ping等问题。
最低0.47元/天 解锁文章
415

被折叠的 条评论
为什么被折叠?



