DLL stands for Dynamic Link Libraries and are external parts of applications that run on Windows or any other operating system. Most applications are not complete in themselves and store code in different files. If there is a need for the code, the related file is loaded into memory and used. This reduces application file size while optimizing the usage of RAM. This article explains what is DLL Hijacking and how to detect and prevent it.
What are DLL Files or Dynamic Link Libraries
DLL files are Dynamic Link Libraries and as evident by the name, are extensions of different applications. Any application we use may or may not use certain codes. Such codes are stored in different files and are invoked or loaded into RAM only when the related code is required. Thus, it saves an application file from becoming too big and prevents resource hogging by the application.
The path for DLL files are set by the Windows operating system. The path is set using Global Environmental Variables. By default, if an application requests a DLL file, the operating system looks into the same folder in which the application is stored. If it is not found there, it goes to other folders as set by the global variables. There are priorities attached to paths and it helps Windows in determining what folders to look for the DLLs. This is where the DLL hijacking comes in.
What is DLL Hijacking
Since DLLs are extensions and necessary to using almost all applications on your machines, they are present on the computer in different folders as explained. If the original DLL file is replaced with a fake DLL file containing malicious code, it is known as DLL Hijacking.
As mentioned earlier, there are priorities as to where the operating system looks for DLL files. First, it looks into the same folder as the application folder and then goes searching based on the priorities set by the operating system’s environment variables. Thus if a good.dll file is in SysWOW64 folder and someone places a bad.dll in a folder that has higher priority compared to SysWOW64 folder, the operating system will use the bad.dll file, as it has the same name as the DLL requested by the application. Once in RAM, it can execute the malicious code contained in the file and may compromise your computer or networks.
How to detect DLL Hijacking
The easiest method to detect and prevent DLL hijacking is to use third-party tools. There are some good free tools available in the market that helps in detecting a DLL hack attempt and preventing it.
One such program is DLL Hijack Auditor but it supports only 32-bit applications. You can install it on your computer and scan all your Windows applications to see what all applications are vulnerable to DLL hijack. The interface is simple and self-explanatory. The only drawback of this application is that you cannot scan 64-bit applications.
Another program, to detect DLL hijacking, DLL_HIJACK_DETECT, is available via GitHub. This program checks applications to see if any of them are vulnerable to DLL hijacking. If it is, the program informs the user. The application has two versions – x86 and x64 so that you can use each to scan both 32-bit and 64-bit applications respectively.
It should be noted that the above programs just scan the applications on the Windows platform for vulnerabilities and do not actually prevent the hijacking of DLL files.
How to prevent DLL Hijacking
The issue should be tackled by the programmers in the first place as it is not much you can do except beef up your security systems. If instead of a relative path, programmers start using an absolute path, the vulnerability will be reduced. Reading the absolute path, Windows or any other operating system will not depend on system variables for path and will go straight for the intended DLL, thereby dismissing the chances of loading the same name DLL in a higher priority path. This method too is not fail-proof because if the system is compromised, and the cybercriminals know the exact path of the DLL, they will replace the original DLL with the fake DLL. That would be overwriting the file to change the original DLL into malicious code. But again, the cybercriminal will need to know the exact absolute path mentioned in the application that calls for the DLL. The process is tough for cybercriminals and hence can be counted upon.
Coming back to what you can do, just try to scale up your security systems to better secure your Windows system. Use a good firewall. If possible, use a hardware firewall or turn on the router firewall. Use good intrusion detection systems so that you know if anyone is trying to play with your computer.
If you are into troubleshooting computers, you may also perform the following to up your security:
- Disable DLL loading from remote network shares
- Disable loading of DLL files from WebDAV
- Disable WebClient service completely or set it to manual
- Block the TCP ports 445 and 139 as they are used most for compromising computers
- Install the latest updates to the operating system and security software.
Microsoft has released a tool to block DLL load-hijacking attacks. This tool mitigates the risk of DLL hijacking attacks by preventing applications from insecurely loading code from DLL files.
Please comment below if you want to add anything to the article.