Skip to content
RCE Write-up Intermediate

CVE-2016-4991: Command injection in NodePDF

The NodePDF library passed user input to a shell command after an incomplete escape, allowing an attacker to inject shell metacharacters and execute arbitrary commands. The example shows a crafted URL causing the shell to run an echo command and the 'w' command.

amlw.dev

Published on amlw.dev

Software: nodepdf Website: https://github.com/TJkrusinski/NodePDF

The author, on amlw.dev

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The shell-escape library failed to encode semicolons and curly braces, so input passed to child_process.exec() could break out of the intended command and inject additional shell commands.

Impact

An attacker could execute arbitrary shell commands on the server hosting the application, potentially leading to full system compromise.

What the attacker needed

Application uses nodepdf with user-controlled input

The fix

The vulnerability was fixed in the shell-escape library, which now properly encodes all special characters.

How it was found

  1. Install the vulnerable version of the nodepdf package.
  2. Create a script that calls the Pdf() function with a URL containing shell metacharacters.
  3. Run the script and observe the output showing the injected command executed.

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 write-up has not been written yet. The Original tab links to the source.

When a program builds a command for the operating system, it must carefully handle special characters like semicolons and braces. Here, the escaping was incomplete, so an attacker could sneak in extra commands that the system would run. This is dangerous because it lets an attacker run their own code on the server.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

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.