Privilege Escaltion
Once we gain a foothold in the domain, our goal shifts to advancing our position further by moving laterally or vertically to obtain access to other hosts, and eventually achieve domain compromise or some other goal, depending on the aim of the assessment. To achieve this, there are several ways we can move laterally. Typically, if we take over an account with local admin rights over a host, or set of hosts, we can perform a Pass-the-Hash
attack to authenticate via the SMB protocol.
But what if we don't yet have local admin rights on any hosts in the domain?
There are several other ways we can move around a Windows domain:
Remote Desktop Protocol
(RDP
) - is a remote access/management protocol that gives us GUI access to a target hostPowerShell Remoting - also referred to as PSRemoting or Windows Remote Management (WinRM) access, is a remote access protocol that allows us to run commands or enter an interactive command-line session on a remote host using PowerShell
MSSQL Server
- an account with sysadmin privileges on an SQL Server instance can log into the instance remotely and execute queries against the database. This access can be used to run operating system commands in the context of the SQL Server service account through various methods
We can enumerate this access in various ways. The easiest, once again, is via BloodHound, as the following edges exist to show us what types of remote access privileges a given user has:
We can also enumerate these privileges using tools such as PowerView and even built-in tools.
Scenario Setup
In this section, we will move back and forth between a Windows and Linux attack host as we work through the various examples. You can spawn the hosts for this section at the end of this section and RDP into the MS01 Windows attack host. For the portion of this section that requires interaction from a Linux host (mssqlclient.py
and evil-winrm
) you can open a PowerShell console on MS01 and SSH to 172.16.5.225
with the credentials htb-student:HTB_@cademy_stdnt!
. We recommend that you try all methods shown in this section (i.e., Enter-PSSession
and PowerUpSQL
from the Windows attack host and evil-winrm
and mssqlclient.py
from the Linux attack host).
Remote Desktop
Typically, if we have control of a local admin user on a given machine, we will be able to access it via RDP. Sometimes, we will obtain a foothold with a user that does not have local admin rights anywhere, but does have the rights to RDP into one or more machines. This access could be extremely useful to us as we could use the host position to:
Launch further attacks
We may be able to escalate privileges and obtain credentials for a higher privileged user
We may be able to pillage the host for sensitive data or credentials
Using PowerView, we could use the Get-NetLocalGroupMember function to begin enumerating members of the Remote Desktop Users
group on a given host. Let's check out the Remote Desktop Users
group on the MS01
host in our target domain.
Import PowerView:
Enumerating the Remote Desktop Users Group
From the information above, we can see that all Domain Users (meaning all
users in the domain) can RDP to this host. It is common to see this on Remote Desktop Services (RDS) hosts or hosts used as jump hosts. This type of server could be heavily used, and we could potentially find sensitive data (such as credentials) that could be used to further our access, or we may find a local privilege escalation vector that could lead to local admin access and credential theft/account takeover for a user with more privileges in the domain. Typically the first thing I check after importing BloodHound data is:
Does the Domain Users group have local admin rights or execution rights (such as RDP or WinRM) over one or more hosts?
Checking the Domain Users Group's Local Admin & Execution Rights using BloodHound
If we gain control over a user through an attack such as LLMNR/NBT-NS Response Spoofing or Kerberoasting, we can search for the username in BloodHound to check what type of remote access rights they have either directly or inherited via group membership under Execution Rights
on the Node Info
tab.
Checking Remote Access Rights using BloodHound
We could also check the Analysis
tab and run the pre-built queries Find Workstations where Domain Users can RDP
or Find Servers where Domain Users can RDP
. There are other ways to enumerate this information, but BloodHound is a powerful tool that can help us narrow down these types of access rights quickly and accurately, which is hugely beneficial to us as penetration testers under time constraints for the assessment period. This can also be helpful for the blue team to periodically audit remote access rights across the environment and catch large-scale issues such as all Domain Users having unintended access to a host or audit rights for specific users/groups.
To test this access, we can either use a tool such as xfreerdp
or Remmina
from our VM or the Pwnbox or mstsc.exe
if attacking from a Windows host.
WinRM
Like RDP, we may find that either a specific user or an entire group has WinRM access to one or more hosts. This could also be low-privileged access that we could use to hunt for sensitive data or attempt to escalate privileges or may result in local admin access, which could potentially be leveraged to further our access. We can again use the PowerView function Get-NetLocalGroupMember
to the Remote Management Users
group. This group has existed since the days of Windows 8/Windows Server 2012 to enable WinRM access without granting local admin rights.
Enumerating the Remote Management Users Group
We can also utilize this custom Cypher query
in BloodHound to hunt for users with this type of access. This can be done by pasting the query into the Raw Query
box at the bottom of the screen and hitting enter.
Using the Cypher Query in BloodHound
We could also add this as a custom query to our BloodHound installation, so it's always available to us.
Adding the Cypher Query as a Custom Query in BloodHound
We can use the Enter-PSSession cmdlet using PowerShell from a Windows host.
Establishing WinRM Session from Windows
From our Linux attack host, we can use the tool evil-winrm to connect.
To use evil-winrm
we can install it using the following command:
Installing Evil-WinRM
Typing evil-winrm
will give us the help menu and all of the available commands.
Viewing Evil-WinRM's Help Menu
We can connect with just an IP address and valid credentials.
Connecting to a Target with Evil-WinRM and Valid Credentials
From here, we could dig around to plan our next move.
SQL Server Admin
More often than not, we will encounter SQL servers in the environments we face. It is common to find user and service accounts set up with sysadmin privileges on a given SQL server instance. We may obtain credentials for an account with this access via Kerberoasting (common) or others such as LLMNR/NBT-NS Response Spoofing or password spraying. Another way that you may find SQL server credentials is using the tool Snaffler to find web.config or other types of configuration files that contain SQL server connection strings.
BloodHound, once again, is a great bet for finding this type of access via the SQLAdmin
edge. We can check for SQL Admin Rights
in the Node Info
tab for a given user or use this custom Cypher query to search:
Here we see one user, damundsen
has SQLAdmin
rights over the host ACADEMY-EA-DB01
.
Using a Custom Cypher Query to Check for SQL Admin Rights in BloodHound
We can use our ACL rights to authenticate with the wley
user, change the password for the damundsen
user and then authenticate with the target using a tool such as PowerUpSQL
, which has a handy command cheat sheet. Let's assume we changed the account password to SQL1234!
using our ACL rights. We can now authenticate and run operating system commands.
First, let's hunt for SQL server instances.
Enumerating MSSQL Instances with PowerUpSQL
We could then authenticate against the remote SQL server host and run custom queries or operating system commands. It is worth experimenting with this tool, but extensive enumeration and attack tactics against MSSQL are outside this module's scope.
We can also authenticate from our Linux attack host using mssqlclient.py from the Impacket toolkit.
Displaying mssqlclient.py Options
Running mssqlclient.py Against the Target
Once connected, we could type help
to see what commands are available to us.
Viewing our Options with Access to the SQL Server
We could then choose enable_xp_cmdshell
to enable the xp_cmdshell stored procedure which allows for one to execute operating system commands via the database if the account in question has the proper access rights.
Choosing enable_xp_cmdshell
Finally, we can run commands in the format xp_cmdshell <command>
. Here we can enumerate the rights that our user has on the system and see that we have SeImpersonatePrivilege, which can be leveraged in combination with a tool such as JuicyPotato, PrintSpoofer, or RoguePotato to escalate to SYSTEM
level privileges, depending on the target host, and use this access to continue toward our goal. These methods are covered in the SeImpersonate and SeAssignPrimaryToken
of the Windows Privilege Escalation module. Try them out on this target if you would like to practice further!
Enumerating our Rights on the System using xp_cmdshell
Moving On
This section demonstrated a few possible lateral movement techniques in an Active Directory environment. We should always look for these types of rights when we gain our initial foothold and gain control of additional user accounts. Remember that enumerating and attacking is an iterative process! Every time we gain control over another user/host, we should repeat some enumeration steps to see what, if any, new rights and privileges we have obtained. Never overlook remote access rights if the user is not a local admin on the target host because we could very likely get onto a host where we find sensitive data, or we're able to escalate privileges.
Finally, whenever we find SQL credentials (in a script, a web.config file, or another type of database connection string), we should test access against any MSSQL servers in the environment. This type of access is almost guaranteed SYSTEM
access over a host. If we can run commands as the account we authenticate with, it will almost always have the dangerous SeImpersonatePrivilege
right.
Last updated