Skip to content
RCE Write-up Advanced

How We Got There

An authenticated file upload feature allowed PHP scripts to be written to directories that did not block dangerous functions, leading to remote code execution in a restricted shell. The attacker then escaped the jail by abusing an unauthenticated Consul API to register a service check with a script that executed a reverse shell outside the restricted environment.

medium.com

Published on medium.com

Escaping jailed or restricted environments comes with its own set of challenges. However, more often than not, there’s going to be a way in.

Charley Célice, on medium.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

Likely the file upload utility allowed writing PHP files to directories that did not enforce the same blacklist of dangerous functions, and the Consul API was exposed without authentication, allowing arbitrary command execution via service check registration.

Impact

The attacker could execute commands on the host, escape the restricted shell, and gain standard user privileges as the 'consul' user, enabling further enumeration and lateral movement.

What the attacker needed

Authenticated user; file upload feature; access to Consul API

How it was found

  1. Upload PHP scripts to list files and read local files.
  2. Use a PHP script to write files to other directories and find a non-blacklisted folder.
  3. Upload a PHP script that opens a reverse shell to the attacker's IP.
  4. Receive a shell but find it restricted by chroot.
  5. Upload statically-compiled binaries to enumerate the system and network.
  6. Discover a Consul API on port 8443 and use it to register a service check with a script that executes a reverse shell.

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.

The application let users upload PHP files, and some folders did not block dangerous commands like 'system' or 'exec'. By uploading a file to one of those folders, the attacker could run commands on the server. The server was in a restricted environment, but the attacker found an unprotected Consul API that allowed running commands outside the jail.

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.