【DVWA(八)】命令执行漏洞Command Injection


命令执行漏洞(Command Injection)

前言:

其实说起来,攻击方式跟SQL注入有点相似,简单来说,就是通过漏洞,可以执行一些本来不应该执行的指令!需要对CMD指令比较熟悉,这方面我还需要加强。

&,&&,|,||命令拼接符的区别:

A&B:AB之间无制约关系;

A&&B:A执行成功之后,然后才执行B;

A|B:A的输出,作为B的输入;

A||B:A执行失败,之后才能执行B;


low:

1.观察:

输入ip:127.0.0.1测试,正常返回,但是这时候有一段乱码,

属于浏览器的锅,火狐浏览器:查看->文字编码->简体中文,即可解决

2.漏洞测试:

输入 127.0.0.1&&help


说明漏洞存在,而且很明显没有进行任何保护

3.查看源码:

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

?> 

果然没有进行任何防护!


medium:

1.测试观察:

输入127.0.0.1提交,正常;
输入127.0.0.1&&help提交,返回如图;

2.猜测:

对&&进行了过滤,换指令拼接符:输入help||help,返回如图:


猜测正确,过滤了&&,然后我们让||前的命令失效,这样就会执行之后的指令,图中【1】就是第一个help的失效返回,【2】是第二个help命令的返回

3.查看源码:

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

?> 

过滤了“&&”和“;”


high:

1.先看源码

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

?> 

这里有一段过滤,基本要赶尽杀绝了,但是存在一个'| ',也就是说'|'还可以用(其实这里不太明白为什么要有这么明显的地方,难道是故意的?要不然没法攻击

2.测试:

输入:127.0.0.1|help,测试成功


impossible:

对ip输入的格式进行了限制,没有办法绕过了!


后记:

对于此类的漏洞利用,暂时没有想到怎么用。

猜你喜欢

转载自www.cnblogs.com/wayne-tao/p/11105964.html
今日推荐