代码审计
打开dvwa靶场,把难度设置为high,然后进入“命令执行”漏洞靶场



<?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>";
}
?&g

文章讲述了如何在PHP代码审计过程中发现并分析一个命令执行漏洞,通过实例展示了如何利用str_replace、stristr等函数进行输入验证,以及php_uname获取系统信息的过程。
最低0.47元/天 解锁文章
2005

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



