DWVA-命令注入漏洞闯关(Command Injection)
前言
Vulnerability: Command Injection
LOW级别
代码:
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// 几首一个变量为ip的参数
$target = $_REQUEST[ 'ip' ];
// 判断系统
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
echo "<pre>{$cmd}</pre>";
}
?>
我们分析这个靶场的代码可以看到$_REQUEST接受用户传过来的值 我们并没有看到有什么过滤机制的代码所以 可以输入任何东西。
测试执行ping127.0.0.1没问题 我们利用管道命令来 再加命令语句


Medium级别
代码:
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
$target = $_REQUEST[ 'ip' ];
// 黑名单过滤
$substitutions = array(
'&&' => '',
';' => '',
);
// 如果有黑名单字符则进行替换
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
// 判断系统
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
echo "<pre>{$cmd}</pre>";
}
?>
我们注意6-9行 这里是个黑名单过滤 我们可以想办法绕过 这里虽然把&&和分号;加入了黑名单,但是我们还可以用逻辑或(||)、管道符(|)或(&)来命令执行 绕过

High级别
代码:
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = trim($_REQUEST[ 'ip' ]);
// 白名单
$substitutions = array(
'&' => '',
';' => '',
'| ' => '', //主义这一行 l后面是空格说明仅仅过滤了l+空格 没过滤单独的l
'-' => '',
'$' => '',
'(' => '',
')' => '',
'`' => '',
'||' => '',
);
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
echo "<pre>{$cmd}</pre>";
}
?>
127.0.0.1|net user照样绕过
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 ); //stripslashes()过滤删除由 addslashes() 函数添加的反斜杠。
// 以.分割命令
$octet = explode( ".", $target );
// 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 ) ) {
// 以.拼接
$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();
?>
DWVA-命令注入漏洞闯关(Command Injection)的更多相关文章
- DVWA各等级命令注入漏洞
漏洞描述 在web程序中,因为业务功能需求要通过web前端传递参数到后台服务器上执行,由于开发人员没有对输入进行严格过滤,导致攻击者可以构造一些额外的"带有非法目的的"命令,欺骗后 ...
- Commix命令注入漏洞利用
介绍 项目地址:https://github.com/stasinopoulos/commix Commix是一个使用Python开发的漏洞测试工具,这个工具是为了方便的检测一个请求是否存在命令注入漏 ...
- CVE-2020-15778 OpenSSH命令注入漏洞复现
一.漏洞概要 OpenSSH 8.3p1及之前版本中的scp允许在scp.c远程功能中注入命令,攻击者可利用该漏洞执行任意命令.目前绝大多数linux系统受影响. 参考链接:https://githu ...
- sqli-labs注入lesson1-2闯关秘籍
·lesson1 1.判断是否存在注入,并判断注入的类型 其实根据第一关提示 判断注入类型 输入下面的语句进行测试: ?id= 返回界面如下图:说明存在 字符型注入 2. 使用order by 猜测S ...
- CVE-2017-17215 - 华为HG532命令注入漏洞分析
前言 前面几天国外有个公司发布了该漏洞的详情.入手的二手 hg532 到货了,分析测试一下. 固件地址:https://ia601506.us.archive.org/22/items/RouterH ...
- sqli-labs注入lesson3-4闯关秘籍
·lesson 3 与第一二关不同的是,这一关是基于错误的get单引号变形字符型注入 要使用 ') 进行闭合 (ps:博主自己理解为字符型注入,是不过是需要加括号进行闭合,适用于博主自己的方便记忆的 ...
- SaltStack 命令注入漏洞(CVE-2020-16846)
SaltStack 是基于 Python 开发的一套C/S架构配置管理工具.2020年11月SaltStack官方披露了CVE-2020-16846和CVE-2020-25592两个漏洞,其中CVE- ...
- 【代码审计】VAuditDemo 命令注入漏洞
一般PHP中可以使用下列函数来执行外部的应用程序或命令 system() exec() passthru() shell_exec() 跟踪$cmd --> 跟进$target,发现传递给tar ...
- 安全性测试入门:DVWA系列研究(二):Command Injection命令行注入攻击和防御
本篇继续对于安全性测试话题,结合DVWA进行研习. Command Injection:命令注入攻击. 1. Command Injection命令注入 命令注入是通过在应用中执行宿主操作系统的命令, ...
随机推荐
- 这玩意比ThreadLocal叼多了,吓得why哥赶紧分享出来。
这是why哥的第 70 篇原创文章 从Dubbo的一次提交开始 故事得从前段时间翻阅 Dubbo 源码时,看到的一段代码讲起. 这段代码就是这个: org.apache.dubbo.rpc.RpcCo ...
- Spring Boot 整合多点套路,少走点弯路~
持续原创输出,点击上方蓝字关注我 个人原创博客+1,点击前往,查看更多 目录 前言 Spring Boot 版本 找到自动配置类 注意@Conditionalxxx注解 注意EnableConfigu ...
- visio2016激活 试用版
输入秘钥: W9WC2-JN9W2-H4CBV-24QR7-M4HB8 可以成功激活成试用版 有效期30天,30天之后需要你正式激活! 经本人使用完全可以激活,欢迎大家使用! 也欢迎大家支持正 ...
- C# 将DataTable里面的数据导出到excel
//需要在bin里面添加 Interop.Microsoft.Office.Interop.Excel.dll 的引用 //添加引用 using System.Data; /// <summar ...
- Cypress系列(70)- server() 命令详解
如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 作用 启动服务器以开始将响应路由到 cy ...
- retrofit和RxJava结合
public class MainActivity extends AppCompatActivity { @SuppressLint("CheckResult") protect ...
- Linux常用系统文件目录结构
Linux常用系统文件目录结构 bin:全称binary,含义是二进制.该目录中存储的都是一些二进制文件,文件都是可以被运行的. dev:该目录主要存放的是外接设备,例如硬盘.其他的光盘等.在其中的外 ...
- 01 . Go框架之Gin框架从入门到熟悉(路由和上传文件)
Gin框架简介 Gin是使用Go/Golang语言实现的HTTP Web框架, 接口简洁, 性能极高,截止1.4.0版本,包含测试代码,仅14K, 其中测试代码9K, 也就是说测试源码仅5k左右, 具 ...
- http twisted
Sunday, September 30th, 2007 Twisted的WEB开发 作者: gashero <harry.python@gmail.com> 目录 1 简介 2 ...
- 微信小程序获取高宽uniapp
代码片段 <template> <view> <view class="text" id="w">补充文字</view ...