Skip to content
Path traversal Write-up Intermediate

Escaping the Sandbox: How a Simple Python Path Flaw Led to Host RCE

A deployment automation tool used Python's os.path.join to confine script execution to a build directory, but an absolute path supplied by the user discarded that directory. An attacker with deployment access could run an arbitrary script on the host, achieving remote code execution.

HackerMD Follow

Published on medium.com

Here is a deep dive into how I turned a simple path traversal bug into a full-scale Vertical Privilege Escalation.

Hacker MD, 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

The code assumed os.path.join would always keep the result inside the base directory, but an absolute path component replaces the base directory entirely.

Impact

The attacker could run commands as the deployment service user on the host, and from there could query the cloud instance metadata service to steal credentials, move laterally, and exfiltrate secrets.

What the attacker needed

Low-privileged deployment access; ability to modify deployment configuration; ability to place a file on the host

The fix

The code should resolve the final path with os.path.abspath and check that it still starts with the base directory before executing anything.

How it was found

  1. Place a script on the host at an absolute path using low-privileged deployment access.
  2. Change the deployment configuration in the web dashboard to use that absolute path instead of a relative script path.
  3. Trigger the deployment so the agent runs the flawed path-joining logic and executes the script on the host.

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 tool tried to keep scripts inside a safe folder by gluing a folder name and a user-supplied file name together. In Python, if the user-supplied part starts with a slash, the gluing function throws away the safe folder and uses only the user's path. That let the attacker run their own script anywhere 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.

More by HackerMD

View all

7 more disclosed reports, best first.

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.