Skip to content
RCE Disclosed report Beginner

[git-lib] RCE via insecure command formatting

The git-lib npm module builds a shell command by inserting user-supplied input without any validation, so a crafted argument can run extra shell commands. An attacker who can influence that input could execute arbitrary commands on the victim's machine.

mik317 Follow

Originally disclosed on HackerOne

Medium 6.4 View original
  • Triaged in 2 hours
  • Fixed in 10 months
  • Disclosed after 11 months

I would like to report a RCE issue in the git-lib module. It allows to execute arbitrary commands remotely inside the victim's PC

Module

module name: git-lib version: 1.6.0 npm page: https://www.npmjs.com/package/git-lib

Module Description

A library that contains different methods to be consumed by a node module

Module Stats

[~4/5] downloads in the last day [30] downloads in the last week [~120] 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/shime/git-lib/blob/master/index.js#L32

Steps To Reproduce:

  1. Create the following PoC file:
JavaScript
// poc.js
var git = require("git-lib");

git.add("test;touch HACKED;").then(function(){
    /** successfully added **/
}).catch(function(err){
    /** unsuccessful **/
});

  1. Check there aren't files called HACKED
  2. Execute the following commands in another terminal:
Bash
npm i git-lib # Install affected module
git init # Avoid problems with *git*
node poc.js #  Run the PoC
  1. Recheck the files: now HACKED has been created :)
    Screenshot_from_2019-10-20_13-47-50.png
    Screenshot_from_2019-10-20_13-47-50.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 git-lib

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 library concatenates user input into a shell command string instead of passing arguments safely, so shell metacharacters are interpreted.

Impact

An attacker able to control the input passed to the library could execute arbitrary commands on the victim's PC.

What the attacker needed

Victim uses git-lib 1.6.0; attacker controls input passed to the library

How it was found

  1. Create a small script that calls the library's add function with an argument containing extra shell commands.
  2. Confirm that no file named HACKED exists yet.
  3. Install the affected module and initialise a git repository.
  4. Run the script and check again: the extra file has now been 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 library runs a system command for you, and it pastes whatever text you give it straight into that command. Special characters in that text can end the original command and start a new one, so the person supplying the text can run their own programs on the machine. That is called remote code execution, meaning someone else's code runs on your 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.