Dynamic Linking Injection and LOLBAS Fun
A .NET web application passed user-controlled input to LoadLibrary and GetProcAddress, allowing an attacker to load arbitrary DLLs and invoke arbitrary functions. This could lead to local privilege escalation or remote code execution by abusing native Windows functions.
Published on praetorian.com
LoadLibrary and LoadLibraryEx are how Windows applications load shared libraries at runtime. Praetorian recently tested a .NET web application that unsafely passed user input into LoadLibrary.
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 application passed unsanitised user input directly to LoadLibrary and GetProcAddress without validating the library path or function name.
Impact
An attacker could execute arbitrary code as the service account, leading to local privilege escalation or remote code execution.
What the attacker needed
Ability to send HTTP requests; local access to plant a DLL (for some scenarios); knowledge of function signature (for remote exploitation)
How it was found
- Send a POST request with modified 'engine' and 'method' parameters to observe error messages.
- Use Process Monitor to filter for Load Image events and identify the DLL being loaded.
- Plant a malicious DLL in a world-writable directory.
- Send a request with a path traversal to load the malicious DLL.
- Use WinDBG to determine the function signature of the exported method.
- Use a native Windows function like URLDownloadToFileW to download and execute a remote DLL.
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.
This bug is like letting a user choose which program file to run. The application took a user-supplied name and loaded it as a library, so an attacker could point it to a malicious file and run their own code.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.