DVWA笔记之二:Command Injection
2017-08-11 11:50
423 查看
命令注入
1.Low级别
<?php
if( 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>";
}
?>
没有增加任何过滤,可以直接执行命令。这里讲一下Linux中的管道 |
用法: command 1 | command 2 他的功能是把第一个命令command 1执行的结果作为command 2的输入传给command 2,
当然&&也可以执行,";"也可以执行
2.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>";
}
?>
从过滤函数入手,str_replace只是把;和&&符号过滤成'',而对单个&符号并不会进行处理,因此可以交叉使用
构造 &;& ,这样它就会把;过滤掉过滤之后就变成了&&,从而可以进行命令的执行,此时Payload为 127.0.0.1 &;& uname -a
3.HIGH级别
这次过滤的就比较丰富,基本上各种可能存在执行的命令字符都已经过滤掉了
但是有个细节,在过滤|时后面多出来一个空格,因此还是要细心的才能发现,直接使用管道|进行
4.Impossible级别
相关函数介绍
stripslashes(string)
stripslashes函数会删除字符串string中的反斜杠,返回已剥离反斜杠的字符串。
explode(separator,string,limit)
把字符串打散为数组,返回字符串的数组。参数separator规定在哪里分割字符串,参数string是要分割的字符串,可选参数limit规定所返回的数组元素的数目。
is_numeric(string)
检测string是否为数字或数字字符串,如果是返回TRUE,否则返回FALSE。
可以看到,Impossible级别的代码加入了Anti-CSRF token,同时对参数ip进行了严格的限制,只有诸如“数字.数字.数字.数字”的输入才会被接收执行,因此不存在命令注入漏洞。
1.Low级别
<?php
if( 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>";
}
?>
没有增加任何过滤,可以直接执行命令。这里讲一下Linux中的管道 |
用法: command 1 | command 2 他的功能是把第一个命令command 1执行的结果作为command 2的输入传给command 2,
当然&&也可以执行,";"也可以执行
2.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>";
}
?>
从过滤函数入手,str_replace只是把;和&&符号过滤成'',而对单个&符号并不会进行处理,因此可以交叉使用
构造 &;& ,这样它就会把;过滤掉过滤之后就变成了&&,从而可以进行命令的执行,此时Payload为 127.0.0.1 &;& uname -a
3.HIGH级别
这次过滤的就比较丰富,基本上各种可能存在执行的命令字符都已经过滤掉了
但是有个细节,在过滤|时后面多出来一个空格,因此还是要细心的才能发现,直接使用管道|进行
4.Impossible级别
相关函数介绍
stripslashes(string)
stripslashes函数会删除字符串string中的反斜杠,返回已剥离反斜杠的字符串。
explode(separator,string,limit)
把字符串打散为数组,返回字符串的数组。参数separator规定在哪里分割字符串,参数string是要分割的字符串,可选参数limit规定所返回的数组元素的数目。
is_numeric(string)
检测string是否为数字或数字字符串,如果是返回TRUE,否则返回FALSE。
可以看到,Impossible级别的代码加入了Anti-CSRF token,同时对参数ip进行了严格的限制,只有诸如“数字.数字.数字.数字”的输入才会被接收执行,因此不存在命令注入漏洞。
相关文章推荐
- DVWA-1.9系列操作之Command Injection
- 设计模式笔记--行为型模式之二--Command
- DVWA(V1.10)中Command Injection的high等级绕过
- the linux command line学习笔记之二
- DVWA 之命令注入(Command Injection)
- DVWA-1.9全级别教程之Command Injection
- DVWA - Command Injection (low, medium, high)
- Kali下利用XAMPP搭建DVWA及使用command injection
- –DVWA-command injection
- 离开图形界面的那些日子 之二:Oracle 11.2.0.3 instance & database upgrade by Command Line
- PHP面向对象学习笔记之二 生成对象的设计模式
- Performance Testing Guidance学习笔记之二
- ThinAPP笔记之二:使用ThinAPP将应用程序打包
- JAVA学习笔记之二(对象)
- 设计模式C++学习笔记之二(Proxy代理模式)
- Windows Phone 开发笔记 (2) Command
- 设计模式笔记(8 CHAIN OF RESPONSIBILITY & COMMAND)
- Mybatis学习笔记之二:在项目中使用Mybatis
- java学习笔记2:对象的"引用"之二
- Java NIO学习笔记之二-图解ByteBuffer