Skip to content
RCE Disclosed report Beginner

[ascii-art] Command injection

The ascii-art npm module passed an unsanitised command line argument into a shell command, so a crafted argument could run arbitrary shell commands. An attacker who can influence that argument could execute commands on the host running the tool.

pontus_johnson Follow

Originally disclosed on HackerOne

High 8.6 View original
  • Triaged in 36 hours
  • Fixed in 34 days
  • Disclosed after 34 days

Summary by the program

vulnerable versions: < 1.4.4 patched versions: >= 1.4.4

The report

I would like to report a command injection vulnerability in the ascii-art npm module. It allows arbitrary shell command execution through a maliciously crafted command line argument.

Module

module name: ascii-art version: 1.4.3 npm page: https://www.npmjs.com/package/ascii-art

Module Description

Images, fonts, tables, ansi styles and compositing in Node.js & the browser. 100% JS.

In the beginning there was colors.js but in the fine tradition of vendors calling out a problem they have the solution to, chalk was introduced. In that same vein, I offer ascii-art as an update, expansion and generalization of MooAsciiArt and at the same time it can replace your existing ansi colors library.

It features support for Images, Styles, Tables and Figlet Fonts as well as handling multi-line joining automatically.

Module Stats

56 downloads in the last day 217 downloads in the last week 1432 downloads in the last month

Vulnerability

Vulnerability Description

ascii-art does not sanitize the target command line argument, and subsequently passes it to child_process.exec(), thus allowing arbitrary shell command injection.

Steps To Reproduce:

  1. Install ascii-art: sudo npm install -g ascii-art (On a pristine Google Cloud instance, I also had to install pkg-config, libcairo2-dev, libjpeg-dev and libgif-dev, and then install ascii-art with unsafe-perm=true).
  2. Run ascii-art with malicious argument: ascii-art preview 'doom"; touch /tmp/malicious; echo "'
  3. Check that the injected command was executed: ls /tmp/

Patch

Command execution happens here:

exec('open "http://www.figlet.org/fontdb_example.cgi?font='+target.toLowerCase()+'.flf"')

exec could be replaced by execFile, which would force developers to separate the command and its arguments.

Supporting Material/References:

  • Operating system: Debian GNU/Linux 9.5 (stretch)
  • Node.js v8.11.3
  • npm v5.6.0

Wrap up

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

Impact

Arbitrary shell command execution.

The original report as published on HackerOne, by pontus_johnson. 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 target argument was concatenated into a string passed to child_process.exec, so shell metacharacters in the argument were interpreted by the shell.

Impact

Arbitrary shell command execution on the machine running the tool, with the privileges of that user.

What the attacker needed

Ability to control the tool's argument; ascii-art below 1.4.4 installed

The fix

The text suggests replacing exec with execFile so command and arguments are separate; it does not say this was the actual patch.

How it was found

  1. Install the ascii-art module globally, along with any native build dependencies needed on the system.
  2. Run the tool's preview command with an argument that contains shell syntax alongside the font name.
  3. List the temporary directory to confirm the injected 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.

Some programs build a shell command as a piece of text and hand it to the operating system to run. If part of that text comes from user input and is not cleaned, the user can add extra shell instructions that also get run. Here the tool took a font name from the command line and pasted it into a command that opens a web address, so a font name containing shell syntax ran extra 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 by pontus_johnson

View all

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