Weak File/Folder Permissions
MITRE ATT&CK™ Hijack Execution Flow - Technique T1574
Theory
It is very often in Windows environments to discover services that run with SYSTEM privileges. If you have write permissions over the folder or binary used by the service you can use it to escalate you privileges.
Practice
Service Binary Hijacking
Given sufficient permissions over a service's binary, swapping it with our own binary enables us to gain code execution as the user configured to run this service.
To identify weaknesses in service binary permissions, we can take the following steps: retrieve a complete list of all service binary files, retrieve their permissions, identify specific ones for our controlled user.
We can perform such enumeration by using one of the following methods:
CMD
PowerShell
PowerUp
winPEAS
Service DLL Hijacking
DLL hijacking can be applied in many other cases, but this section focuses solely on services. For a more comprehensive approach, please refer to this page.
In case you have write permissions over the service binary folder, we can write our DLL in and then hijack the DLL search order. Here is the default DLL search order in windows (in safe mode which is the default):
The executable directory.
The system directory.
The 16-bit system directory.
The Windows directory.
The current directory.
The directories that are listed in the PATH environment variable.
We can enumerate permissive service folders by using the following PowerShell command
If we find a writable service folder, we first want to exfiltrate its service binary to a local windows machine. On this controlled computer, download Process Monitor (procmon) to monitor for missing or hijackable DLLs.
In procomon, specify this three filters (edit the service name with yours):
We may find some CreateFile
actions with a NAME NOT FOUND
result for a dll inside of the writable service binary folder. If so we can use this DLL name for DLL Hijacking !
Resources
Last updated