CVE-2022-32223 Discovery: DLL Hijacking via npm CLI
Node.js versions before 16.16.0 and 14.20.0 on Windows, when OpenSSL is installed, search for a DLL named providers.dll in the current working directory. An attacker who can place a malicious DLL there can execute code with the privileges of the user running Node.js or npm.
Published on blog.aquasec.com
Aqua Team Nautilus recently discovered that all Node.js versions earlier than 16.16.0 (LTS) and 14.20.0 on Windows are vulnerable to dynamic link library (DLL) hijacking if OpenSSL is installed on the host. Attackers can exploit this vulnerability to escalate their privileges and establish persistence in a target…
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
Likely, Node.js built-in modules that depend on OpenSSL load a DLL named after the OpenSSL provider_sect setting without specifying a full path, so Windows falls back to searching the current working directory.
Impact
An attacker could execute code with the privileges of the user running Node.js or npm, potentially leading to privilege escalation or persistence, and could embed malicious DLLs in packages.
What the attacker needed
Windows host with Node.js below 16.16.0 or 14.20.0; OpenSSL installed with default config file; Attacker can write to current working directory; User runs npm or Node.js command
The fix
The vulnerability was fixed in Node.js 16.16.0 and 14.20.0 by changing how OpenSSL configuration is loaded, defaulting to a nodejs_conf section and allowing explicit configuration via environment variable or command-line option.
How it was found
- Run an npm command such as npm --version on Windows with Node.js and OpenSSL installed.
- Observe with Process Monitor that node.exe searches for providers.dll and does not find it.
- Create a malicious providers.dll and place it in the current working directory.
- Run the npm command again; the malicious DLL is loaded and its code executes.
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 Windows program needs extra code from a shared library (a DLL), it looks in several folders. If it does not find the library in the expected places, it may look in the folder you are currently working in. An attacker who can put a malicious DLL with the right name in that folder can make the program run their code instead.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.