In Windows, every named object has a security descriptor, which contains the security settings for an object.
A security descriptor has two separate Access Control List: a System ACL (SACL) and a discretionary ACL. SACL determine which operation on an object is logged. DACL determine which user can perform a particular operation on the object.
In this case, we will more focus on the DACL, that contains Access Control Entry (ACE) which mainly describe the following information :
Most of the Windows services can be found just by researching on your Windows search bar "Services".
Creating a service in Windows can be done by using the command sc.exe
To confirm that your service has been correctly created, you can list all the services present in the system.
There are other ways to find your service like opening task manager and click on the tab "Services".
Or using WMI to query the services.
We have quickly defined the services and SDDL, how about we check the permission of a service ?
Let's take a native service that can be started or stopped.
To start a service:
The service cannot be run by a normal user, how can we give the right to the user ?
First let's check the SDDL of the service to understand more closely what permission it has.
D: indicate the DACL, followed by several ACEs and the S: indicate the SACL.
Let’s add the following SDDL to give the permission to start and stop a service (A;;WPRP;;; S-1-5-21-320533732-2754806046-4003924088-1001).
After adding the new access control entry, the user can start and stop the service.
How about we get more stealthy and attempt to hide some services. The permission "LC" will ask the Service Control Manager the current status of a service, but I've noticed that by denying this permission, the service will disappear.
Let's add the following ACE to the DACL of Xblgamesave service : (D;;LC;;;S-1-5-21-320533732-2754806046-4003924088-1001)
Once this ACE has been added, the service will be invisible for the user.
Moreover by denying the right to ask the Service Control Manager the current status of the service, the user cannot start or stop the service.
Therefore if we want that the service to not be found, or to not able to get stopped by any user, simply add those ACE in the first position / order of the ACEs : (A;;RP;;;SY)(D;;CCLCSWWPDTLOCRRC;;;WD)
Then host the payload on a python HTTP server. The payload has to be stored on the directory that you have started your python server, in my case /root/http
Start Metasploit and configure it to listen on the port 4444.
Now that we have compromised the system, let's move on the persistence. For our case, we will create a service and a schedule task.
Exit the interactive session without killing the session by typing background.
Create a service with Metasploit :
The service created on the Windows system is called swHrOyUa.
We create a scheduled task for the persistence that starts the service when any user is loging in the system.
Let's change the permission of the malicious service, replace the SDDL by D:(A;;LCRP;;;SY)(D;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD)
Let's test if this is working. First, shutdown the victim system which will lead to killing our meterpreter session.
Once it is dead, listen again on the port 4444 then start the system and log in with any user.
Boom, the service run automatically after any user log in this system and I become SYSTEM :).