演示环境
dvwa靶场
Low
<?php if( isset( $_POST[ 'Submit' ] ) ){ $target = $_REQUEST[ 'ip' ]; if( stristr( php_uname( 's' ), 'Windows NT' ) ) { $cmd = shell_exec( 'ping' . $target ); } else { $cmd = shell_exec( 'ping -c 4' .$target ); } echo "<pre>{$cmd}</pre>"; } ?>
isset的作用是用来检查某一变量是否被定义并赋值,如果未定义或值为空,则返回false,否则返回true。
stristr的作用是从第一个即(php_uname( 's' ))中查找第二个即(’Windows NT‘)
此处表达为如果有’Windows NT‘则执行下面代码,否则else
php_uname()的作用是返回运行 PHP 的系统的有关信息。该函数主要用于获取服务器或操作系统的详细信息,如内核版本、处理器类型、操作系统类型和名称等。
这里php_uname( 's' )中s代表只取操作系统名称
if如果_post接收到了Submit这个值则true
获取IP
如果在查看系统名称php_uname( 's' )中查’Windows NT'则执行
ping
如果没有执行
ping -c 4 这里代表ping 4下
Medium
<?php if( isset( $_POST[ 'Submit' ] ) ) { // Get input $target = $_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>"; } ?>
array_keys
它用于获取数组中的所有键名。这里获取的就是'&&'和';'
str_replace
它用于替换字符串中的某些字符或子字符串。这里最后要将值存储到$target中
前面开始替换将
'&&'和';'替换为空
trim它用于删除字符串两侧的空白字符和其他预定义字符。
if如果_post接收到了Submit这个值则true
获取IP
定义两个(黑名单的制作)
分别为'&&' => ' ',为空
分别为';' => ' ',为空
array_keys获得键名,str_replace替换到$target中
如果在查看系统名称php_uname( 's' )中查’Windows NT'则执行
ping
如果没有执行
ping -c 4 这里代表ping 4下