DVWA(命令执行)

命令行执行(Command Injection)

命令连接符:
command1 & command2 :不管command1执行成功与否,都会执行command2(将上一个命令的输出作为下一个命令的输入);
command1 && command2 :先执行command1执行成功后才会执行command2;
command1 | command2 :只执行command2;
command1 || command2 :command1执行失败,再执行command2(若command1执行成功,就不再执行command2);
command 1;command2:只在Linux里适用,command1和command2独立执行, 不管command1执行成功没有,command2继续执行 。

Low

在这里插入图片描述
在输入框输入ip,用burp抓包,把数据发送给intruder;
在这里插入图片描述
把提交数据设置成变量,把可能构造成功的命令行执行语句都写进字典里,进行暴破;
在这里插入图片描述
暴破后发现返回数据包长度不同,这里是数据越长,表示被执行的命令越多,接下来我把这5个语句返回的结果都列举下面,我们可以做个比较;
在这里插入图片描述
1构造命令行执行成功;
在这里插入图片描述
2构造命令行执行成功;在这里插入图片描述
3构造命令行执行失败;
在这里插入图片描述
4构造命令行执行成功;
在这里插入图片描述
5构造命令行执行失败;
在这里插入图片描述
以上结果显示,这124构造的语句都能利用该漏洞,这里ipconfig是显示或配置网络设备的命令,这里可以结合用途,构造自己需要的命令行。

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(
        '&&' => '',
        ';'  => '',
    );

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

?>

这里可以看到high级别只是比medium级别的过滤条件更多了,这里我们还是相应的绕过就好了,通过观察这里对|的限制是 |空格,所以并不是对|做了过滤,所以我们可以采取|来执行该漏洞。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值