低级难度
首先看一下题目,说的是让我们输入一个IP,它会发起ping包,确实如此。
再来查看一下源代码
<?php
if( isset( $_POST[ 'submit' ] ) ) {
$target = $_REQUEST[ 'ip' ];
if (stristr(php_uname('s'), 'Windows NT')) {
$cmd = shell_exec( 'ping ' . $target );
echo '<pre>'.$cmd.'</pre>';
} else {
$cmd = shell_exec( 'ping -c 3 ' . $target );
echo '<pre>'.$cmd.'</pre>';
}
}
?>
大致意思是当我们输入一个IP之后它会做一个判断选择windows还是linux来做一个ping包动作,那么可以尝试构造语句尝试注入命令
中等难度
先来查看一下源代码
<?php
if( isset( $_POST[ 'submit' ] ) ) {
$target = $_REQUEST[ 'ip' ];
$substitutions = array(
'&&' => '',
';' => '',
);
if (stristr(php_uname('s'), 'Windows NT')) {
$cmd = shell_exec( 'ping ' . $target );
echo '<pre>'.$cmd.'</pre>';
} else {
$cmd = shell_exec( 'ping -c 3 ' . $target );
echo '<pre>'.$cmd.'</pre>';
}
}
?>
可以看到,跟低级难度相比,它只是过滤了 &&,;命令分割符
,但是过滤不够严格
高级难度
先来看一下源代码
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = trim($_REQUEST[ 'ip' ]);
// Set blacklist
$substitutions = array(
'&' => '',
';' => '',
'| ' => '',
'-' => '',
'$' => '',
'(' => '',
')' => '',
'`' => '',
'||' => '',
);
// 删除数组中的任何字符(黑名单)
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
// 确定操作系统并执行ping命令
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// 针对最终用户的反馈
echo "<pre>{$cmd}</pre>";
}
?>
难度有些大,参考了其他人的文章,找到一条答案,把”| ”
(注意这里|后有一个空格)替换为“|”
,于是 ”|”成了“漏网之鱼”。127.0.0.1|net user
不可能难度
先来看一下源代码
<?php
if( isset( $_POST[ 'submit' ] ) ) {
$target = $_REQUEST["ip"];
$target = stripslashes( $target );
// 将IP分割为4个八位字节
$octet = explode(".", $target);
// 检查每个二进制八位数是否为整数
if ((is_numeric($octet[0])) && (is_numeric($octet[1])) && (is_numeric($octet[2])) && (is_numeric($octet[3])) && (sizeof($octet) == 4) ) {
// 如果所有4个二进制八位数都是整数,则将IP重新组合在一起
$target = $octet[0].'.'.$octet[1].'.'.$octet[2].'.'.$octet[3];
// 确定操作系统并执行ping命令
if (stristr(php_uname('s'), 'Windows NT')) {
$cmd = shell_exec( 'ping ' . $target );
echo '<pre>'.$cmd.'</pre>';
} else {
$cmd = shell_exec( 'ping -c 3 ' . $target );
echo '<pre>'.$cmd.'</pre>';
}
}
else {
echo '<pre>ERROR: You have entered an invalid IP</pre>';
}
}
?>
确实,几乎不可能ಥ‿ಥ
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/134390.html