<?php
if( isset( $_POST[ 'Submit' ] ) ) {
//判断post提交的值是否为空。
// Get input
$target = trim($_REQUEST[ 'ip' ]);
//设置黑名单
// Set blacklist
$substitutions = array(
'&' => '',
';' => '',
'| ' => '',
'-' => '',
'$' => '',
'(' => '',
')' => '',
'`' => '',
'||' => '',
); //定义$substitutions=数组
// Remove any of the charactars in the array (blacklist)./删除数组中的任何字符(黑名单)。
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
//将数组中设置的值替换
// Determine OS and execute the ping command.
//判断操作系统,执行ping命令
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
//忽略大小写查看当前运行php的系统版本是否为Windows
$cmd = shell_exec( 'ping ' . $target );
} //如果是则执行cmd进行ping
else {
//否则
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}执行ping 4下
// Feedback for the end user
echo "<pre>{$cmd}</pre>";
} //保留原有格式,最后输出ping的值
impossible难度的命令执行
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
//判断post提交的值是否为空
checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );
//检查令牌(接收传参用户令牌并建立连接)
$target = $_REQUEST[ 'ip' ];
//接收前端传送的ip
$target = stripslashes( $target );
//去除函数的反斜杆
$octet = explode( ".", $target );
//使用一个字符串分割另一个字符串用.和ip地址进行拼接
if( ( is_numeric( $octet[0] ) ) && ( is_numeric( $octet[1] ) ) && ( is_numeric( $octet[2] ) ) && ( is_numeric( $octet[3] ) ) && ( sizeof( $octet ) == 4 ) ) {
$target = $octet[0] . '.' . $octet[1] . '.' . $octet[2] . '.' . $octet[3];
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
//判断操作系统,执行ping命令
$cmd = shell_exec( 'ping ' . $target );
} //运行ping命令
else {
//则
$cmd = shell_exec( 'ping -c 4 ' . $target );
} //ping4 次
echo "<pre>{$cmd}</pre>";
//输出ping的结果
}
else {
//则
echo '<pre>ERROR: You have entered an invalid IP.</pre>';
} //输出您输入的IP地址错误
}
generateSessionToken();
//生成会话令牌
?>