Remote LD_PRELOAD Exploitation
GoAhead web server passed untrusted HTTP request parameters as environment variables to CGI scripts, allowing an attacker to set LD_PRELOAD and load a malicious shared object from the POST body via /proc/self/fd/0, achieving remote code execution.
elttam.com.au
Published on elttam.com.au
This blog post details CVE-2017-17562, a vulnerability which can be exploited to gain reliable remote code execution in all versions of the GoAhead web server < 3.6.5.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The CGI handler copied all HTTP request parameters into the environment of the spawned CGI process without filtering special variable names such as LD_PRELOAD.
Impact
An attacker could achieve reliable remote code execution on servers running GoAhead with CGI enabled and dynamically linked executables.
What the attacker needed
GoAhead with CGI support enabled; CGI scripts are dynamically linked executables; Server runs on a Unix-like system
The fix
The issue was fixed by skipping special parameter names and prefixing all others with a static string.
How it was found
- Send a POST request to a CGI endpoint with a malicious shared object as the body.
- Include a query parameter that sets LD_PRELOAD to /proc/self/fd/0, which points to the temporary file holding the POST body.
- The server forks and executes the CGI script with the attacker-controlled environment.
- The dynamic linker loads the shared object from the request body and runs its constructor, executing the attacker's code.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
When a web server runs a CGI script, it starts a new process and passes it some settings as environment variables. GoAhead let users control those settings through the URL, so an attacker could set a special variable called LD_PRELOAD that tells the system to load an extra library before the program starts. By uploading a malicious library in the request body and pointing LD_PRELOAD at it, the attacker could run their own code on the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.