zoukankan      html  css  js  c++  java
  • PHP安全漏洞1--命令执行

    主要参考:
    1 https://www.owasp.org/index.php/Testing_for_Command_Injection_(OTG-INPVAL-013)
    2 http://php.net/manual/zh/ 中文手册

       PHP中可以使用下列函数来执行外部的应用程序或函数

         system 、exec 、passthru、shell_exec、proc_open

       system函数原型

    string system(string $command [, int &$return_var ] )
      参数:
       command

      要执行的命令。

        return_var

      如果提供 return_var 参数, 则外部命令执行后的返回状态将会被设置到此变量中

    返回值:

      成功则返回命令输出的最后一行, 失败则返回 FALSE

      exec函数原型

    string exec ( string $command [, array &$output [, int &$return_var ]] )
    参数:
        command
          要执行的命令
        output
          返回输出的结果
        return_var
          直接返回的状态
    返回值
        命令执行结果的最后一行内容

      passthru函数原型

    void passthru ( string $command [, int &$return_var ] )
    参数:
       command
          需要执行的命令
       return_var
          执行结果的返回状态
    返回值:
       无返回,直接输出到浏览

      shell_exec函数原型

      proc_open函数原型

    resource proc_open ( string $cmd , array $descriptorspec , array &$pipes [, string $cwd [, array $env [, array $other_options ]]] )

    system漏洞实例(Windows环境)

    <?php
    print("Please specify the name of the dir to print");
    print("<p>");
    $dirname=$_GET['dirname'];
    $rest=system("dir $dirname",$return_var);
    ?>

    请求:

    http://127.0.0.1/syscommad.php?dirname=c:

    响应:

    Please specify the name of the  dir to print
    ������ C �еľ�û�б�ǩ�� �������к��� C038-3181 c: ��Ŀ¼ 2016/06/23 16:41 1,024 .rnd 2015/12/03 01:39 
    burpsuitev1.6.24 2015/08/30 10:30 Drivers 2015/09/22 14:27 IDAPro6.6 2016/06/08 12:24 IDA_Pro_v6.8_Green 2016/04/21 18:07 java 2016/06/14 21:31 masm32 2016/06/27 15:55 metasploit 2009/07/14 11:20 

    exec漏洞实例(Windows环境)

    <?php
    print("Please specify the command");
    print("<p>");
    $comd=$_GET['comd'];
    $rest_str=exec($comd, $output ,$return_var);
    
    echo  "</br>";
    print_r($output);
    ?>

    输入请求

    http://127.0.0.1/execinject.php?comd=dir%20c:/

    防御策略:

    1

     
  • 相关阅读:
    python pandas库和stats库计算偏度和峰度(附程序)
    python matplot 字体配置-中文手绘漫画风格
    流密码
    信息安全和密码学基础知识
    剑指offer48-把字符串转换成整数
    剑指offer47-不用加减乘除做加法
    剑指offer46-求1+2+...+n
    剑指offer45-孩子们的游戏
    剑指offer44-扑克牌顺子
    剑指offer43-翻转单词顺序列
  • 原文地址:https://www.cnblogs.com/superf0sh/p/5694763.html
Copyright © 2011-2022 走看看