Search

Active Directory: Pentesting

Active Directory: Pentesting

Operation

Example VPN connection to an AD environment + LDAP connection to the DC:

image
image

Active Directory Security Resources

Run also PingCastle (GOOD):

Red vs Blue Modern Active Directory Attacks, Detection, and Protection.pdf1430.1KB

Labs

AWS + BadBlood
Cloudformation templates (Checar)

Resources

Tools

AD Documentation

AD Enumeration PS Cheatsheet

Tools, Scripts

My Script for generating an inventory of machine objects in AD

Check out:

AADInternals is a PowerShell module containing tools for administering and hacking Azure AD and Office 365. It is listed in MITRE ATT&CK with id S0677

Asset inventory AD + Powershell

AD Vuln Scanning (No la he checado)

Enumeration, Tools & Commands

📌
To include: Scan SYSVOL for Group Policy Preference passwords

GPO Enumeration:

# THIS SCRIPT REQUIRES GPO Management module (Installation below)

$AllGPOs = Get-GPO -All

foreach ($GPO in $AllGPOs) {
$GPOGUID = $GPO.Id
$ReportPath = "C:\PATH\GPO-REPORTS\" + $GPO.DisplayName + ".html"
Get-GPOReport -Guid $GPOGUID -ReportType html -Path $ReportPath
}

AD RSAT PS Module

MODULE: Microsoft Management Console (MMC) + RSAT - Remote Server Administration Tools

Installation:

  1. Press Start
  2. Search "Apps & Features" and press enter
  3. Click Manage Optional Features
  4. Click Add a feature
  5. Search for "RSAT"
  6. Select "RSAT: Active Directory Domain Services and Lightweight Directory Tools" and click Install

RUNAS(.exe) (Command Injection)

Having credentials, and using a non-joined computer in the same network, we can “impersonate” a legitimate user, opening cmd/ps. This can assist in evading detection (AV), since we can deactivate AMSI and/or Antimalware to execute any task.

# Run command prompt as as administrator and execute:
runas.exe /netonly /user:<domain.com>\<username> cmd.exe

Install RSAT && MMC for AD Activities

💡
This provides only visualization using the UI via RDP. It is not adequate for assessing large environments since it is extremely manual.
# IMPORTANT: To list the installed RSAT Capabilities:
Get-WindowsCapability -Name RSAT* -Online | Select-Object -Property DisplayName, State
  1. INSTALL RSAT:

Press Start → Search "Apps & Features" → Click Manage Optional Features → Click Add a feature → Search for "RSAT" → Select "RSAT: Active Directory Domain Services and Lightweight Directory Tools" → click Install

  1. Install GPO Management in Windows 10:
DISM.exe /Online /add-capability /CapabilityName:Rsat.GroupPolicy.Management.Tools~~~~0.0.1.0
  1. START MMC and attach AD RSAT Snap-In:

If the computer is joined to the domain:

Start → Run → Type “mmc” → In MMC, Click File -> Add/Remove Snap-in → Select and Add all three Active Directory Snap-ins → Click through any errors and warnings → Right-click on Active Directory Domains and Trusts and select Change Forest → Enter tk.domain.com as the Root domain and Click OK

Right-click on Active Directory Sites and Services and select Change Forest → Enter tk.domain.com as the Root domain and Click OK

Right-click on Active Directory Users and Computers and select Change Domain → Enter tk.domain.com as the Domain and Click OK

Right-click on Active Directory Users and Computers in the left-hand pane → Click on View -> Advanced Features

If it is not joined:

Use runas.exe to authenticate → In the cmd prompt type mmc

Navigating the MMC console:

image
image

CMD.exe && Powershell Commands

CMD.exe ENUMERATION

# VERIFICAR autenticación al dominio:
net view \\contoso\

net user # Local users

# hello
net user /domain # Domain users
net group /domain # Domain groups

net group "Domain Admins" /domain # Users of group Domain Admins
net user will.payne /domain # Domain user info

net account # Password policy locally (Account Lockout, etc.)
net account /domain # Password policy for Domain
POWERSHELL.exe ENUMERATION

# -Server seems to be optional unless the machine is not AD-Joined
Get-AdUser alan.watts -Server ad.domain.com -Properties * | format-table Name,Title -A
Get-ADUser -Identity alan.watts -Server ad.domain.com -Properties *

# Format-table & Filtering results (Like Grep with wildcards)
Get-ADUser -Filter 'Name -like "*stevens"' -Server ad.domain.com | Format-Table Name,SamAccountName -A

Get-ADGroup -Identity "Admins" 
Get-AdGroupMember -Identity Administrators

# get "clark"'s Group membership (List only group names Clark is member of)
(Get-ADPrincipalGroupMembership -Identity "clark").name

# List all groups by name & Group Category
Get-ADGroup -Filter '*' | Format-table Name,GroupCategory 

Get-ADObject -Filter 'badPwdCount -gt 0' -Server ad.domain.com

PS C:\> $ChangeDate = New-Object DateTime(2022, 02, 28, 12, 00, 00)
PS C:\> Get-ADObject -Filter 'whenChanged -gt $ChangeDate' -includeDeletedObjects -Server ad.domain.com

DEFENSIVE & HARDENING, BEST PRACTICES, ETC

Lifecycle: Harden, Audit/Assess, Harden, SIEM

SIEM + AD logs

Pentesting & Security Assessments

Active-Directory-Penetration-Manual.pdf522.8KB

“Modern Active Directory Attacks, Detection, and Protection Whitepaper” (Very Good)

us-15-Metcalf-Red-Vs-Blue-Modern-Active-Directory-Attacks-Detection-And-Protection-wp.pdf1430.1KB

Credit: https://github.com/Orange-Cyberdefense

image

Tools

adPEAS

Use ldapdomaindump.py + pretty . pretty.py loads already generated results with ldapdomaindump & display them at stdout:

(For this scenario I used “Badblood” for populating a dummy AD environment)

image

Check Pingcastle:

Example Reports

Example assessment (Edu)
Assessment - Very detailed

Guides, reads,

Recon

Having:

  • An IP with open 3389, grab the screenshot of RDP session (If it’s not using NTLM) with
# If -u is not provided, the current user (Kali, Root, Parrot, My_Name) will be used to authenticate. With an empty -u we can see all the users that have logged in (ADministrator, etc.).
rdesktop -u '' <IP>

About Bloodhound, Sharphound, Bluehound, Plumhound:

Microsoft Active Directory HoundsquadMicrosoft Active Directory Houndsquad

Kerberoasting

Find Service Accounts with Bloodhound, Plumhound, get-spn.py, simply enumerating with PS, etc. that have the SPN (Service Principal Name) enabled. Examples:

Plumhound Output with SPN-enabled Service Accounts
Plumhound Output with SPN-enabled Service Accounts
get-spn.py
get-spn.py
# 1.- Request Kerberos ticket auth:
add-type -assemblyName system.identitymodel
new-object system.identityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList "<SPN of Target Service Account>"

# 2.- Mimikatz For offloading Ticket + Hash

# 3.- Offline Cracking Krbtgt hash
image
Kerberoasting (Asking for TGT to SPN-enabled service accounts) + Mimikatz (For offloading the ticket) + Offline Crack