Skip to content
RCE Disclosed report Beginner CVE-2020-8178

OS Command Injection on Jison [all-parser-ports]

The Jison parser generator's C# and PHP port scripts pass command-line arguments directly to a shell command without sanitisation, allowing an attacker to execute arbitrary OS commands. An attacker who can control the argument to these scripts could run any command on the host.

Piyush Raj ~ Rex Follow

Originally disclosed on HackerOne

  • Triaged in 4 hours
  • Fixed in 8 months
  • Disclosed after 9 months

I would like to report OS Command Injection vulnerability on Jison in parser ports. (CSharp, PHP)

It allows arbitrary OS shell command execution through a crafted command-line argument.

Basic Information

Module: jison Version: 0.4.18 NPM Project Page: https://www.npmjs.com/package/jison

Module Description

An API for creating parsers in JavaScript

Jison generates bottom-up parsers in JavaScript. Its API is similar to Bison's, hence the name. It supports many of Bison's major features, plus some of its own. If you are new to parser generators such as Bison, and Context-free Grammars in general, a good introduction is found in the Bison manual. If you already know Bison, Jison should be easy to pickup. Briefly, Jison takes a JSON encoded grammar or Bison style grammar and outputs a JavaScript file capable of parsing the language described by that grammar. You can then use the generated script to parse inputs and accept, reject, or perform actions based on the input.

Module Stats

Downloads in the last week: (https://api.npmjs.org/downloads/point/last-week/jison)
downloads : 138857
start : 2019-08-31
end : 2019-09-06
package : jison
Downloads in the last month: (https://api.npmjs.org/downloads/point/last-month/jison)
downloads : 678197
start : 2019-08-08
end : 2019-09-06
package : jison

Stats by npm-stat: https://npm-stat.com/charts.html?package=jison

Vulnerability

Jison has parsing/lexing template to php, C# which don't sanitize process.argv (command line arguments), before passing it to child_process.exec(), hence allowing arbitrary shell command injection.

The vulnerable code is in /ports/csharp/Jison/Jison/csharp.js at csharp.js#L19

console.log("Executing: " + "jison " + process.argv[2]);

exec("jison " + process.argv[2], function (error) {
    if (error) {
        console.log(error);
        return;
    }

Steps To Reproduce:

  1. Installing Jison command-line tool via npm install jison -g
  2. Obtaining Jison parsing templates : git clone https://github.com/zaach/jison
  3. cd jison/ports/csharp/Jison/Jison/
  4. Payload : node csharp.js "echo''>pwned"
  5. Check if the attack was successful or not (dummy payload was executed or not): ls -la

Similarly, /ports/php/php.js is vulnerable too as it contains the same blob (php.js#L19). "" was added just to isolate the payload.

Patch

Sanitizing the input. Using execFile (this method signatures force developers to separate the command and its arguments)

Supporting Material/References:

  • Windows 10 1803 (OS Build 17134.950)
  • NodeJS Version: v10.16.3
  • NPM Version: 6.9.0

Wrap up

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

Impact

Arbitrary OS command execution.

Attachments

jison-osi.png
jison-osi.png From the original on HackerOne

The original report as published on HackerOne, by 0x48piraj. 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 scripts build a shell command by concatenating a user-supplied command-line argument and pass it to child_process.exec(), which runs it through a shell without sanitisation.

Impact

An attacker could execute arbitrary OS commands on the host running the vulnerable script.

What the attacker needed

Ability to control the command-line argument; Jison port script is run

The fix

The input should be sanitised, and execFile should be used to separate the command from its arguments.

How it was found

  1. Install the Jison command-line tool globally using npm.
  2. Clone the Jison repository to obtain the parsing templates.
  3. Change into the C# port directory.
  4. Run the C# script with a crafted argument that includes a shell command.
  5. List the directory to check whether the command created a 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.

Jison is a tool that helps programmers build parsers. Some helper scripts for other languages take a command-line argument and run it as part of a system command without checking it. If an attacker can supply that argument, they can make the computer run any command they want.

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.