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 Boot优雅地处理404异常
背景 在使用SpringBoot的过程中,你肯定遇到过404错误.比如下面的代码: @RestController @RequestMapping(value = "/hello" ...
- 练习启动各种浏览器的同时加载插件:Firefox, Chrome, IE
# -*- coding:utf-8 -*-import osimport seleniumfrom selenium import webdriverfrom selenium.webdriver. ...
- SQL Server 数据库bak备份文件还原操作和mdf文件附加操作
前言:现在任何软件都离不开数据的支持,数据的价值是无价的,因此数据目前显得尤为重要,日常软件生产库的数据定时或实时备份必不可少,备份出的文件也需要进行验证,下边我将介绍SQL Server数据的的备份 ...
- 基于tcp的socket通信
# socket # socekt是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口.在设计模式中,socket其实就是一个门面模式,它 # 把复杂的tcp/ip协议族隐藏在socket接 ...
- Python 调用Get接口
import requests,jsonurl = 'http://localhost:30627/api/jobs/GetNuberId?id=2'req = requests.get(url)re ...
- Zabbix监控笔记
了解zabbix,有必要了聊一下监控系统相关内容 企业中常用的开源监视系统目前有 cacti.Nagios.Open-Falcon.zabbix.prometheus等 使用监控系统的目的在于 /1. ...
- EasyRecovery——信息时代的“后悔药”
前几日,小编在豆瓣潜水的时候看到这么一个帖子,说是一对小情侣吵架,女方一气之下把男方的博士论文和资料全删了,求一个办法让男友消气. 站在吃瓜的角度,小编和广大群众看法一致,希望两人直接分手,放男方一条 ...
- 有什么数据恢复软件可以恢复CF数据
虽然现在SD卡出现并且日益流行,但是CF卡(Compact Flash)作为一种存储设备,仍然是专业数码相机的主流标准.不仅是数码相机,CF接口还广泛用于PDA.笔记本电脑和包括台式机在内的各种设备. ...
- ubuntu安装php的 redis扩展
wget https://github.com/phpredis/phpredis/archive/2.2.4.tar.gztar -zxvf 2.2.4.tar.gz cd phpredis-2.2 ...
- 他是 ISIJ 第四名,也是在线知名题库的洛谷“网红”
转载自加藤惠. 2020年国际初中生信息学竞赛(ISIJ)上,以优秀成绩拿下第四名年仅初三的张湫阳,成为最夺目的选手之一. 而且虽然是初三的选手,但他取得优异成绩后,不少网友并不感到陌生,纷纷留言: ...