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一下,之后返回以下内容,可以判 ...
随机推荐
- IAR_STM32_BootLoader
1.STM32 Bootloader与APP IROM中可以分成两个区域,起始代码运行地址为0x08000000,这是基本固定的,可以将IROM的0x08000000 ~ 0x08002000这8KB ...
- Mac OS终端利器 iTem2 配置大全
转载链接:https://www.cnblogs.com/diyxiaoshitou/p/9017413.html 之前一直使用 Mac OS 自带的终端,用起来虽然有些不太方便,但总体来说还是可以接 ...
- [Kafka][1][初识Kafka]
目录 第1章 初识Kafka 1.1 发布与订阅消息系统 1.1.1 如何开始 1.1.2 独立的队列系统 1.2 Kafka登场 1.2.1 消息和批次(Message and batch) 1.2 ...
- HBase高级特性、rowkey设计以及热点问题处理
在阐述HBase高级特性和热点问题处理前,首先回顾一下HBase的特点:分布式.列存储.支持实时读写.存储的数据类型都是字节数组byte[],主要用来处理结构化和半结构化数据,底层数据存储基于hdfs ...
- MathType输入几何符号的技巧
通过学习几何学的知识,我们发现其中包含的几何符号有很多,比如有表示图形的符号,如三角形,平行四边形,圆,角,圆弧等:还有表示位置关系的符号,如平行,垂直等:还有表示矢量等其他符号,那么MathType ...
- 9、Spring Boot安全
1.Spring Security简介 Spring Security是针对Spring项目的安全框架,也是Spring Boot底层安全模块默认的技术选型.他可以实现强大的web安全控制.对于安全控 ...
- NOIP2012 解题报告
TG Day1 T3 开车旅行 1. 预处理出从每座城市两人分别会到达的两座城市. 用 set 可以轻松实现. 2. 用倍增优化 DP 令 \(f_{i,j,k}\) 表示从城市 \(j\) 出发,行 ...
- Tarjan 算法总结
一些概念 连通:无向图中的任意两点都可以互相到达. 强连通:有向图中的任意两点都可以互相到达. 连通分量:无向图的极大连通子图. 强连通分量:有向图的极大强连通子图. DFS 生成树:对一张图(有向无 ...
- 使用Python过程出现的细节问题:TypeError: not enough arguments for format string
今天使用字符串格式化时,遇到的一点小问题:调用这个方法解释器出错了:TypeError: not enough arguments for format string def ll(name,age) ...
- Beta冲刺随笔——Day_Eight
这个作业属于哪个课程 软件工程 (福州大学至诚学院 - 计算机工程系) 这个作业要求在哪里 Beta 冲刺 这个作业的目标 团队进行Beta冲刺 作业正文 正文 其他参考文献 无 今日事今日毕 林涛: ...