Useless P5 path traversal to RCE ☠️
A path traversal flaw let the author read the application's package.json file, which listed an npm dependency name that was unclaimed on the public registry. By publishing a package under that name with a higher version and a preinstall script, the author could run commands on any machine that later ran npm install.
medium.com
Published on medium.com
Apologies for the long time since our last writeup here on Medium, Let’s dive into a straightforward yet interesting RCE vulnerability story. It all started when I stumbled upon a path traversal vulnerability that allowed me to fetch the package.json file from the host using path traversal vulnerability, it’s a bug…
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 server failed to normalise the request path before resolving it against the filesystem, and the project depended on an npm package name that nobody had registered.
Impact
An attacker could execute commands on machines that install the project's dependencies, though the author notes the first several interactions came from an npm bot rather than a real user.
What the attacker needed
Path traversal that reads package.json; an unclaimed dependency name; attacker can publish to npm; victim runs npm install
The fix
The path traversal should be fixed by normalising and restricting requested paths, and dependency names should be checked against the registry or pinned to trusted sources.
How it was found
- Send a request with dot-dot sequences in the path to read package.json from the host.
- Inspect the dependency list for package names that return 404 on the public npm registry.
- Create a local package with the same name and a higher version number.
- Add a preinstall script that contacts a listener controlled by the attacker.
- Publish the package publicly with npm.
- Wait for real users to run npm install and observe their interactions on the listener.
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.
A path traversal bug lets someone use '..' in a URL to step outside the intended folder and read other files on the server. Here it exposed a list of software libraries the project depends on. One of those library names was free to register on npm, the public JavaScript package registry, so the author could publish their own package under that name. When a developer later installed dependencies, npm downloaded that package and ran a script inside it, giving the author command execution on the developer's machine.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.