Skip to content
RCE Disclosed report Beginner

[extra-asciinema] Command Injection via insecure command formatting

The extra-asciinema module passes a user-supplied filename directly into a shell command without validation. An attacker who can control that filename could execute arbitrary commands on the victim's machine.

d3lla Follow

Originally disclosed on HackerOne

Critical View original
  • Triaged in 3 hours
  • Fixed in 4 months
  • Disclosed after 4 months

I would like to report a Command Injection issue in the extra-asciinema module. It allows to execute arbitrary commands on the victim's PC.

Module

module name: extra-asciinema version: 1.0.5 npm page: https://www.npmjs.com/package/extra-asciinema

Module Description

asciinema is a terminal screen recorder.

With this package you can auto-generate terminal recordings for Node.js examples through asciinema programmatically. Each method is also available as separate package for use by bundling tools, like browserify, rollup, uglify-js.

Module Stats

[23] weekly downloads

Vulnerability

Vulnerability Description

The issue occurs because a user input parameter is used inside a command that is executed without any check.

I tested the uploadSync function. Here's the code which causes the issue:

JavaScript
// https://github.com/nodef/extra-asciinema/blob/master/index.js#L214
...
const cp9 = require('child_process');
...
/**
 * Upload recorded asciicast to asciinema.org site.
 * @param {string} f filename
 * @returns {string} asciicast URL
 */
function uploadSync(f) {
  var stdout = cp9.execSync(`asciinema upload ${f}`, {encoding: 'utf8'});
  return stdout.replace(/.*?(https?:\S+).*/s, '$1');
}
...

The f parameter is used to build the command that is passed to the child_process.execSync function without any check.

Steps To Reproduce:

  • create a directory for testing

    • mkdir poc
    • cd poc/
  • install extra-asciinema module:

    • npm i extra-asciinema
  • create the following PoC JavaScript file (poc.js):

JavaScript
const asciinema = require('extra-asciinema');
asciinema.uploadSync('; touch HACKED');

  • make sure that the HACKED file does not exist:
    • ls
  • execute the poc.js file:
    • node poc.js
  • the HACKED file is created:
    • ls
poc_extra-asciinema.mov From the original on HackerOne

Patch

Do not concatenate/format commands using insecure user's input. Always check and sanitize it. In my opinion, it's better to use child_process.execFileSync or child_process.spawnSync functions instead of child_process.execSync.

Supporting Material/References:

  • OPERATING SYSTEM VERSION: Ubuntu 18.04.4 LTS
  • NODEJS VERSION: v13.13.0
  • NPM VERSION: 6.14.4

Wrap up

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

Thank you for your time.

best regards,

d3lla

Impact

Command Injection on extra-asciinema module via insecure command formatting.

The original report as published on HackerOne, by d3lla. 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 could execute arbitrary commands on the victim's PC, but only if they can control the filename passed to uploadSync.

What the attacker needed

Victim runs uploadSync with attacker-controlled filename

The fix

The module should avoid building shell commands from user input and instead use child_process.execFileSync or child_process.spawnSync with separate arguments.

How it was found

  1. Create a test directory and install the extra-asciinema module.
  2. Write a small JavaScript file that calls uploadSync with a filename containing a shell metacharacter and a command.
  3. Confirm that the target file does not exist.
  4. Run the JavaScript file with Node.js.
  5. Observe that the target file has been created, proving command execution.

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.

When a program builds a system command by gluing together text, any extra characters in that text can be interpreted as additional commands. Here, the filename is inserted into a command that runs the asciinema tool, so a filename containing a semicolon can start a second command. This lets an attacker run their own commands on the computer running the code.

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 d3lla

View all

16 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.