Service Binary Hijacking
Each Windows service has an associated binary file that is executed on startup. If these binary files aren't properly secured, a user can replace it with malicious code.
For example, a user installs an application and makes it a Windows service but accidentally allows Read Write (RW) permissions for all users. We can replace this application with a malicious binary, and restart the service, or restart the system system and the malicious binary will execute.
Enumerating Services
To get a list of installed Windows services we can choose a variety of different tools. (Get-Service, Get-Ciminstance, GUI services.msc).
Get-Ciminstance
NOTE: Get-CimInstance and Get-Service will return "Permission denied" if using WinRM. A RDP session will fix this on a non-administrative user.
What we're looking for
We're looking for services that are installed in locations other than C:\Windows\System32. These applications are user installed. For example**: C:\xampp\.**
Enumerating Permissions
Once we've enumerated the installed service and found one of interest, we can view the permissions. We can use tools like: icacls Windows utility or the PowerShell Cmdlet Get-ACL
F
Full access
M
Modify access
RX
Read and execute access
R
Read-only access
W
Write-only access
icacls - Check Permissions of service
Here we see the "Users" group has Full access to modify the binary.
Create Malicious Binary
This can be a reverse shell, or a simpler payload. For example: creating a new user.
Transfer Malicious Binary - iwr
Our malicious binary creates a new user and adds it to Adminstrators group
Move Malicious Binary to Service - Move
Restart Service
If we have permissions on the service we can restart the service with Restart-Service
, otherwise see below.
Restart
We'll need to restart the computer since most services are protected by Admistrators.
We're able to restart the system.
Shutdown Computer:
Verify Exploit
Last updated