Enumeration
Hack Responsibly.
Always ensure you have explicit permission to access any computer system before using any of the techniques contained in these documents. You accept full responsibility for your actions by applying any knowledge gained here.
Without Active Directory module installed
Get Current Domain Info
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()Get Domain Trusts
([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).GetAllTrustRelationships()Get Forest Info
[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()Get Forest Trust Relationships
([System.DirectoryServices.ActiveDirectory.Forest]::GetForest((New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext('Forest', 'forest-of-interest.local')))).GetAllTrustRelationships()Enumerate Domain Users
Get User-related Environment Variables (cmd.exe)
set uList all Usernames
([adsisearcher]"(&(objectClass=User)(samaccountname=*))").FindAll().Properties.samaccountnameList Administrators
([adsisearcher]"(&(objectClass=User)(admincount=1))").FindAll().Properties.samaccountnameList all Info about specific user
([adsisearcher]"(&(objectClass=User)(samaccountname=$UserName))").FindAll().Propertiesnltest /user:"zweilos"View All Users with Description Field Set
([adsisearcher]"(&(objectClass=group)(samaccountname=*))").FindAll().Properties | % { Write-Host $_.samaccountname : $_.description }Using Active Directory PowerShell module
View all Active Directory commands
Get-Command -Module ActiveDirectoryDisplay Basic Domain Information
Get-ADDomainGet Domain SID
Get-DomainSIDEnumerate other Domains:
Get-ADDomain -Identity $DomainNameList Domain Controllers
Get-ADDomainController
Get-ADDomainController -Identity $DomainNameGet all Domain Controllers by Hostname and Operating System
Get-ADDomainController -filter * | select hostname, operatingsystemEnumerate Domain Computers:
Get-ADComputer -Filter * -Properties *
Get-ADGroup -Filter *Enumerate Domain Trust:
Get-ADTrust -Filter *
Get-ADTrust -Identity $DomainNameEnumerate Forest Trust:
Get-ADForest
Get-ADForest -Identity $ForestName
#List Domains in a Forest
(Get-ADForest).DomainsEnumerate Local AppLocker Effective Policy:
Get-AppLockerPolicy -Effective | select -ExpandProperty RuleCollectionsGet all Fine Grained Password Policies
Get-ADFineGrainedPasswordPolicy -filter *Get Domain Default Password Policy
Gets the password policy from the logged in domain
Get-ADDefaultDomainPasswordPolicyBackup Active Directory System State Remotely
This will back up the domain controllers system state data. Change DC-Name to your server name and change the Backup-Path. The backup path can be a local disk or a UNC path
Invoke-Command -ComputerName $DC_Name -scriptblock {wbadmin start systemstateback up -backupTarget:"Backup-Path" -quiet}AD User Enumeration
Get User and List All Properties (attributes)
For the variable $username use the samAccountName of the account
Get-ADUser $username -Properties *Get User and list only specific properties
Get-ADUser $username -Properties * | Select name, department, titleFind a specific string in a certain user's attribute
Get-ADUser -Filter 'Description -like "*pass*"' -Properties Description | select Name, DescriptionGet All Active Directory Users in Domain
Get-ADUser -Filter *Get All Users From a Specific OU
OU = Full distinguished path of the OU
Get-ADUser -SearchBase “OU=Domain Users,dc=test,dc=local” -Filter *Get AD Users by Name
This command will find all users that have the word bob in the name.
Get-Aduser -Filter {name -like "*bob*"}Get All Disable User Accounts
Search-ADAccount -AccountDisabled | select nameDisable User Account
Disable-ADAccount -Identity $UserNameEnable User Account
Enable-ADAccount -Identity $UserNameGet All Accounts with Password Set to Never Expire
Get-Aduser -filter * -properties Name, PasswordNeverExpires | where {$_.passwordNeverExpires -eq "true" } | Select-Object DistinguishedName,Name,EnabledFind All Locked User Accounts
Search-ADAccount -LockedOutUnlock User Account
Unlock-ADAccount –Identity $UserNameList all Disabled User Accounts
Search-ADAccount -AccountDisabledForce Password Change at Next Login
Set-ADUser -Identity $UserName -ChangePasswordAtLogon $trueMove a Single User to a New OU
You will need the distinguishedName of the user and the target OU
Move-ADObject -Identity "CN=bob,OU=Users,DC=ad,DC=test,DC=local" -TargetPath "OU=HR,OU=Users,DC=ad,DC=ad,DC=com"Move Users from one OU to another using a CSV file
Create a csv with a name field containing a list of the users SamAccountName's. Then just change the target OU path to move the users.
# Specify target OU.
$TargetOU = "OU=HR,OU=Users,DC=ad,DC=test,DC=local"
# Read user SAMAccountNames from csv file (field labeled "Name").
Import-Csv -Path $csvFile | ForEach-Object {
# Retrieve the distinguishedName of the User.
$UserDN = (Get-ADUser -Identity $_.Name).distinguishedName
# Move user to target OU.
Move-ADObject -Identity $UserDN -TargetPath $TargetOU
}AD Group Commands
Get All members of a Security group
Get-ADGroupMember -identity $GroupNameGet All Security Groups
This will list all security groups in a domain
Get-ADGroup -filter *Add User to Group
Add-ADGroupMember -Identity $GroupName -Members $user1, $user2Export Users From a Group
This will export group members to a CSV, change group-name to the group you want to export.
Get-ADGroupMember -identity $GroupName | select name | Export-csv -Path $OutCsv -NoTypeInformationGet Group by keyword
Get-AdGroup -filter * | Where-Object {$_.name -like "*$GroupName*"}Import a List of Users to a Group
$members = Import-CSV $csvFile | Select-Object -ExpandProperty samaccountname | Add-ADGroupMember -Identity $GroupName -Members $membersAD Computer Commands
List All Computers
Get-AdComputer -filter *List All Computers by Name
Get-ADComputer -filter * | select nameGet All Computers from a specific OU
Get-ADComputer -SearchBase "OU=$DistinguishedName" -Filter *Get a Count of All Computers in Domain
Get-ADComputer -filter * | measureGet all Windows 10 Computers
Get-ADComputer -filter {OperatingSystem -Like '*Windows 10*'} -property * | select name, operatingsystemGet a Count of All computers by Operating System
This will provide a count of all computers and group them by the operating system. A great command to give you a quick inventory of computers in AD.
Get-ADComputer -Filter "name -like '*'" -Properties operatingSystem | group -Property operatingSystem | Select Name,CountDelete a single Computer
Remove-ADComputer -Identity "$ComputerName"Delete a List of Computer Accounts
Add the hostnames to a text file and run the command below.
Get-Content -Path $ComputerList | Remove-ADComputerDelete Computers From an OU
Get-ADComputer -SearchBase "OU=$DistinguishedName" -Filter * | Remote-ADComputerUsing PowerView
Get Current Domain:
Get-NetDomainEnumerate other Domains:
Get-NetDomain -Domain $DomainNameGet Domain SID:
Get-DomainSIDGet Domain Policy:
Get-DomainPolicy #Will show us the policy configurations of the Domain about system access or kerberos (Get-DomainPolicy)."system access" (Get-DomainPolicy)."kerberos policy"Get Domain Controllers:
Get-NetDomainController Get-NetDomainController -Domain $DomainNameEnumerate Domain Users:
Get-NetUser Get-NetUser -SamAccountName $user Get-NetUser | select cn Get-UserProperty #Check last password change Get-UserProperty -Properties pwdlastset #Get a spesific "string" on a user's attribute Find-UserField -SearchField Description -SearchTerm "wtver" #Enumerate user logged on a machine Get-NetLoggedon -ComputerName $ComputerName #Enumerate Session Information for a machine Get-NetSession -ComputerName $ComputerName #Enumerate domain machines of the current/specified domain where specific users are logged into Find-DomainUserLocation -Domain $DomainName | Select-Object UserName, SessionFromNameEnumerate Domain Computers:
Get-NetComputer -FullData Get-DomainGroup #Enumerate Live machines Get-NetComputer -PingEnumerate Groups and Group Members:
Get-NetGroupMember -GroupName "$GroupName" -Domain $DomainName #Enumerate the members of a specified group of the domain Get-DomainGroup -Identity $GroupName | Select-Object -ExpandProperty Member #Returns all GPOs in a domain that modify local group memberships through Restricted Groups or Group Policy Preferences Get-DomainGPOLocalGroup | Select-Object GPODisplayName, GroupNameEnumerate Shares
#Enumerate Domain Shares Find-DomainShare #Enumerate Domain Shares the current user has access Find-DomainShare -CheckShareAccessEnumerate Group Policies:
Get-NetGPO # Shows active Policy on specified machine Get-NetGPO -ComputerName $ComputerName Get-NetGPOGroup #Get users that are part of a Machine's local Admin group Find-GPOComputerAdmin -ComputerName $ComputerNameEnumerate OUs:
Get-NetOU -FullData Get-NetGPO -GPOname $GPO_GUIDEnumerate ACLs:
# Returns the ACLs associated with the specified account Get-ObjectAcl -SamAccountName $AccountName -ResolveGUIDs Get-ObjectAcl -ADSprefix 'CN=Administrator, CN=Users' -Verbose #Search for interesting ACEs Invoke-ACLScanner -ResolveGUIDs #Check the ACLs associated with a specified path (e.g smb share) Get-PathAcl -Path $Share_PathEnumerate Domain Trust:
Get-NetDomainTrust Get-NetDomainTrust -Domain $DomainNameEnumerate Forest Trust:
Get-NetForestDomain Get-NetForestDomain Forest $ForestName #Domains of Forest Enumeration Get-NetForestDomain Get-NetForestDomain Forest $ForestName #Map the Trust of the Forest Get-NetForestTrust Get-NetDomainTrust -Forest $ForestNameUser Hunting:
#Finds all machines on the current domain where the current user has local admin access Find-LocalAdminAccess -Verbose #Find local admins on all machines of the domain: Invoke-EnumerateLocalAdmin -Verbose #Find computers were a Domain Admin OR a spesified user has a session Invoke-UserHunter Invoke-UserHunter -GroupName "RDPUsers" Invoke-UserHunter -Stealth #Confirming admin access: Invoke-UserHunter -CheckAccessEscalate Privileges to Domain Admin with User Hunting:
If you have local admin access on a machine
If A Domain Admin has a session on that machine
Steal their token and impersonate them!
Using BloodHound
#Using .exe ingestor
.\SharpHound.exe --CollectionMethod All --LDAPUser $UserName --LDAPPass $Password --JSONFolder $OutFile_Path
#Using powershell module ingestor
.\SharpHound.ps1
Invoke-BloodHound -CollectionMethod All -LDAPUser $UserName -LDAPPass $Password -OutputDirectory $OutFile_PathGroup Policy
Get all GPO related commands
Get-Command -Module grouppolicyGet all GPOs by status
Get-GPO -all | select DisplayName, gpostatusBackup all GPOs in the Domain
Backup-Gpo -All -Path E:GPObackupEnumeration using nltest and .Net
Get Domain Information
nltest /DCLIST:DomainName
nltest /DCNAME:DomainName
nltest /DSGETDC:DomainNameGet Current Domain Info
nltest /dsgetdc:test.local
set lView Domain Forest Info
nltest /domain_trustsView Domain Trust Information
([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).GetAllTrustRelationships()
([System.DirectoryServices.ActiveDirectory.Forest]::GetForest((New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext('Forest', 'forest-name.local')))).GetAllTrustRelationships()nltest /domain_trusts
nltest [server:<fqdn_foreign_domain>] /domain_trusts /all_trusts /v
nltest /dsgetfti:<domain>
nltest /server:<ip_dc> /domain_trusts /all_trustsView All Domain Controllers
nltest /dclist:$domainFQDN
net group "domain controllers" /domainView DC for Current Session
nltest /dsgetdc:$domainFQDNKerberos
Get domain name and DC the user authenticated to
klistGet All Logged on Sessions, Includes NTLM & Kerberos
klist sessionsView Current Kerberos Tickets
klistView Cached Krbtgt
klist tgtOther useful AD enumeration tools
LDAPDomainDump Information dumper via LDAP, Gathers the AD schema details.
adidnsdump Integrated DNS dumping by any authenticated user
ACLight Advanced Discovery of Privileged Accounts
ADRecon Detailed Active Directory Recon Tool
ADExplorer easily navigate an AD database, save snapshots of an AD database for off-line viewing.
Last updated