Node.js - DLL Hijacking on Windows
Node.js on Windows would load a DLL named providers.dll from the current directory or other search paths when OpenSSL configuration was present. An attacker could place a malicious DLL to achieve local privilege escalation, persistence, or code execution via a malicious package.
- Triaged in 29 hours
- Fixed in 11 days
- Paid in 11 days
- Disclosed after 11 days
Summary by the program
DLL Hijacking on Windows (High)(CVE-2022-32223) This vulnerability can be exploited if the victim has the following dependencies on Windows machine:
OpenSSL has been installed and “C:\Program Files\Common Files\SSL\openssl.cnf” exists. Whenever the above conditions are present, node.exe will search for providers.dll in the current user directory. After that, node.exe will try to search for providers.dll by the DLL Search Order in Windows.
It is possible for an attacker to place the malicious file providers.dll under a variety of paths and exploit this vulnerability.
More details will be available at CVE-2022-32223 after publication.
Thank you to Yakir Kadkoda from Aqua Security for reporting this vulnerability.
Impacts:
All versions of the 16.x, and 14.x releases lines.
Full Security Advisory: https://nodejs.org/en/blog/vulnerability/july-2022-security-releases/
The report
Full Node.js Security Releases - summarizing the issue is here:https://nodejs.org/en/blog/vulnerability/july-2022-security-releases/ The original Node.js HackerOne report is here: https://hackerone.com/bugs?report_id=1447455
Node.js versions earlier than 16.16.0 (LTS) and 14.20.0 are vulnerable to dynamic link library (DLL) hijacking. Attackers can exploit this vulnerability to escalate their privileges and establish persistence in a target environment. The vulnerability can also provide another way to embed malicious code into packages.
This vulnerability can be exploited if the victim has the following dependencies on Windows machine:
- OpenSSL has been installed or “C:\Program Files\Common Files\SSL\openssl.cnf” exists.
Whenever the above conditions are present, node.exe will search for providers.dll in the current user directory. After that, node.exe will try to search for providers.dll by the DLL Search Order in Windows.
It is possible for an attacker to place the malicious file providers.dll under a variety of paths and exploit this vulnerability. This was fixed in Node.js 16.16.0 and 14.20.0 versions.
Impact
A locally unprivileged attacker could perform a local privilege escalation, also It is possible for an attacker to place the malicious file "providers.dll" under a variety of paths (or under any other custom name via changing "Providers=provider_sect" providers filed to other package name( In addition, the attackers may upload packages containing malicious dlls which run on the victim's windows machine after they download them. The victim will not see any interaction with the dll in package code, so if he doesn't analyze the dll and decides to install the package, then the code will run.
Context
Node.js on Windows loads a dynamic link library named providers.dll as part of its OpenSSL integration. The report describes a DLL hijacking issue in that loading path: when certain OpenSSL configuration is present on the machine, node.exe resolves providers.dll through the standard Windows DLL search order, and an attacker who can place a file with that name in one of the searched locations can get their code loaded by Node.js.
The issue was reported to the Internet Bug Bounty programme on HackerOne by Yakir Kadkoda of Aqua Security, and is tracked as CVE-2022-32223. The programme rated it High with a CVSS score of 7.2, under the weakness category Untrusted Search Path. The affected asset is the Node.js repository at https://github.com/nodejs/node, and the report was disclosed on 25 July 2022.
Setup
The vulnerability is Windows-specific and depends on the state of the victim's machine rather than on anything the attacker controls remotely. The report lists the preconditions as follows:
- OpenSSL has been installed, or the file
C:\Program Files\Common Files\SSL\openssl.cnfexists. - The victim runs a vulnerable Node.js version: releases earlier than 16.16.0 (LTS) and 14.20.0. The programme summary states that all versions of the 16.x and 14.x release lines are impacted.
When those conditions hold, node.exe searches for providers.dll in the current user directory and then continues through the Windows DLL search order. No account, role or special tooling is described beyond a Windows host meeting the above conditions.
Finding it
Node.js resolves providers.dll dynamically on Windows once the OpenSSL configuration file is present. Because the resolution follows the Windows DLL search order, the name is looked up in a variety of paths where an attacker may be able to place a file. That makes the load path attacker-influenced: a file named providers.dll placed in one of those searched paths will be picked up by node.exe instead of a legitimate library.
The report frames this as a dynamic link library hijacking issue, and notes that the same mechanism can be used to embed malicious code into packages.
Exploitation
Step 1: Confirm the preconditions on the target
The attacker needs a Windows machine where OpenSSL has been installed or where C:\Program Files\Common Files\SSL\openssl.cnf exists, and where a vulnerable Node.js version (earlier than 16.16.0 or 14.20.0) is in use.
Step 2: Place the malicious library
With the preconditions met, node.exe will search for providers.dll in the current user directory and then by the DLL Search Order in Windows. The attacker places a malicious file named providers.dll in one of the paths covered by that search order. The report states that a variety of paths are usable for this.
Step 3: Trigger the load
When Node.js starts under those conditions, it resolves providers.dll through the search order and loads the attacker's file. The report does not include a command line, a payload listing or a captured response for this step; the mechanism described is the search and load itself.
Step 4: Alternative naming through the OpenSSL configuration
The report notes that the library name is not fixed to providers.dll: an attacker can use any other custom name by changing the Providers=provider_sect providers field to another package name. In that case the correspondingly named DLL is what Node.js looks for.
Step 5: Delivery through a package
Beyond local placement, attackers may upload packages containing malicious DLLs which run on the victim's Windows machine after the victim downloads them. The victim sees no interaction with the DLL in the package code, so if they do not analyse the DLL and decide to install the package, the code runs.
Root cause
The mistake is an untrusted search path: node.exe resolves providers.dll by name through the Windows DLL search order, which includes directories that are not trusted for library loading. The OpenSSL configuration file being present is what puts Node.js on this code path. The load happens through the normal search order rather than through an absolute, trusted path, so a file planted in a searched directory is accepted as the library. The report does not go into the specific code change or the internal call site, so the exact implementation detail is not stated here.
Impact
A locally unprivileged attacker could perform a local privilege escalation. Because the malicious providers.dll can be placed under a variety of paths, the issue also gives another way to embed malicious code into packages: a package can ship a DLL that runs on the victim's Windows machine after download, without any visible interaction in the package code. The report also notes that the custom name option via the Providers=provider_sect field widens what an attacker can plant. The programme summary lists the impact as applying to all versions of the 16.x and 14.x release lines.
Fix
The issue was fixed in Node.js 16.16.0 and 14.20.0. The report points to the July 2022 Node.js security releases for the full advisory. It does not describe the code change itself, so the specific fix mechanism is not stated here.
Variants to test
- Other Node.js components that load DLLs by name on Windows: check whether any of them resolve a library through the search order when a configuration file or environment setting is present. A positive result is a library loaded from a user-writable directory.
- Other OpenSSL configuration directives that name a module or provider: try changing the provider field to a custom name and see whether the correspondingly named DLL is searched for. A positive result is a load attempt for the custom name.
- Package-based delivery: install a package that ships a DLL matching a searched name and observe whether it executes on a Windows host with the preconditions present. A positive result is code execution without any visible interaction in the package code.
- Different vulnerable version lines: test hosts on 16.x and 14.x releases earlier than the fixed versions to confirm the behaviour, and on 16.16.0 and 14.20.0 to confirm it is gone.
What happened, in plain words
Node.js is a program that lets people run JavaScript code outside a web browser, for example on a server or on a Windows PC. On Windows, programs often do not contain all their code in one file. They borrow pieces of code from separate files called dynamic link libraries, or DLLs for short. When a program starts, Windows has to find each DLL it needs and load it.
This report is about a problem in how Node.js on Windows finds one particular DLL, called providers.dll. That DLL is part of Node.js's connection to OpenSSL, a widely used toolkit for encryption (the maths that keeps data private). Under certain conditions, node.exe (the Node.js program file on Windows) goes looking for providers.dll by name, and Windows searches a list of folders in a fixed order. Some of those folders can be written to by an ordinary user, or by whoever built a package the victim installs. If an attacker puts a file called providers.dll in one of those folders, Node.js may load the attacker's file instead of the real one. That is called DLL hijacking: someone else's library gets loaded in place of the intended one.
The issue was reported to the Internet Bug Bounty programme on HackerOne by Yakir Kadkoda of Aqua Security. It is tracked as CVE-2022-32223. CVE stands for Common Vulnerabilities and Exposures: a public catalogue number given to a known security flaw so people can refer to it unambiguously. The programme rated it High with a CVSS score of 7.2. CVSS is a standard scoring system for how serious a vulnerability is; 7.2 sits in the High band. The weakness category is Untrusted Search Path, which is the formal name for this kind of problem: a program looks for a file in a place it should not trust. The affected asset is the Node.js repository at https://github.com/nodejs/node, and the report was disclosed on 25 July 2022.
A useful everyday comparison: imagine a courier who is told to collect a parcel called "providers" but is not told which building. The courier checks a list of addresses in order and takes the first parcel with that name. If someone leaves a fake parcel with the right name at an address the courier checks early, the courier picks up the fake one. The program is the courier, the DLL name is the parcel name, and the Windows search order is the list of addresses.
Setup
This vulnerability is specific to Windows, and it depends on the state of the victim's machine rather than on anything the attacker can do remotely over the internet. In other words, the attacker does not need to break in from outside; they need a way to put a file on the machine, or to get the victim to install something that does.
The report lists the preconditions as follows:
- OpenSSL has been installed, or the file
C:\Program Files\Common Files\SSL\openssl.cnfexists. - The victim runs a vulnerable Node.js version: releases earlier than 16.16.0 (LTS) and 14.20.0. The programme summary states that all versions of the 16.x and 14.x release lines are impacted.
A few terms here. OpenSSL is the encryption toolkit mentioned above; installing it is common on machines that need to handle secure connections. openssl.cnf is a configuration file: a plain text file that tells OpenSSL how to behave. LTS stands for Long Term Support, a release line that the project keeps maintained for longer. The path C:\Program Files\Common Files\SSL\openssl.cnf is simply where that configuration file lives on a typical Windows install.
When those conditions hold, node.exe searches for providers.dll in the current user directory and then continues through the Windows DLL search order. The current user directory is the folder the program was started from. The Windows DLL search order is the fixed list of places Windows checks, in sequence, when a program asks for a DLL by name alone. No account, role or special tooling is described beyond a Windows host meeting the above conditions.
Finding it
Node.js resolves providers.dll dynamically on Windows once the OpenSSL configuration file is present. "Resolves" here means "works out which file to load". "Dynamically" means the program decides at run time, by name, rather than being hard-wired to one exact file location.
Because the resolution follows the Windows DLL search order, the name is looked up in a variety of paths where an attacker may be able to place a file. An unprivileged user is someone using the computer without administrator rights. A package author is someone who publishes a reusable bundle of code (a package) that others download and install. That makes the load path attacker-influenced: a file named providers.dll placed in one of those searched paths will be picked up by node.exe instead of a legitimate library.
The report frames this as a dynamic link library hijacking issue, and notes that the same mechanism can be used to embed malicious code into packages. "Embed" here means hiding the harmful part inside something that looks ordinary, so it arrives as part of a normal download.
Exploitation
Step 1: Confirm the preconditions on the target
The attacker needs a Windows machine where OpenSSL has been installed or where C:\Program Files\Common Files\SSL\openssl.cnf exists, and where a vulnerable Node.js version (earlier than 16.16.0 or 14.20.0) is in use. This step is about checking the ground is ready before doing anything else: if the configuration file is not there, Node.js does not take the code path that looks for providers.dll, and the trick does not work.
Step 2: Place the malicious library
With the preconditions met, node.exe will search for providers.dll in the current user directory and then by the DLL Search Order in Windows. The attacker places a malicious file named providers.dll in one of the paths covered by that search order. The report states that a variety of paths are usable for this. The reason this works is the courier comparison again: the program asks for a name, not a full address, so any folder on the search list is a candidate, including folders an ordinary user can write to.
Step 3: Trigger the load
When Node.js starts under those conditions, it resolves providers.dll through the search order and loads the attacker's file. The report does not include a command line, a payload listing or a captured response for this step; the mechanism described is the search and load itself. In plain terms, the mechanism described is the search and load itself.
Step 4: Alternative naming through the OpenSSL configuration
The report notes that the library name is not fixed to providers.dll: an attacker can use any other custom name by changing the Providers=provider_sect providers field to another package name. In that case the correspondingly named DLL is what Node.js looks for. The Providers=provider_sect line is a setting inside the OpenSSL configuration file; it tells OpenSSL which provider (a pluggable module of encryption code) to use. Changing that setting changes the name Node.js goes looking for, so the attacker is not limited to one filename.
Step 5: Delivery through a package
Beyond local placement, attackers may upload packages containing malicious DLLs which run on the victim's Windows machine after the victim downloads them. The victim sees no interaction with the DLL in the package code, so if they do not analyse the DLL and decide to install the package, the code runs. This is the part that matters most for people who are not system administrators: you do not have to be attacked directly. You install something that looks normal, and the harmful DLL rides along. Analysing a DLL means opening it with tools that inspect what it actually does, which most users never do.
Root cause
The mistake is an untrusted search path: node.exe resolves providers.dll by name through the Windows DLL search order, which includes directories that are not trusted for library loading. The OpenSSL configuration file being present is what puts Node.js on this code path. The load happens through the normal search order rather than through an absolute, trusted path, so a file planted in a searched directory is accepted as the library. An absolute path is a full address, like a street address with house number; a name-only lookup is like asking for "the parcel called providers" and trusting whoever answers first. The report does not go into the specific code change or the internal call site, so the exact implementation detail is not stated here.
Impact
A locally unprivileged attacker could perform a local privilege escalation. Privilege escalation means going from a low level of permission (an ordinary user) to a higher one (for example an administrator), which lets the attacker do far more on the machine. Because the malicious providers.dll can be placed under a variety of paths, the issue also gives another way to embed malicious code into packages: a package can ship a DLL that runs on the victim's Windows machine after download, without any visible interaction in the package code. The report also notes that the custom name option via the Providers=provider_sect field widens what an attacker can plant. The programme summary lists the impact as applying to all versions of the 16.x and 14.x release lines.
Fix
The issue was fixed in Node.js 16.16.0 and 14.20.0. The report points to the July 2022 Node.js security releases for the full advisory. An advisory is the official notice a project publishes to tell users what was wrong and what to upgrade to. The report does not describe the code change itself, so the specific fix mechanism is not stated here.
Variants to test
- Other Node.js components that load DLLs by name on Windows: check whether any of them resolve a library through the search order when a configuration file or environment setting is present. A positive result is a library loaded from a user-writable directory.
- Other OpenSSL configuration directives that name a module or provider: try changing the provider field to a custom name and see whether the correspondingly named DLL is searched for. A positive result is a load attempt for the custom name.
- Package-based delivery: install a package that ships a DLL matching a searched name and observe whether it executes on a Windows host with the preconditions present. A positive result is code execution without any visible interaction in the package code.
- Different vulnerable version lines: test hosts on 16.x and 14.x releases earlier than the fixed versions to confirm the behaviour, and on 16.16.0 and 14.20.0 to confirm it is gone.
Glossary
- Node.js: a program that runs JavaScript code outside a web browser, often on servers or Windows PCs.
- DLL (dynamic link library): a separate file of reusable code that a program loads when it needs it, rather than containing everything in one file.
- DLL hijacking: tricking a program into loading an attacker's DLL in place of the intended one, usually by placing a file with the right name where the program looks.
- OpenSSL: a widely used toolkit that provides encryption for secure connections.
openssl.cnf: the configuration file that tells OpenSSL how to behave.- Configuration file: a plain text file of settings that a program reads at start-up.
node.exe: the Node.js program file on Windows.providers.dll: the DLL that Node.js looks for as part of its OpenSSL integration on Windows.- Windows DLL search order: the fixed list of folders Windows checks, in sequence, when a program asks for a DLL by name alone.
- Current user directory: the folder a program was started from, often writable by the user.
- Resolve: work out which file to load for a given name.
- Dynamically: decided at run time, by name, rather than fixed to one exact file location.
- Absolute path: a full file address, as opposed to a name-only lookup.
- Untrusted search path: the weakness category for a program looking for a file in a location it should not trust.
- CVE: Common Vulnerabilities and Exposures, a public catalogue number for a known security flaw.
- CVSS: a standard scoring system for the severity of a vulnerability; 7.2 is in the High band.
- LTS (Long Term Support): a release line a project keeps maintained for longer.
- Unprivileged user: someone using a computer without administrator rights.
- Package: a reusable bundle of code that people download and install.
- Package author: the person who publishes a package.
- Provider (OpenSSL): a pluggable module of encryption code that OpenSSL can load.
Providers=provider_sect: a setting in the OpenSSL configuration file that names which provider to use.- Privilege escalation: moving from a low level of permission to a higher one, for example from ordinary user to administrator.
- Advisory: the official notice a project publishes about a security issue and the upgrade that fixes it.
- HackerOne: the platform where the report was filed.
- Internet Bug Bounty: the programme that handled the report.