FastCGI - Port 9000
Become VeryLazyTech member! π
Follow us on:
β Twitter @VeryLazyTech.
πΎ Github @VeryLazyTech.
π Medium @VeryLazyTech.
πΊ YouTube @VeryLazyTech.
π© Telegram @VeryLazyTech.
π΅οΈββοΈ My Site @VeryLazyTech.
Visit our shop for e-books and courses. π
Basic info
What is FastCGI?
FastCGI is a binary protocol that allows web servers to communicate with application servers (typically PHP-FPM) to process dynamic content. It's an evolution of CGI (Common Gateway Interface) designed to:
Persist processes instead of spawning them per request
Reduce overhead of process creation
Scale better with high-traffic applications
Support multiple languages (PHP, Python, Perl, Ruby, etc.)
FastCGI vs CGI
Architecture
Typical Web Stack with FastCGI:
Process Flow:
Client requests
http://server/index.phpNginx receives request
Nginx forwards to PHP-FPM via FastCGI (port 9000)
PHP-FPM executes script
PHP-FPM returns result to Nginx
Nginx sends response to client
PHP-FPM
PHP-FPM (FastCGI Process Manager) is the most common FastCGI implementation:
Manages pool of PHP worker processes
Handles FastCGI protocol
Usually listens on localhost:9000
Can listen on Unix socket (
/var/run/php-fpm.sock)
Configuration Files:
Default Port
Port 9000 - FastCGI (typically PHP-FPM)
Important Notes:
Usually binds to localhost only (127.0.0.1)
Exposed FastCGI is a critical vulnerability
No authentication by default
Binary protocol (not HTTP)
FastCGI Protocol Overview
Protocol Structure
FastCGI Record Format:
Record Types
FastCGI Parameters
Key Parameters (CGI Environment Variables):
PHP-Specific Parameters:
Reconnaissance & Enumeration
Port Scanning
Basic Nmap Scan
Sample Output:
Note: Nmap often shows "unknown" service for FastCGI
Service Fingerprinting
Using cgi-fcgi (libfcgi)
Sample Status Page Output:
Using netcat (Limited)
Check for Exposed FastCGI
Local Testing:
Remote Testing:
Shodan Queries
Note: FastCGI is rarely indexed by Shodan since it's usually localhost-only
Remote Code Execution (RCE)
Method 1: Direct FastCGI RCE (Exposed Port)
Concept: Abuse PHP_VALUE to set auto_prepend_file with PHP code
Bash Script Exploitation:
What This Does:
Sets
PHP_VALUEto modify PHP configurationEnables
allow_url_includeandallow_url_fopenUses
auto_prepend_fileto execute code before scriptUses
data://stream wrapper with base64-encoded payloadExecutes when accessing existing PHP file
Testing:
Method 2: Python FastCGI Exploit
Advanced Python Script:
Usage:
Method 3: SSRF to FastCGI (Gopher Protocol)
Concept: Use SSRF vulnerability to access localhost:9000
Gopher Payload Builder:
Usage in SSRF:
Method 4: Nginx Misconfiguration Exploitation
Vulnerable Nginx Configuration:
With PHP Configuration:
Exploitation:
Path Traversal Exploitation:
Known Vulnerabilities & CVEs
CVE-2024-xxxx: libfcgi Integer Overflow
Affected: libfcgi <= 2.4.4 (2024)
Impact: Heap overflow β Remote Code Execution
Description:
Integer overflow in
nameLen/valueLenparsingAffects 32-bit builds (common in IoT/embedded)
Leads to heap corruption
RCE when FastCGI socket is reachable
Vulnerable Code:
Exploitation:
Mitigation:
Update to libfcgi > 2.4.4
Use 64-bit systems
Validate input lengths
CVE-2024-9026: PHP-FPM Log Manipulation
Affected: PHP-FPM with catch_workers_output = yes
Impact: Log injection/truncation
Description:
When
catch_workers_outputis enabledAttackers can inject/truncate log entries
Up to 4 bytes per log line
Can hide attack indicators
Poison logs for SIEM evasion
Exploitation:
Mitigation:
Update PHP-FPM
Disable
catch_workers_outputif not neededMonitor logs for corruption
Use centralized logging
Nginx + cgi.fix_pathinfo Misconfiguration
Not a CVE, but widespread vulnerability
Vulnerable Configuration:
Impact:
Path traversal
Arbitrary file execution
Source code disclosure
Example Attack:
Proper Configuration:
Defense & Hardening
Secure PHP-FPM Configuration
Bind to Localhost Only:
Security Settings:
Secure Nginx Configuration
Safe PHP Handling:
Disable Path Info (Secure):
Network Security
Firewall Rules:
Monitor Connections:
Monitoring & Detection
Log Monitoring:
Intrusion Detection:
File Integrity Monitoring:
Regular Security Practices
Tools & Scripts
Essential Tools
cgi-fcgi - FastCGI client (libfcgi)
Gopherus - SSRF payload generator
curl - HTTP client (for testing)
nmap - Port scanning
Custom Python scripts - Protocol manipulation
Install cgi-fcgi
Complete Exploitation Framework
Cheat Sheet
Quick Reference
Important Files
Key Parameters
Conclusion
FastCGI, while designed for performance, introduces significant security risks when exposed or misconfigured. The combination of no default authentication, powerful parameter injection capabilities, and common misconfigurations makes it a critical target for attackers.
Key Takeaways:
Never expose FastCGI externally - Bind to localhost only
Use Unix sockets - More secure than TCP sockets
Validate file existence - Nginx must check files exist
Disable cgi.fix_pathinfo - Set to 0 in php.ini
Restrict PHP settings - Disable dangerous functions
Monitor FastCGI connections - Alert on external access
Keep software updated - Patch libfcgi and PHP-FPM
Use strong Nginx config - Include try_files directive
Regular security audits - Check binding and config
Defense in depth - Firewall + config + monitoring
Attack Vectors:
Direct FastCGI access (if exposed)
SSRF to localhost:9000 (gopher protocol)
Nginx misconfiguration (path traversal)
Parameter injection (PHP_VALUE abuse)
Integer overflow (CVE-2024 libfcgi)
Log manipulation (CVE-2024-9026)
Remember to only perform these techniques during authorized security assessments. Unauthorized access is illegal and unethical.
Additional Resources
Last updated
Was this helpful?