AD - enumeration - powershell
Mindmap
On Active Directory Domain Controller
enumerate user
get-aduser -Filter * -searchBase "CN=Users,DC=THMREDTEAM,DC=COM"
get-aduser -Filter * -searchBase "OU=THM,DC=THMREDTEAM,DC=COM"
get-aduser -Filter 'Name -like "*stevens"' -Server za.tryhackme.com | Format-Table Name,SamAccountName -A
$ChangeDate = New-Object DateTime(2022, 02, 28, 12, 00, 00)
Get-ADObject -Filter 'whenChanged -gt $ChangeDate' -includeDeletedObjects -Server za.tryhackme.com
powershell and LDAP
error - execution of scripts is disabled on this system
get domain[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
#-> est : thm.local
#-> ainControllers : {ADBASICS.thm.local}
#-> ldren : {}
#-> ainMode : Unknown
#-> ainModeLevel : 7
#-> ent :
#-> RoleOwner : ADBASICS.thm.local
#-> RoleOwner : ADBASICS.thm.local
#-> rastructureRoleOwner : ADBASICS.thm.local
#-> e : thm.local
$domainObj = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$PDC = ($domainObj.PdcRoleOwner).Name
$searchStr = "LDAP://"
$searchStr += $PDC + "/"
$Name = "DC=$($domainObj.Name.Replace('.',',DC='))"
$searchStr += $Name
$searchStr
$seracher = New-Object System.DirectoryServices.DirectorySearcher([ADSI]$searchStr)
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$seracher.SearchRoot = $objDomain
$seracher.filter = "samAccountType=805306368"
$items = $seracher.FindAll()
Foreach($obj in $items) {
Foreach($prop in $obj.Properties) {
$prop.name # <- print only name
}
Write-Host "-------------------------"
}
get groups
$domainObj = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$PDC = ($domainObj.PdcRoleOwner).Name
$searchStr = "LDAP://"
$searchStr += $PDC + "/"
$Name = "DC=$($domainObj.Name.Replace('.',',DC='))"
$searchStr += $Name
$searchStr
$seracher = New-Object System.DirectoryServices.DirectorySearcher([ADSI]$searchStr)
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$seracher.SearchRoot = $objDomain
$seracher.filter = "(objectClass=group)"
$items = $seracher.FindAll()
Foreach($obj in $items) {
Foreach($prop in $obj.Properties) {
$prop.name
$prop.member
}
Write-Host "-------------------------"
}
get serverprincipalname
$domainObj = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$PDC = ($domainObj.PdcRoleOwner).Name
$searchStr = "LDAP://"
$searchStr += $PDC + "/"
$Name = "DC=$($domainObj.Name.Replace('.',',DC='))"
$searchStr += $Name
$searchStr
$seracher = New-Object System.DirectoryServices.DirectorySearcher([ADSI]$searchStr)
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$seracher.SearchRoot = $objDomain
$seracher.filter = "serviceprincipalname=*http*"
$items = $seracher.FindAll()
Foreach($obj in $items) {
Foreach($prop in $obj.Properties) {
$prop
}
Write-Host "-------------------------"
}
get loggedon users
get sessions from dc