RCE via Dependency Confusion: A Real-World Attack on Unclaimed np
An internal Node.js SDK package name found in a public GitHub package.json was unclaimed on the public npm registry, so the researcher published a package with the same name and a higher version containing a preinstall script. Any developer or CI system that installed or updated the dependency could have run the script, which exfiltrated host details and system files to an attacker server.
ABDELKARIM MOUCHQUELITA Follow
Published on mchklt.medium.com
Before i would say don’t underestimate yourself when it comes to learning something new. I once came across an article on this topic a year ago, but I didn’t try to understand it because I thought it was beyond me.
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 internal package name was never reserved on the public npm registry, and the installer resolved the higher public version over the private one.
Impact
Any developer or system that installed or updated the package could have had host details and system files sent to the attacker, and the author notes a reverse shell was also possible but not used.
What the attacker needed
Internal package name visible publicly; name unclaimed on public npm; victim installs or updates the package
How it was found
- Find an internal package name in a public package.json on GitHub.
- Check the public npm registry and confirm the name is unclaimed.
- Create a package with that name and a higher version, with a preinstall script that runs code.
- Publish the package to npm.
- Wait for installs and capture the exfiltrated data on the attacker server.
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.
Projects often pull in helper code called packages from a public library like npm. If a company uses a private package name that nobody has registered publicly, anyone can register that name and publish their own version. When the project installs dependencies, it may grab the attacker's version instead of the private one, and that package can run code on the machine during installation.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.