So search order hijacking depends on have their malicious DLL in the PATH var ? So I made every PATH dir non-writable.
In programming as you know, there is this concept of breaking down code to small chunks. For various reasons, nobody wants one long pile of spaghetti code.
The code is broken down across many executables and modules.
For the software to know which module it has to load from where, the following is possible:
- You can write hardcoded paths set in stone. It can be written in the registry, in various files like ini, in the executable logics. This is HIGHLY undesirable for various reasons.
- Potentially, I can write the installdir and various other directories needed for functionality, then construct the paths in real time.
The other way to do it, is to just specify the name of the module that needs to be loaded. Windows will then go around looking for module with this name in this order:
- The Application's Directory: The folder where the application's executable (.exe) is located. This is the primary location attackers target
- The System Directory: C:\Windows\System32
- The 16-bit System Directory: C:\Windows\System (mainly for legacy reasons)
- The Windows Directory: C:\Windows
- Directories in the PATH Environment Variable: The folders listed in the system's PATH variable, searched in order.
- The Current Directory: The directory from which the application was launched.
So let's say that my portable application TudaPlayer has TudaPlayer.exe and ccCodecSupport.dll.
TudaPlayer is a very popular and widespread app that I've signed submitted to AV vendors as well. Most of these vendors now trust TudaPlayer, potentially excluding it from behavioural monitoring as well (some AVs do not monitor trusted and prevalent apps).
When I've been writing TudaPlayer, I couldn't have placed hardcoded variables/constants with the module paths - it is a portable app, I don't know where you will download and extract it.
Attacker replaces ccCodecSupport.dll with a fake copy that performs malicious actions. These actions are now hidden behind my trusted app and potentially, the AV has a blind spot.
There is very little you can do to prevent this. To make things more exciting, attacker can create subdirectories, something like "Resources" and place a few fictional files, along with the real DLL. Attackers can load the real DLL through instructions in the malicious one. In this case, the player will function.
Assuming that ccCodecSupport.dll is not signed, SAC could block its loading.