Share via

Preventing Rogue DLL Loading in .NET 9 WPF Applications due to DLL Search Path Vulnerability

Akshatha CHHABRA 20 Reputation points
2025-05-13T15:52:19.9233333+00:00

Issue:

A WPF application targeting .NET 9 is published via ClickOnce. During a security test done security team, a malicious DLL named “VERSION.DLL” was placed in the application installation folder as shown in below image, which opens a calculator. Upon relaunching the application, this malicious DLL executed instead of the legitimate one.

User's image

Investigation Analysis:

Version.dll is a non core system dll present in System32 folder. The operating system first looks at the application installation folder and then looks in System32 folder as part of DLL search path during the app initialization.

In an ideal scenario, the Version.dll from the System32 folder would load, as observed in the Process Monitor image below:

ProcMon

However, if a malicious DLL with the same name is present in the working directory, it gets loaded instead, as shown in the Process Monitor image below:

ProcMon1

This behavior was reproduced with a simple console application targeting .NET 8 or .NET 9.

Operating System - Microsoft Windows [Version 10.0.22631.5189]

Steps to reproduce:

  1. Create a console application targeting .NET 8 or .NET 9.
  2. Place a rogue DLL named VERSION.dll in the bin\debug folder.
  3. Start the application via the executable.
  4. Result: The VERSION.dll gets loaded and executed, causing the application to fail to load.
  5. Expected Result: The VERSION.dll from the System32 folder should load, and the application should start normally.

Solutions tried but didn't work:

  1. Attempted to remove the current working directory from the DLL search path in the main() method. This did not work as the issue occurs before control reaches the Main method.
  2. Used a C/C++ bootstrapper to modify the DLL search path before calling the C# application. This solution also did not work.

Is there a way to prevent a malicious DLL with the same name as a non-core system DLL from being loaded? Feedback on this issue would be appreciated.

Developer technologies | .NET | .NET Runtime
0 comments No comments

Answer accepted by question author
  1. RLWA32 52,441 Reputation points
    2025-05-13T20:53:22.9733333+00:00

    The application folder resides in a user's profile. If a different user without administrator privilege is able to write to that location then system security is already compromised. If an untrustworthy administrator is dropping a rogue dll in some user's application folder then the system is already compromised and that action is probably the least of your worries. Similarly, if an application was installed to a protected file system location that is writable by a non-administrator then the system is already insecure. So in each case you are essentially asking how to protect an application on a system that is already compromised. The issue is not how to prevent a rogue dll from being loaded from an application folder but rather how did it get there in the first place?

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.