首页 > 其他分享 >FASTCGI组件漏洞

FASTCGI组件漏洞

时间:2023-07-24 16:44:37浏览次数:46  
标签:CGI process server 漏洞 FASTCGI file 组件 data FastCGI

CGI introduction

  common gatewa interface/CGI describes a stardand for transferring data between server and client programs,allowing a client to request data from a program running on a network server  via web browser

  CGI is independent of any language,CGI program can be implemented using any scripting language or completely independent programming language,as long as this language can run on the system.(in fact,it is to process http request data parsed by the web server)

CGI workflow

the complete process is shown in follow figure.

specific process as follows:

  1.user send a request package via browser to access server.

    http://xx?user=1&passwd=1&age=11

  2.server accquire the data and parse it

  3.nginx don't know how to handle these login data and send them to the cgi program.the server then creates a CGI process to handle the data

  4.CGI process execute

  5.server send the cgi handle result to the client

CGI specific structure

the specific process of CGI process is as follows:

1. load the configuration,if neccessary,load the configuration to obtain data

2.connect to other server like database

3.perform logical processing

4.obtain the result and send it to server

5.exit

 the drawbacks of CGI

when nginx send data to cig process,the server will create a cgi process.

frequent creation and destruction of processes are required when dealing with data,which leads to high server overhead and low efficiency.

therefore we can take a look at fastcgi

fastcgi

fast common gateway interface is an improvement over the CGI.fastcgi aims to reduce the overhead of interaction between web servers and cgi program,allowing server to handle more web request simultaneously.

unlike create a new process for each reqeust,fastcgi uses persistant processes to handle a serias of requests.

these processes are managed by fastcgi manager,rather than web server

different between fastcgi and cgi

FastCGI is a long-lived application program, while CGI is a short-lived application program. FastCGI is like a resident (long-live) CGI that can keep running without having to fork every time. In contrast, a regular CGI creates a new process for each request. FastCGI is a resident process and service, as can be seen from the following line of code.

while(FCGI_Accept()>=0)

 The specific process is as follows:

1.The user accesses the server through a browser and sends a request with the following URL: http://localhost/login?user=zhang3&passwd=123456&age=12&sex=man

2.The server receives the data and parses it.

3. For some login data that it does not know how to handle, nginx sends the data to the fastcgi program through local sockets and network communication (via the socket interface).

4. FastCGI is started (not directly by the web server, but by a fastCGI process manager). The process includes loading configuration (optional), connecting to the server (database), and looping (if there is a request from the server, process it and send the processing result to the server; if there is no request, block).

5. The server sends the processing result of fastCGI to the client.

fastcgi usage

nginx cannot directly execute external executable programs like Apache, but it can act as a proxy server and forward requests to backend servers, which is one of its main functions. Among them, nginx supports FastCGI proxy, which receives client requests and then forwards them to the backend FastCGI process. Here's how to write CGI/FastCGI using C/C++ and deploy it to nginx. As mentioned earlier, FastCGI processes are managed by the FastCGI process manager, not nginx. This requires a FastCGI manager to manage our FastCGI program. We use spawn-fcgi as the FastCGI process manager. spawn-fcgi is a universal FastCGI process manager that is simple and compact. It was originally part of lighttpd, but later became a standalone project due to its widespread use. spawn-fcgi uses the pre-fork model, which mainly opens the listening port, binds the address, and then fork-and-exec to create our FastCGI application process, and exits to complete the work. The FastCGI application program initializes and then enters a loop to listen for socket connection requests.

php-fpm 

PHP-FPM is a program that implements the FastCGI protocol. Its full name is FastCGI Process Manager. With PHP-FPM, web containers can send data in the format of the FastCGI protocol(the format is key-value), and PHP-FPM can execute the PHP file specified by the value of SCRIPT_FILENAME.

By default, PHP-FPM listens on port 9000. If this port is directly accessible, we can construct the FastCGI protocol ourselves and communicate with FPM.

For example, if we can control the content of this request packet, we can add 'PHP_ADMIN_VALUE': 'allow_url_include = On' to the request packet. Then the file requested in this request can use remote file inclusion.

loophole exploit

conditions

  1 the absolute path of one php file on server

  2. we can access php-fpm 9000 port

     we can construct a malicious fastcgi format data to transfer with php-fpm,then we can make a rce

{
    'GATEWAY_INTERFACE': 'FastCGI/1.0',
    'REQUEST_METHOD': 'GET',
    'SCRIPT_FILENAME': '/var/www/html/index.php',
    'SCRIPT_NAME': '/index.php',
    'QUERY_STRING': '?a=1&b=2',
    'REQUEST_URI': '/index.php?a=1&b=2',
    'DOCUMENT_ROOT': '/var/www/html',
    'SERVER_SOFTWARE': 'php/fcgiclient',
    'REMOTE_ADDR': '127.0.0.1',
    'REMOTE_PORT': '12345',
    'SERVER_ADDR': '127.0.0.1',
    'SERVER_PORT': '80',
    'SERVER_NAME': "localhost",
    'SERVER_PROTOCOL': 'HTTP/1.1'
    'PHP_VALUE': 'auto_prepend_file = php://input',
    'PHP_ADMIN_VALUE': 'allow_url_include = On'
}

