Skip to content
RCE Write-up Advanced

Remote LD_PRELOAD Exploitation - elttam

GoAhead passed untrusted HTTP request parameters into the environment of forked CGI processes, so an attacker could set special dynamic-linker variables such as LD_PRELOAD. By uploading a shared object in a POST body and pointing LD_PRELOAD at the process's own stdin, an attacker could get reliable remote code execution.

elttam.com

Published on elttam.com

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 author, on elttam.com

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 built the child process environment from unfiltered request parameters, allowing control of special dynamic-linker variables such as LD_PRELOAD.

Impact

An attacker could achieve reliable remote code execution on affected servers, though only those running a Unix-like system with CGI enabled and dynamically linked CGI executables are affected.

What the attacker needed

CGI support enabled; Unix-like host; dynamically linked CGI executables; attacker can send HTTP requests

The fix

The issue was fixed by skipping special parameter names and prefixing all remaining ones with a static string.

How it was found

  1. Send a request to a CGI script with a parameter named LD_PRELOAD pointing at a shared object on disk.
  2. Observe that the shared object's constructor code runs in the CGI process.
  3. Upload a malicious shared object as the body of a POST request to the CGI script.
  4. Set LD_PRELOAD to /proc/self/fd/0 so the loader reads the uploaded body as a library.
  5. The constructor in the uploaded library executes, giving code execution.

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.

A web server can start small helper programs (CGI scripts) to handle some requests, and it hands them settings through 'environment variables', which are named values the operating system passes to a program. GoAhead copied request parameters straight into those settings, and some names are special to the Linux program loader, which runs before the helper's own code. One of them tells the loader to load an extra library file first, so the attacker's uploaded file ran their code.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.