命令注入(Command Injection),是指通过提交恶意构造的参数破坏命令语句结构,从而达到执行恶意命令的目的。
Low级别
window和linux系统都可以用&&来执行多条命令
127.0.0.1 && net user
<?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
echo "<pre>{
$cmd}</pre>";
}
?>
相关函数:
stristr(string,search,before_search)
查找“search”在“string”中的第一次出现并返回字符串的剩余部分
before_search默认为“false”,如果设置为 “true”,它将返回 “search”第一次出现之前的字符串部分
php_uname (mode)
mode为单个字符
‘a’:此为默认。包含序列 “s n r v m” 里的所有模式。
‘s’:操作系统名称。
‘n’:主机名。
‘r’:版本名称。
‘v’:版本信息。
‘m’:机器类型。
Medium级别
127.0.0.1 & net user
127.0.0.1 &;& net user
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = $_REQUEST[ 'ip' ];
// Set blacklist
$substitutions =