This request is to access index.php, and its absolute path on the server is /var/www/html/index.php. Knowledge of the absolute path of a file is necessary to exploit vulnerabilities.

auto_prepend_file tells PHP to include the file specified in auto_prepend_file before executing the target file; auto_append_file tells PHP to include the file specified in auto_append_file after executing the target file.

Now, suppose we set auto_prepend_file to php://input and enable allow_url_include by adding 'PHP_ADMIN_VALUE': 'allow_url_include = On' in the fastcgi data. In this case, index.php will first load the code we put in the post request body before loading, achieving remote code execution.

标签:CGI,process,server,漏洞,FASTCGI,file,组件,data,FastCGI
From: https://www.cnblogs.com/lisenMiller/p/17577210.html

相关文章

  • 初级设计师必看的UI设计组件库
    UI组件库是一个可以理解为重复使用界面设计元素的集合,是一个文件库。UI组件库在整个系统中起着行为层面的作用,是团队内部设计师与开发者之间的横向合作,是保证产品产出一致的标准基础。即时设计资源社区提供丰富的组件库,包括不同行业、不同顶级互联网厂商的UI组件库!可以免费一键使......
  • WEB漏洞—文件操作之文件包含漏洞
    文件包含原理 ----传递一个参数(可以是一个文件),然后PHP脚本包含这个文件,则无论这个文件是什么格式,访问PHP脚本,传递参数的文件都能以PHP格式执行。本地文件包含测试 #本地创建一个1.php和shell.txt,代码如下#访问PHP脚本并且传递1.txt文件为参数,发现txt里的内容以php代码执行......
  • vue组件封装 - 选择器远程搜索下拉列表
    <!--*component:人员选择-远程搜索下拉列表*time:2023/7/19*author:zx*使用方式*importPersonSelectfrom"@/components/Dialog/personSelect.vue";*components:{PersonSelect}*<person-selectv-model="test"/>--><......
  • vue组件封装 - 省市县下拉选联动
    改封装组件依赖element-china-area-data插件,引入组件可参照:https://www.npmjs.com/package/element-china-area-data<!--*component:省市县下拉选联动*time:2023/7/19*author:zx*使用方式:*importDialogAddressfrom"@/components/Dialog/dialogAddress.......
  • springCloud五大核心组件「建议收藏」
    大家好,又见面了。1.springCloud五大组件运行流程2.springcloud简单介绍SpringCloud是微服务架构的集大成者,将一系列优秀的组件进行了整合。基于springboot构建,对我们熟悉spring的程序员来说,上手比较容易。通过一些简单的注解,我们就可以快速的在应用中配置一下常用模块并构建庞......
  • Cilium 系列-3-Cilium 的基本组件和重要概念
    系列文章Cilium系列文章前言安装完了,我们看看Cilium有哪些组件和重要概念。Cilium组件如上所述,安装Cilium时,会安装几个运行组件(有些是可选组件),它们各是什么用途?CiliumOperatorCiliumOperator可以理解为Cilium的管理平面或操作运维平面。CiliumOperator不......
  • 漏洞扫描工具AWVS的安装
    AWVS是一款常用的漏洞扫描工具,全称为AcunetixWebVulnerabilityScanner,它能通过网络爬虫测试你的网站安全,检测流行安全漏洞,大大提高了渗透效率。主要使用的功能有:仪表盘(监视器)功能、添加目标功能、漏洞排序功能、扫描功能、发现功能、用户功能,其它还有扫描配置功能、网络扫描功......
  • Unity3D 使用带刚体组件的预制体配合脚本自动生成一面墙时上层墙体被弹飞
    异常效果如下图所示:预制体是一个正方体(Cube),其参数设置如下图所示:控制墙面生成的C#脚本如下所示:usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassWall:MonoBehaviour{publicTransformbrick;//Usethisf......
  • SpringBoot自动化装配中,如何解决组件装配顺序
    SpringBoot自动化装配中,如果有两个AutoConfiguration,A依赖B,这时ConditionalOnBean如何保证顺序使需要的Bean会提前加载使用@AutoConfigureAfter,当几个组件加载完成后,再加载当前组件,如:Nacos服务注册自动配置类加载前需要加载:通用的服务注册配置,服务注册的自动化配置,服务发现的自......
  • WEB漏洞-查询方式及报错注入
    WEB漏洞-查询方式及报错注入目录WEB漏洞-查询方式及报错注入1.查询方式1.1select查询数据1.2insert插入数据1.3delete删除数据1.4update更新数据1.5orderby排序数据2.SQL注入报错盲注2.1基于布尔的SQL盲注-逻辑判断2.如何进行布尔盲注?3.靶场案例演示:总结归纳:2.2基......