Skip to content
RCE Write-up Beginner

Code review to simple RCE

A PHP endpoint passed user-supplied query parameters directly into a shell command, allowing an attacker to inject arbitrary commands. The author demonstrated command execution by making the server fetch a URL containing the output of a whoami command and later reading the password file.

hogarth45.medium.com

Published on hogarth45.medium.com

Start with a search for sensitive functions being called “shellexec” This is the function used by PHP to execute shell commands. So if it is ever seen in code, it should be a focus point.

Jess, on hogarth45.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

User-controlled input was concatenated directly into a shell command without sanitisation or escaping.

Impact

An attacker could execute arbitrary commands on the server, leading to full compromise and access to sensitive files.

What the attacker needed

Network access to the endpoint; attacker-controlled server for exfiltration

How it was found

  1. Identify the shell_exec call that builds a command from the query and customer parameters.
  2. Send a request with a crafted customer parameter that includes a command substitution and a wget to an attacker-controlled server.
  3. Observe the attacker server logs receiving the output of the whoami command.
  4. Send another request to read the password file and see its contents in the logs.

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 took text from a web request and glued it onto a command that the server runs. Because it did not clean or check that text, an attacker could add their own commands after the expected ones. This let them run anything on the server, such as reading sensitive files.

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.