Skip to content
RCE Disclosed report Beginner

[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.

mik317 Follow

Originally disclosed on HackerOne

Medium 6.8 View original
  • 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:

  1. Create the following PoC file:
JavaScript
// poc.js
var git = require('npm-git-publish');
git.publish('.', 'http://gihub.com ;touch HACKED; #')

  1. Check there aren't files called HACKED
  2. Execute the following commands in another terminal:
Bash
npm i npm-git-publish # Install affected module
node poc.js #  Run the PoC
  1. Recheck the files: now HACKED has been created :)
    Screenshot_from_2019-11-05_22-27-27.png
    Screenshot_from_2019-11-05_22-27-27.png From the original on HackerOne

Patch

Don't format commands using insecure user'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

The original report as published on HackerOne, by mik317. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

  1. Create a small script that calls the module's publish function with a crafted remote URL.
  2. Confirm a marker file does not yet exist.
  3. Install the affected module and run the script.
  4. 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.

More by mik317

View all

23 more disclosed reports, best first.

More from Node.js third-party modules

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.