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命令注入 命令注入是通过在应用中执行宿主操作系统的命令, ...
随机推荐
- Codeforces Round #676 (Div. 2) A - D个人题解(E题待补)
1421A. XORwice 题目链接:Click Here // Author : RioTian // Time : 20/10/18 #include <bits/stdc++.h> ...
- css变量复用 全局变量-局部变量
前言 简单使用场景:同一套后台系统有多套主题的情况下,主题色作为一个最常用到的可复用的颜色,非常有必要像js的全局变量一样存在全局变量中以作复用,之前我第一个想到的是sass的变量声明,未曾想到css ...
- solr之functionQuery(函数查询)【转】
函数查询 让我们可以利用 numeric域的值 或者 与域相关的的某个特定的值的函数,来对文档进行评分. 怎样使用函数查询 这里主要有两种方法可以使用函数查询,这两种方法都是通过solr http 接 ...
- 第三十三章 linux常规练习题(二)
一.练习题一 1.删除用户基本组shanghai03.发现无法正常删除,怎样才能将其删除掉,不能删除用户.2.打开多个xshell窗口连接登录同一虚拟机,使用不同的用户登录多次,分别使用w和who命令 ...
- concurrenthasmap
concur'renthashmap java1.7 hashMap在单线程中使用大大提高效率,在多线程的情况下使用hashTable来确保安全.hashTable中使用synchronized关键字 ...
- 没事学些KVM(三)虚拟机基础管理
创建完成虚拟机后,需要对虚拟机进行基础管理学习 virsh list #查看虚拟机列表 改命令只能查看正在运行或挂起的虚拟机 如果需要查看所有的虚拟机需要添加--all 参数 virsh start ...
- Error in mounted hook: "TypeError: handlers[i].call is not a function" 原因
Error in mounted hook: "TypeError: handlers[i].call is not a function" 百度翻译 安装钩子中的错误:" ...
- NB-IoT技术适合在哪些场景应用
LPWAN,Low Power Wide Area Network,低功耗广域网.名字里就有它的两个最重要的特点:低功耗.广覆盖.目前比较主流的有:NB-IoT.LoRa.Sigfox.eMTC.NB ...
- 阿里云app原型设计
软件需求分析与系统设计 https://edu.cnblogs.com/campus/zswxy/2018SE 这个作业要求在哪里 https://edu.cnblogs.com/campus/zsw ...
- Jmeter 获取系统时间
${__time(yyyy-MM-dd HH:mm:ss:SSS,time)} :格式化生成时间格式 2020-11-03 21:59:13:658