zoukankan      html  css  js  c++  java
  • 【靶场训练_DVWA】Command Execution

    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>';
        }
        
    }
    
    ?>
  • 相关阅读:
    OC编程之道-创建对象之工厂方法
    OC编程之道-创建对象之单例模式
    OC编程之道-创建对象之原型模式
    OC编程之道-创建对象之生成器模式
    effective OC2.0 52阅读笔记(七 系统框架)
    effective OC2.0 52阅读笔记(六 块)+ Objective-C高级编程 (二 Blocks)
    effective OC2.0 52阅读笔记(五 内存管理)
    effective OC2.0 52阅读笔记(四 协议与分类)
    安装Sublime Text 3插件的方法
    cocos2d-x学习笔记
  • 原文地址:https://www.cnblogs.com/chrysanthemum/p/11517770.html
Copyright © 2011-2022 走看看