6 - Windows Services
Topics
Introduction to the Windows Shells
Windows Permissions
Reverse Shells in Windows
SeImpersonatePrivilege Exploitation
On Cross Compilation
Windows Services
Weak Service Permissions
Unquoted Service Path
DLL Hijacking
Always Install Elevated
Files with Sensitive Data
Windows Hashes
Stored Credentials and the Windows Vault
Scheduled Task
Critical Registry Paths
Useful Tools
AMSI Bypass
Windows Services
Windows Services are specialized processes designed to operate in the background without user interaction (can be comparable to 'deamon' in linux systems). These services often start automatically when the system boots and continue running even after a user logs off.
Key Features of Windows Services
Run independently of the logged-in user.
Managed via the Services Control Manager (SCM) panel.
Operate in various contexts:
Local Services
Network Services
System Services
Third-Party Application Services
Security and Attack Surface
Windows Services present a substantial attack surface. Improper configurations or vulnerabilities in services can be exploited to gain elevated privileges or execute malicious code.
Managing Services
Below are useful commands to manage Windows Services effectively:
Listing and Viewing Services
List All Services:
Display Specific Properties:
Get Binary Paths for Running Services:
Service Operations
Start a Service:
Stop a Service:
Check Service Configuration:
Modifying Services
Change the Binary Path of a Service:
Check Service Permissions:
Update Service Permissions:
Advanced Operations
Convert SDDL to Readable Format:
Get Executable Path for All Processes:
Adding a New Service
To add a new service, you must provide an executable file (.exe
) that implements the Windows Service API.
Creating a Service Using sc.exe
Create the Service:
Verify the Configuration:
Start the Service:
Stop the Service:
Delete the Service:
Compiling a Custom Service
To create a custom Windows Service, write the code in a language like C and compile it using mingw-w64
.
Example Compilation Command:
Once compiled, follow the steps above to register, start, and manage the service.
Using NSSM (Non-Sucking Service Manager)
For simplicity, you can use NSSM to run any arbitrary .bat
or .exe
file as a service.
Download NSSM: From NSSM's Official Website.
Install the Service:
Other Resources
Windows local privilege escalation: https://xorond.com/posts/2021/04/wind...
ConvertFrom-SddlString: https://learn.microsoft.com/en-us/pow...
Security Descriptor Definition Language (SDDL): https://learn.microsoft.com/en-us/win...
Create Windows service from executable: https://stackoverflow.com/questions/3...
The Non-Sucking Service Manager: https://nssm.cc/
Very basic Windows Service template in C: https://gist.github.com/mmmunk/0b0adb...
Cygwin and MinGW Options: https://gcc.gnu.org/onlinedocs/gcc/Cy...
Working with SDDL: https://www.advancedinstaller.com/for...
Disclaimer
❗ Never use tools and techniques on real IP addresses, hosts or networks without proper authorization!❗
Last updated