Skip to content
Access control Disclosed report Intermediate CVE-2021-22921CVE-2021-29221CVE-2021-22117

Node Installer Local Privilege Escalation

The Node.js installer on Windows created an installation directory with permissions that allowed any local user to write files, and added that directory to the system PATH. An unprivileged attacker could place a malicious executable or DLL there, which would then be run by a privileged user, leading to privilege escalation.

deepsurface-robert Follow with deepsurface

Originally disclosed on HackerOne

Medium 6.7 View original
  • Triaged in 8 days
  • Fixed in 35 days
  • Paid in 40 days
  • Disclosed after 35 days

Node is vulnerable to local privilege escalation attacks under certain conditions on Windows platforms. More specifically, improper configuration of permissions in the installation directory allows an attacker to perform two different escalation attacks: PATH and DLL hijacking.

To demonstrate this flaw, we first download the latest version of Node from https://nodejs.org/en/download/. At the time of writing, this was node version 14.17.0.

We follow the standard installation steps, except for the installation directory, which we change to C:\tools. This directory can either be created through the installer GUI, or through mkdir C:\tools.

image1.png
image1.png From the original on HackerOne

We also select the option in a later step to “automatically install the necessary tools”.

In the screenshot below, note the improper permissions, BUILTIN\Users Allow *, on the installation directory, which are inherited from the drive root. This gives any local user the ability to create arbitrary files in the installation directory.

image4.png
image4.png From the original on HackerOne

This unprotected directory has also been added to the system PATH variable, allowing an attacker to drop malicious executables in that directory and have them executed by other users in certain circumstances. (Note that you may have to start a new powershell instance to see the PATH change.)

image5.png
image5.png From the original on HackerOne

To fully demonstrate the implications of this vulnerability, first create a new unprivileged user. Then, as this user, drop a malicious exe into the C:\tools directory and rename it to npm.exe. For testing purposes, you can simply do cp node.exe npm.exe. Note that the same could be done for npx.

Windows will search for a program with the .exe extension first, meaning that the malicious npm.exe will take precedence over npm.cmd.

Now, as the privileged user, try running npm. This should drop you into the node shell, demonstrating how an attacker could run a malicious executable.

image2.png
image2.png From the original on HackerOne

A writable PATH directory would also allow an attacker to hijack the execution of any commands that come later in the path. From the default node installation, this would include chocolatey, a software management tool for Windows. However, such a vulnerability could also affect all programs installed in the future as well.

Aside from the PATH vulnerability, the insecure permissions configured could also allow an attacker to perform a DLL hijacking attack against the node.exe. Using Process Monitor, we can confirm that node attempts to load a number of DLLs from the unprotected folder.

image3.png
image3.png From the original on HackerOne

For more information on DLL hijacking attacks, see our blog post.

It is worth noting that a very similar problem was discovered in RabbitMQ and reported by the DeepSurface Security research team. The RabbitMQ team fixed this issue in May 2021. For more information, see: CVE-2021-22117.

Impact

A locally unprivileged attacker could perform a local privilege escalation attack through PATH and DLL hijacking.

The original report as published on HackerOne, by deepsurface-robert. 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 installer inherited overly permissive access control settings from the drive root, granting write access to all local users on the installation directory, and then added that directory to the system PATH.

Impact

A locally unprivileged attacker could escalate privileges by hijacking the execution of npm or other commands via PATH, or by DLL hijacking against node.exe.

What the attacker needed

Node.js installed on Windows with custom directory; Attacker has local unprivileged access; Privileged user runs a command from the affected directory

How it was found

  1. Download the Node.js installer and start it.
  2. Change the installation directory to C:\tools and select the option to automatically install necessary tools.
  3. Observe that the C:\tools directory has permissions allowing any user to create files, and that it is added to the system PATH.
  4. Create a new unprivileged user account.
  5. As that unprivileged user, place a malicious executable named npm.exe into C:\tools.
  6. As a privileged user, run npm, which executes the malicious npm.exe instead of the legitimate npm.cmd.

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 you install software, the installer sometimes creates a folder that any user on the computer can write to. If that folder is also in the list of places Windows looks for programs (the PATH), a low-privilege user can put a fake program there. When an administrator later runs a command, Windows might run the fake program instead, giving the attacker the administrator's powers.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More from Node.js

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.