DVWA——Command Injection(low)

Command Injection

界面

在这里插入图片描述

源代码


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

?>

代码分析

通过点击submit将输入的ip获取出来,并判断当前提交ip的机器的类型,若是windows则使用:ping ip方式进行ping操作;若是其他机型,则使用:ping -c 4 ip的操作进行ping

渗透步骤

       第一步:分析代码,可以看到代码并没有对用户输入的ip进行合法判断,直接进行ping操作。通过使用ip&&其他命令的方式,可以使电脑输出其他除ping之外的结果,访问敏感数据。
       第二步:正常输入127.0.0.1,ping自己的电脑
在这里插入图片描述
第三步:通过构造127.0.0.1 && dir,查看服务器当前文件夹
在这里插入图片描述

分析可能用到的构造语句

       第一个:ip && 其他命令
              即执行ping ip操作之后执行其他命令
       第二个:ip & 其他命令
              执行第一个命令,不管成功与否,都执行后面的其他命令
       第三个:(ip)| 其他命令
              ip可以不写,把一个的结果用作第二个的输入,只打印第二个命令的结果

可能用到的命令

       使用dir代替linux下的ls命令
       使用type代替linux下的cat命令

遇到的问题

       DVWA乱码
       解决方法:将WWW\DVWA\dvwa\includes文件夹下的dvwaPage.inc.php文件里的utf-8全部改为GBK

猜你喜欢

转载自blog.csdn.net/qq_37589805/article/details/112191707
今日推荐