加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

【靶场训练_DVWA】Command Execution

发布时间:2020-12-13 21:29:41 所属栏目:PHP教程 来源:网络整理
导读:low 利用: ; ls ../../ ? ? ?源码分析: ? php if ( isset ( $_POST [ ‘submit‘ ] ) ) { // 将ip对应的值复制给target $target = $_REQUEST [ ‘ip‘ ]; if ( stristr ( php_uname (‘s‘),‘Windows NT‘ )) { // 如果是winds就直接ping $cmd = shell_ex

low

利用:

;ls ../../

?

?

?源码分析:

<?php

if( isset( $_POST[ ‘submit‘ ] ) ) 
{
    //将ip对应的值复制给target
    $target = $_REQUEST[ ‘ip‘ ];
    
    if (stristr(php_uname(‘s‘),‘Windows NT‘)) 
    { 
        //如果是winds就直接ping
    
        $cmd = shell_exec( ‘ping  ‘ . $target );
        echo ‘<pre>‘.$cmd.‘</pre>‘;
        
    } 
    else 
    { 
        //如果是Linux就默认ping 3个包
        $cmd = shell_exec( ‘ping  -c 3 ‘ . $target );
        echo ‘<pre>‘.$cmd.‘</pre>‘;
        
    }
    
}
?>
  • $_REQUEST[]具用$_POST[] $_GET[]的功能,但是$_REQUEST[]比较慢。通过post和get方法提交的所有数据都可以通过$_REQUEST数组获得
  • php_uname — 返回运行 PHP 的系统的有关信息
  • stristr() 函数搜索字符串在另一字符串中的第一次出现
  • php_uname(‘s‘):返回操作系统名称

?

Medium

利用:

|| 或者  &;& 或者 &

?

源码分析:

?就多了一点过滤,但是没过滤完整

<?php

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

    $target = $_REQUEST[ ‘ip‘ ];

    // 过滤了 &&,;命令分割符
    $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>‘;
        
    }
}

?>

High

无能为力了Orz,只有诸如“数字.数字.数字.数字”的输入才会被接收执行.

<?php

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

    $target = $_REQUEST["ip"];
    
    /*
        stripslashes() 函数删除由 addslashes() 函数添加的反斜杠。
     */
    
    $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‘)) 
        { 
    
            $cmd = shell_exec( ‘ping  ‘ . $target );
            echo ‘<pre>‘.$cmd.‘</pre>‘;
        
        } 
        else 
        { 
    
            $cmd = shell_exec( ‘ping  -c 3 ‘ . $target );
            echo ‘<pre>‘.$cmd.‘</pre>‘;
        
        }
    
    }
    else
    {
        echo ‘<pre>ERROR: You have entered an invalid IP</pre>‘;
    }
    
}

?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读