zoukankan      html  css  js  c++  java
  • 【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输入的格式进行了限制,没有办法绕过了!


    后记:

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

  • 相关阅读:
    vector order by function and object
    C++ Tree node ,when g++ compile multiple cpp files should list them respectively
    Node.1
    asp遍历xml节点
    redis扩展安装以及在tp5中的操作
    JS中在循环内实现休眠(for循环内setTimeout延时问题)
    一种开发软件的新思路,给Web页面穿个马甲,用web页面做软件UI,用C#(或者C++等其它语言)代码做功能 碧血黄沙
    高仿QQMusic播放器,浅谈WinForm关于UI的制作 碧血黄沙
    我的站(艾网城市生活新门户)重新上线了 碧血黄沙
    用WPF开发仿QQ概念版之MessageWindow开发以及Demo下载 碧血黄沙
  • 原文地址:https://www.cnblogs.com/wayne-tao/p/11105964.html
Copyright © 2011-2022 走看看