Red Team Active Directory Enumeration Techniques
While there are several well known and older techniques for performing recognizance in an active directory, this article will focus on newer techniques that modern Red Teams utilize. These techniques are aimed at being stealthy by leveraging native Windows/Acitve Directory functionalities and components.
Instead of focusing on zero-day exploits that may crash a box or cause loud noise on a network, we will focus on identifying misconfigurations or exploiting trust relationships to eventually gain domain administrator.
We will begin with User Hunting. The two tools we will use for this enumeration include:
PowerView
AD PowerShell Module - which should be installed on a compromised host with an elevated shell.
We can begin enumeration by performing DNS lookups using LDAP. With this method we could ask for a list of specific computers or all the DCs and the associated IP addresses through just an LDAP call.
To identify machines inside the domain:
Code
>> get-adcomputer -filter * -Properties ipv4address | where {$_.IPV4address} | select name, ipv4addressDo a reverse lookup via LDAP:
Code
>> get-adcomputer -filter {ipv4address -eq 'IP'} -Properties Lastlogondate,passwordlastset,ipv4addressNext we will find enterprise services using SPN scanning. SPN scanning uses LDAP queries which use and look for Service Principal Names. This lets us know which services are running that support Kerberos authentication, no need for port scanning!
Some SPN types include MSSQLSvc, TERMSERV, WSMan, and exchangeMDB. This allows us to find all the SQL servers easily and the format has the SPN type, server name, and SQL often has a port number or an instance at the end.
SPN Directory List
A great automated tool for enumeration using SPN scanning can be found here:
Find-PSServiceAccounts
For manual testing we can use the following PowerShell command:
Code
>> Get-ADComputer -filter {ServicePrincipalName -Like "*SPN*" } -Properties OperatingSystem,OperatingSystemVersion,OperatingSystemServicePack, PasswordLastSet, LastLogonDate, ServicePrincipalName, TrustedForDelegation, TrustedtoAuthForDelegationNext we will find all the group policies in the organization that authenticated users have read access, which is all of them by default. What we are looking for in the group policies include:
+ PowerShell logging policy
+ Full auditing policy
+ Configurations like "prevent local account at logon", "add server admin to local administrator group",
+ EMET config,
+ AppLocker config
+ And more...
To discover all the group policies in the domain we would use the following PowerView command.
Code
>> Get-NetGPO | select displayname,name,whenchangedNow onto the User Hunting! We want to be able to identify users, where they have privilages etc and we want to be able to do it as an unprivileged user.
PowerView leverages a couple of native API calls to perform this task. One of the API calls commonly used is Add-Type but we will avoid it because it is not fileless. To be stealthy we must avoid writing files onto hosts as much as possible. Instead we will utilize straight reflection for API interaction through PowerShell, see https://github.com/mattifestation/PSReflect for more information.
An example of using PowerView to find Domain Admins:
Code
>> Get-NetGroupMember 'Domain Admins' -RecurseA more advance method of performing User Hunting with PowerView is to use:
Code
>> Invoke-UserHunter -Stealth -ShowAllThis will enumerate all the distributed file systems and DCs and pulls all user objects, script path(s), home directories etc. It will pull certain type of fields that tend to map where file server are and a user AD schema. The stealth factor is it will target computers that are heavily trafficked so our queries will not be unusual. It will then perform a Get-NetSession against those systems. The sessions of those systems can give us about 70% mapping of the network, due to their heavy traffic.
The primary difference between using the -Stealth feature and not using it is the amount of systems we are sending queries to. This will greatly reduce our overall network fingerprint.
Last, we will look at how to query a single domain controller's Global Catalog to get all the users of an AD forest. We don't even need Administrator privileges.
I recommend the following powershell script to perform the query:
Retrieve-All-Users-from-AD
After running the above script we should see AD user information including host name, IP location, domain, forest, roles and more.
The techniques above will assist a penetration tester who has compromised a Windows computer on a domain. Once we have compromised the host we can search for permissions of the current users of the host we are on, map to other hosts with our privleges, search for computers that a higher privilaged user is on and how to eventually access that computer and gain domain admin credentials. I provided a summary of the different methods but more research will be needed and practice required, to really understand the process.


