DVWA系列——命令执行(Command Injection)

DVWA系列 ——命令执行(Command Injection)

简介

命令执行:
即命令注入,通过提交恶意构造的参数破坏命令语句结构,达到执行恶意命令的目的
比如删除文件就可以用一个url请求

http://127.0.0.1/delete.php?filename=bob.txt;id

delete.php 的内容

<?php
$file=$_GET['filename']
system("rm $file");
?>

(基于linux系统)这样就能达到恶意删除bob.txt文件的目的同时用了;分隔符还能同时执行输出id的命令
现在用NVWA进行实战

low级别

输入127.0.0.1 && ipconfig
我们在输入的IP地址后面加了个&&分隔符返回ipconfig的命令返回内容即在他执行完ping 127.0.0.1后又执行了后面的命令
在这里插入图片描述这里提供一些常用的注入

127.0.0.1 || ipconfig
127.0.0.1 & ipconfig
127.0.0.1 && ipconfig
127.0.0.1 | ipconfig
127.0.0.1 |ipconfig
127.0.0.1 ; ipconfig

适用于windows和linux系统
现在我们来看下源码
low

<?php

if( isset( $_POST[ 'Submit' ]  ) ) {
    // Get input
    $target = $_REQUEST[ 'ip' ];

    // 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级别没有任何guolv以上注入都可行(’;’ 是用于Linux系统window不适用)

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>";
}

?>

其中

 $substitutions = array(
        '&&' => '',
        ';'  => '',

设置了黑名单有&&会被赋值为空,当然我们绕过就行啦
用一个上面的常用注入绕过例如
我使用127.0.0.1 | ipconfig
直接跳过ping执行了恶意命令ipconfig
在这里插入图片描述

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>";
}

?> 

这里黑名单就比较多了同样的方法绕过手工注入太麻烦我们直接用brupsuite
准备好字典
在这里插入图片描述
随便输入127.0.0.1打开代理brupsuite截断
在这里插入图片描述
在这里插入图片描述抓包发往intruder
在这里插入图片描述将其他目标clear,选择要用的ip add添加
在这里插入图片描述选择刚刚的准备好的字典然后开始攻击
在这里插入图片描述可以在Render看返回效果可以看出在high级别只有127.0.0.1 |ipconfig可以绕过黑名单(注意 “|” 后没有空格)

impossible级别

观察分析源码
在这里插入图片描述这里
在这里插入图片描述这段代码限制了输入只能是纯数字
就无法注入了

总结

防范方法
1设置黑名单
2替换,转义关键字
3对于IP地址可以以‘ . ’为分界将数字分到数组判断是否为数字以保证输入内无连接符避免注入

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值