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命令注入 命令注入是通过在应用中执行宿主操作系统的命令, ...
随机推荐
- GeoServer发布shapfile字段名和值乱码问题解决
摘要: 网上说了一大堆方法又是转格式咯又是改源代码了,修改很简单: 修改Styles下的你的style: Xml代码 修改Stores下你的图层的属性,设置 DBF charset为GBK 以上设置G ...
- Java进阶专题(十五) 从电商系统角度研究多线程(下)
前言 本章节继上章节继续梳理:线程相关的基础理论和工具.多线程程序下的性能调优和电商场景下多线程的使用. 多线程J·U·C ThreadLocal 概念 ThreadLocal类并不是用来解决 ...
- python 操作conf配置文件方法
参考文章链接:https://blog.csdn.net/qq_23587541/article/details/85019610
- PHP程序员必须会的 45 个PHP 面试题
Q1: == 和 === 之间有什么区别? 话题: PHP困难: 如果是两个不同的类型,运算符 == 则在两个不同的类型之间进行强制转换 === 操作符执行'类型安全比较' 这意味着只有当两个操作数具 ...
- vue中跳转页面逻辑
跳转详情页面具体代码 写这个页面需要安装两个 1.安装axios命令 Cnpm install axios --save 2.安装vant Cnpm install vant --save 在inde ...
- buuctf-pwn:jarvisoj_level6_x64
jarvisoj_level6_x64 只能申请unsorted bin大小下的unlink IDA看一下,可以发现edit里面有任意堆溢出的情况(realloc造成堆溢出) 然后free里面有UAF ...
- vue项目中mockjs的使用
mock.js是一个库,源码托管:https://github.com/nuysoft/Mock github上的原话:Mock.js是一个模拟数据生成器,可帮助前端开发和原型与后端进度分开,并减少某 ...
- java安全编码指南之:文件IO操作
目录 简介 创建文件的时候指定合适的权限 注意检查文件操作的返回值 删除使用过后的临时文件 释放不再被使用的资源 注意Buffer的安全性 注意 Process 的标准输入输出 InputStream ...
- Mybatis---03Mybatis配置文件浅析(一)
一.写入mybatis配置文件的约束 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE co ...
- 文本的3D效果
HTML <div class="g-box"> <h1>CSS的世界很美</h1> </div> CSS .g-box { wid ...