前言

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)的更多相关文章

  1. DVWA各等级命令注入漏洞

    漏洞描述 在web程序中,因为业务功能需求要通过web前端传递参数到后台服务器上执行,由于开发人员没有对输入进行严格过滤,导致攻击者可以构造一些额外的"带有非法目的的"命令,欺骗后 ...

  2. Commix命令注入漏洞利用

    介绍 项目地址:https://github.com/stasinopoulos/commix Commix是一个使用Python开发的漏洞测试工具,这个工具是为了方便的检测一个请求是否存在命令注入漏 ...

  3. CVE-2020-15778 OpenSSH命令注入漏洞复现

    一.漏洞概要 OpenSSH 8.3p1及之前版本中的scp允许在scp.c远程功能中注入命令,攻击者可利用该漏洞执行任意命令.目前绝大多数linux系统受影响. 参考链接:https://githu ...

  4. sqli-labs注入lesson1-2闯关秘籍

    ·lesson1 1.判断是否存在注入,并判断注入的类型 其实根据第一关提示 判断注入类型 输入下面的语句进行测试: ?id= 返回界面如下图:说明存在 字符型注入 2. 使用order by 猜测S ...

  5. CVE-2017-17215 - 华为HG532命令注入漏洞分析

    前言 前面几天国外有个公司发布了该漏洞的详情.入手的二手 hg532 到货了,分析测试一下. 固件地址:https://ia601506.us.archive.org/22/items/RouterH ...

  6. sqli-labs注入lesson3-4闯关秘籍

    ·lesson 3 与第一二关不同的是,这一关是基于错误的get单引号变形字符型注入 要使用 ') 进行闭合  (ps:博主自己理解为字符型注入,是不过是需要加括号进行闭合,适用于博主自己的方便记忆的 ...

  7. SaltStack 命令注入漏洞(CVE-2020-16846)

    SaltStack 是基于 Python 开发的一套C/S架构配置管理工具.2020年11月SaltStack官方披露了CVE-2020-16846和CVE-2020-25592两个漏洞,其中CVE- ...

  8. 【代码审计】VAuditDemo 命令注入漏洞

    一般PHP中可以使用下列函数来执行外部的应用程序或命令 system() exec() passthru() shell_exec() 跟踪$cmd --> 跟进$target,发现传递给tar ...

  9. 安全性测试入门:DVWA系列研究(二):Command Injection命令行注入攻击和防御

    本篇继续对于安全性测试话题,结合DVWA进行研习. Command Injection:命令注入攻击. 1. Command Injection命令注入 命令注入是通过在应用中执行宿主操作系统的命令, ...

随机推荐

  1. 蒲公英 &#183; JELLY技术周刊 Vol.26: 请问您这个月要来点肝么?

    蒲公英 · JELLY技术周刊 Vol.26 今年的十月,不知道大家在 TODO List 上新增了多少条目准备尝鲜,你可能已经准备了 Vue3.Webpack5 以及 React v17.0 RC, ...

  2. airtest本地连接和远程连接

    一.本地连接 # -*- coding: utf-8 -*-# from poco.drivers.android.uiautomation import AndroidUiautomationPoc ...

  3. Vue基础语法(四)

    vue的生命周期钩子函数 所有的生命周期钩子自动绑定this到上下文实例中,因此可以访问数据对property和方法进行运算,这意味着不蹦使用箭头函数来定义一个生命周期方法.参考官方文档,生命周期图 ...

  4. spark load data from mysql

    spark load data from mysql code first 本机通过spark-shell.cmd启动一个spark进程 SparkSession spark = SparkSessi ...

  5. Ignite、Vertx

    Ignite IpFinder 默认采用multicast的ip发现方式 优点: 集群较小时,配置方便 缺点 集群较大100s-1000s时,广播非常耗时,此时建议使用ZooKeeper发现机制(Zo ...

  6. ES2020链判断运算符?.和Null判断运算符??

    链判断运算符 ?.  业务场景: 1 // 假设data是个数组,如果data没有值,为undefinded,则直接复制会报错,因为没有length这个属性 2 3 const dateCount = ...

  7. (PatchGANs)Pecomputed Real-time Texture Synthesis With Markovian Generative Adversarial Networks

    Introduction: Deconvolution;   Computational costs; Strided convolutional nets; Markov patches; 1. Q ...

  8. 数据结构(C++)——顺序栈

    顺序栈结构 #include<iostream> #define MaxSize 50 using namespace std; typedef int ElemType; typedef ...

  9. Redis---01简述目录结构与redis.conf文件

    一.Redis目录结构 (当前Redis是在CentOS 7 1708 64位环境下,Redis版本为3.2.5) 进入默认的Redis安装目录/usr/local/bin,可以看见这些下图目录结构 ...

  10. Dev中配置graphcis.h

    下载地址:http://winbgim.codecutter.org/ 搞得自己有点奔溃 没成功 尝试了全网的所以的方法都没成功