Skip to content
RCE Write-up Intermediate

From Git to Shell: How I Went from a Leaked Git Repo to Full RCE

A publicly accessible .git directory exposed source code containing a PHP script that passed user input to file_get_contents() and system(). An attacker could use the file_get_contents() call to reach the AWS metadata service and steal IAM credentials, and the system() call to execute arbitrary commands on the server.

Shrivarshan Follow

Published on shrivarshan81.medium.com

So there I was, doing what every bored hacker does on a weekend: scanning random targets. This time, my curiosity landed on a domain — let’s call it redacted.com (because I'm not here to get into legal trouble, just into servers 😎).

Shrivarshan, on shrivarshan81.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 application exposed its .git directory and used unsanitised user input in file_get_contents() and system() calls.

Impact

An attacker could read AWS IAM role credentials and execute arbitrary commands on the server, potentially leading to full cloud compromise.

What the attacker needed

Publicly accessible .git directory; no authentication required

The fix

The .git directory should be removed from the web root and user input should never be passed to file_get_contents() or system().

How it was found

  1. Run a directory scan against the target domain and find a publicly accessible .git directory.
  2. Clone the exposed .git repository to obtain the source code.
  3. Inspect the source and identify a PHP script that passes POST parameters to file_get_contents() and system().
  4. Send a request to the script with the ip parameter set to the AWS metadata endpoint to confirm SSRF.
  5. Request the IAM security credentials path through the same parameter to retrieve AWS role credentials.
  6. Send a request with the organization parameter set to a command to confirm remote command 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.

The website accidentally left its source code repository (a .git folder) open to the public, so anyone could download the code. The code showed two dangerous mistakes: one part fetched any web address a user typed in, and another ran any command a user typed in. This let an attacker read cloud server secrets and run commands 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.

More by Shrivarshan

View all

1 more disclosed report, best first.

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.