zoukankan      html  css  js  c++  java
  • DVWA笔记之二:Command Injection

    命令注入

    1.Low级别

    <?php 

    if( isset( $_POST'Submit' ]  ) ) { 
        
    // Get input 
        
    $target $_REQUEST'ip' ]; 

        
    // Determine OS and execute the ping command. 
        
    if( stristrphp_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>"


    ?> 

    没有增加任何过滤,可以直接执行命令。这里讲一下Linux中的管道 |

    用法: command 1 | command 2 他的功能是把第一个命令command 1执行的结果作为command 2的输入传给command 2,

    当然&&也可以执行,";"也可以执行


    2.Medium级别

    这里只是过滤了;和&&两个符号,但是没有对管道符号|进行过滤,因此还是可以继续使用|进行执行

    同时通过审计源码发现还可以如此绕过

    <?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_replacearray_keys$substitutions ), $substitutions$target );

        
    // Determine OS and execute the ping command. 
        
    if( stristrphp_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>"


    ?> 

    从过滤函数入手,str_replace只是把;和&&符号过滤成'',而对单个&符号并不会进行处理,因此可以交叉使用 构造 &;& ,这样它就会把;过滤掉过滤之后就变成了&&,从而可以进行命令的执行,此时Payload为 127.0.0.1 &;& uname -a


    3.HIGH级别

    这次过滤的就比较丰富,基本上各种可能存在执行的命令字符都已经过滤掉了

    但是有个细节,在过滤|时后面多出来一个空格,因此还是要细心的才能发现,直接使用管道|进行


    4.Impossible级别

    相关函数介绍

    stripslashes(string)

    stripslashes函数会删除字符串string中的反斜杠,返回已剥离反斜杠的字符串。

    explode(separator,string,limit)

    把字符串打散为数组,返回字符串的数组。参数separator规定在哪里分割字符串,参数string是要分割的字符串,可选参数limit规定所返回的数组元素的数目。

    is_numeric(string)

    检测string是否为数字或数字字符串,如果是返回TRUE,否则返回FALSE

    可以看到,Impossible级别的代码加入了Anti-CSRF token,同时对参数ip进行了严格的限制,只有诸如“数字.数字.数字.数字”的输入才会被接收执行,因此不存在命令注入漏洞。




  • 相关阅读:
    修改tableVIewCell里控件的属性
    常用正则表达式
    解决定时器在主线程不工作问题
    iOS App集成Apple Pay
    使用UIDataDetectorTypes自动检测电话、网址和邮箱
    NSDictionary初始化的坑
    关于UIViewController的presentViewController实现
    iOS8以上使用CoreLocation定位
    .xib 创建的文件 [self.view bringSubviewToFront:XXX];不好用
    socket通讯----GCDAsyncSocke 解读
  • 原文地址:https://www.cnblogs.com/vspiders/p/7399090.html
Copyright © 2011-2022 走看看