Skip to content
Path traversal Write-up Intermediate

Shell Wars: Episode II – Attack of the Code {Review}

A path traversal in a file download endpoint allowed the attacker to download the entire PHP source code. Reviewing the code revealed blind SQL injection, an unauthenticated password reset that used a database ID, and an unrestricted file upload that led to remote command execution.

medium.com

Published on medium.com

For the last few months I’ve been taking Offensive Security’s OSWE course, which has a specific focus on code review. So, when a few weeks ago I was performing a black box application test on behalf of a large corporate client, and I was lucky enough to find a vulnerability which morphed the assessment into a white…

Greenwolf, 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 download endpoint did not sanitise user-supplied paths, and the codebase contained multiple other input validation and authentication design flaws.

Impact

An attacker could read all source code, extract usernames via blind SQL injection, reset any user's password without authentication, and upload a web shell to achieve remote command execution.

What the attacker needed

Access to the file download endpoint; ability to send crafted requests; knowledge of a valid username or user ID

The fix

The text recommends escaping path traversal strings and SQL injection characters, checking file upload type server side, and redesigning password reset to use a token sent to the user's email rather than a database ID.

How it was found

  1. Run Burp active scan and identify a path traversal in a file download endpoint.
  2. Use the traversal to download the source code of the vulnerable file and then the index.php file.
  3. Enumerate includes from index.php to download all PHP files and exfiltrate the entire source code.
  4. Grep the source for lines containing SELECT and $_GET to find potential SQL injection.
  5. Exploit a blind SQL injection using the MySQL BENCHMARK function to confirm it works.
  6. Use the SQL injection to extract usernames and user IDs, then reset a user's password via the unauthenticated password reset function.

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 download files by specifying a path, and it did not check that the path stayed inside the intended folder. By using '..' sequences, the attacker could read any file on the server, including the source code. With the code in hand, the attacker found other mistakes that allowed database access, password resets, and finally running commands on the server.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.