10. Credentialed Active Directory Enumeration

Credentialed Active Directory Enumeration from Linux

 We have various options available, but the most important thing to remember is that most of these tools will not work without valid domain user credentials at any permission level. So at a minimum, we will have to have acquired a user's cleartext password, NTLM password hash, or SYSTEM access on a domain-joined host.

Crackmapexec /nxc

CME offers a help menu for each protocol (i.e., crackmapexec winrm -h, etc.). Be sure to review the entire help menu and all possible options.

With --users flag you can enumerate users with valid creds. Same with --groups

Using --loggedon-users on an interesting host we can figure out some more information about logged in users and, depending on the kind of host, (i.e. jump host) reveals information about the host, if it's a jump host we can potentially steal creds or impersonate them.

It's also possible to view shares with --shares. Self-explanatory.

The module spider_plus will dig through each readable share on the host and list all readable files. Let's give it a try.

 sudo crackmapexec smb 172.16.5.5 -u forend -p Klmcargo2 -M spider_plus --share 'Department Shares'

When completed, CME writes the results to a JSON file located at /tmp/cme_spider_plus/<ip of host>


SMBMap Great for enumerating SMB shares from a linux attack host.

smbmap -u forend -p Klmcargo2 -d INLANEFREIGHT.LOCAL -H 172.16.5.5

Say we have read access of a Department Shares directory. Let's do a recursive listing of directores in this share.

smbmap -u forend -p Klmcargo2 -d INLANEFREIGHT.LOCAL -H 172.16.5.5 -R 'Department Shares' --dir-only

RPCClient

rpcclient -U "" -N 172.16.5.5

Looking at users with rpcclient you will see rid fieeld. Example is below on how that all fits in

However, there are accounts that will have the same RID regardless of what host you are on. Accounts like the built-in adminstrator for a domain will have a RID [administrator] rid:[0x1f4]

Rpcclient user enum with RID

rpcclient $> queryuser 0x457

This implies we know the RIDof the user we want to target. Otherwise we can issue:

enumdomusers

Impacket toolkit for enumeration purposes

Earlier in the poisoning section, we grabbed a hash for the user wley with Responder and cracked it to obtain the password transporter@4

We will see in the next section that this user is a local admin on the ACADEMY-EA-FILE host

PSexec.py

psexec.py inlanefreight.local/wley:'transporter@4'@172.16.5.125  

wmiexec.py

wmiexec.py inlanefreight.local/wley:'transporter@4'@172.16.5.5  

windapsearch.py

python3 windapsearch.py --dc-ip 172.16.5.5 -u forend@inlanefreight.local -p Klmcargo2 --da

python3 windapsearch.py --dc-ip 172.16.5.5 -u forend@inlanefreight.local -p Klmcargo2 -PU
python3 windapsearch.py -u 'forend@inlanefreight.local' -p 'Klmcargo2' -d 'inlanefreight.local' --dc-ip 172.16.5.5 --attrs memberOf --custom '(sAMAccountName=SAPService)'

Bloodhound Lots of review of stuff you already know. Consists of the bloodhound.py ingestor and the sharphound ingestor (c#) Uses a graph database + graph theory to determine relationships within an AD environment. Initially released with only a powershell collector and had to be run from windows. Python port was released by the community for uses where we have valid domain credentials but do not have rights to access a domain-joined windows host or do not have a windows attack host to run the sharphound collector from.

sudo bloodhound-python -u 'forend' -p 'Klmcargo2' -ns 172.16.5.5 -d inlanefreight.local -c all 

Credentialed Active Directory Enumeration from Windows

ActiveDirectory Powershell Module https://docs.microsoft.com/en-us/powershell/module/activedirectory/?view=windowsserver2022-ps

Basic domain information: https://docs.microsoft.com/en-us/powershell/module/activedirectory/get-addomain?view=windowsserver2022-ps

Get-ADDomain

Prints domain SID, domain functional level, child domains and more.

Next, Get-ADUser

Get-ADUser -Filter {ServicePrincipalName -ne "$null"} -Properties ServicePrincipalName

We're filtering for accounts with the ServicePrincipalName property populated (is not null). This will return a listing of accounts that may be susceptible to Kerberoasting

Verify domain trust relationships with the Get-ADTrust cmdlet. This will print out any trust relationships the domain has. We can determine if they are trusts within our forest or with domains in other forests, the type of trust, direction of the trust, and the name of domain the relationship is with.

 Get-ADTrust -Filter *

Next, Get-ADGroup

Get-ADGroup -Filter * | select name
[...] this will only return group names. We can further inspect specific groups like this: 
Get-ADGroup -Identity "Backup Operators"

Now that we know more about a group we can get a member listing with Get-ADGroupMember

Get-ADGroupMember -Identity "Backup Operators"

This is all very tedious but its important to know how to do it manually, and gain a greater appreciation of tools like Bloodhound. Utilizing the ActiveDirectory module on a host can be a stealthier way of performing actions than dropping a tool onto a host or loading it into memory and attempting to use it.


PowerView

Much like bloodhound, way to identify where users are logged in on a network and enumerate domain information. Able to perform kerberoasting Requires a bit more work to determine misconfigurations. The table below describes some of the most useful functions PowerView offers.

Command Description
Export-PowerViewCSV Append results to a CSV file
ConvertTo-SID Convert a User or group name to its SID value
Get-DomainSPNTicket Requests the Kerberos ticket for a specified Service Principal Name (SPN) account
Domain/LDAP Functions:
Get-Domain Will return the AD object for the current (or specified) domain
Get-DomainController Return a list of the Domain Controllers for the specified domain
Get-DomainUser Will return all users or specific user objects in AD
Get-DomainComputer Will return all computers or specific computer objects in AD
Get-DomainGroup Will return all groups or specific group objects in AD
Get-DomainOU Search for all or specific OU objects in AD
Find-InterestingDomainAcl Finds object ACLs in the domain with modification rights set to non-built in objects
Get-DomainGroupMember Will return the members of a specific domain group
Get-DomainFileServer Returns a list of servers likely functioning as file servers
Get-DomainDFSShare Returns a list of all distributed file systems for the current (or specified) domain
GPO Functions:
Get-DomainGPO Will return all GPOs or specific GPO objects in AD
Get-DomainPolicy Returns the default domain policy or the domain controller policy for the current domain
Computer Enumeration Functions:
Get-NetLocalGroup Enumerates local groups on the local or a remote machine
Get-NetLocalGroupMember Enumerates members of a specific local group
Get-NetShare Returns open shares on the local (or a remote) machine
Get-NetSession Will return session information for the local (or a remote) machine
Test-AdminAccess Tests if the current user has administrative access to the local (or a remote) machine
Threaded 'Meta'-Functions:
Find-DomainUserLocation Finds machines where specific users are logged in
Find-DomainShare Finds reachable shares on domain machines
Find-InterestingDomainShareFile Searches for files matching specific criteria on readable shares in the domain
Find-LocalAdminAccess Find machines on the local domain where the current user has local administrator access
Domain Trust Functions:
Get-DomainTrust Returns domain trusts for the current domain or a specified domain
Get-ForestTrust Returns all forest trusts for the current forest or a specified forest
Get-DomainForeignUser Enumerates users who are in groups outside of the user's domain
Get-DomainForeignGroupMember Enumerates groups with users outside of the group's domain and returns each foreign member
Get-DomainTrustMapping Will enumerate all trusts for the current domain and any others seen.
Table is not all-encompassing. https://academy.hackthebox.com/course/preview/active-directory-powerview

Example Get-DomainUser usage:

Get-DomainUser -Identity mmorgan -Domain inlanefreight.local | Select-Object -Property name,samaccountname,description,memberof,whencreated,pwdlastset,lastlogontimestamp,accountexpires,admincount,userprincipalname,serviceprincipalname,useraccountcontrol

Example Get-DomainGroupMember usage:

Get-DomainGroupMember -Identity "Domain Admins" -Recurse

-Recurse tells Powerview that if it finds any groups that are part of the target group, list out members of that group too. For example, a group named Secadmins is part of Domain Admins group through nested group membership.

It's also possible to enumerate domain trust mappings.

Get-DomainTrustMapping

SourceName      : INLANEFREIGHT.LOCAL
TargetName      : LOGISTICS.INLANEFREIGHT.LOCAL
TrustType       : WINDOWS_ACTIVE_DIRECTORY
TrustAttributes : WITHIN_FOREST
TrustDirection  : Bidirectional
WhenCreated     : 11/1/2021 6:20:22 PM
WhenChanged     : 2/26/2022 11:55:55 PM

SourceName      : INLANEFREIGHT.LOCAL
TargetName      : FREIGHTLOGISTICS.LOCAL
TrustType       : WINDOWS_ACTIVE_DIRECTORY
TrustAttributes : FOREST_TRANSITIVE
TrustDirection  : Bidirectional
WhenCreated     : 11/1/2021 8:07:09 PM
WhenChanged     : 2/27/2022 12:02:39 AM

SourceName      : LOGISTICS.INLANEFREIGHT.LOCAL
TargetName      : INLANEFREIGHT.LOCAL
TrustType       : WINDOWS_ACTIVE_DIRECTORY
TrustAttributes : WITHIN_FOREST
TrustDirection  : Bidirectional
WhenCreated     : 11/1/2021 6:20:22 PM
WhenChanged     : 2/26/2022 11:55:55 PM 

Test-AdminAccess function can be used for testing local admin access to either the current machine, or a remote one.

Test-AdminAccess -ComputerName ACADEMY-EA-MS01

We can perform the same function for each host to see where we may have admin access. (we can see later how bloodhound performs this check)

Checking for users with the SPN attribute set, which indicates the user may be kerberoastable:

Get-DomainUser -SPN -Properties samaccountname,ServicePrincipalName

Powerview is deprecated portion of powersploit offensive powershell toolkit. The tool has now been receiving updates by BC-Security as apart of the Empire-4 framework.


SharpView

Another tool worth mentioning is the .NET port of powerview, sharpview. Many functions supported by powerview can be used by sharpview.

.\SharpView.exe Get-DomainUser -Help
Experiment with SharpView on the MS01 host and recreate as many PowerView examples as possible. Though evasion is not in scope for this module, SharpView can be useful when a client has hardened against PowerShell usage or we need to avoid using PowerShell.

Shares

SNAFFLER is a tool that can help us acquire creds or other sensitive data in an AD environment.

Snaffler.exe -s -d inlanefreight.local -o snaffler.log -v data

hunts for passwords, ssh keys, conf files, or other data. snaffler is color-coded to check things out


Bloodhound

We need to get the ingestor onto the system, or use the python ingestor from the attack host. [[2. Windows File Transfer]] it's worth experimenting with transferring the tool to the attack host from Pwnbox or our own VM using methods such as a Python HTTP server, smbserver.py from Impacket, etc.

.\SharpHound.exe -c All --zipfilename ILFREIGHT

Exfiltrate the dataset to our own vm and ingest it with the bloodhound gui.

We will often see users with local admin rights on their host (perhaps temporarily to install a piece of software, and the rights were never removed), or they occupy a high enough role in the organization to demand these rights (whether they require them or not). Other times we'll see excessive local admin rights handed out across the organization, such as multiple groups in the IT department with local admin over groups of servers or even the entire Domain Users group with local admin over one or more hosts. This can benefit us if we take over a user account with these rights over one or more machines. We can run the query `Find Computers where Domain Users are Local Admin` to quickly see if there are any hosts where all users have local admin rights. If this is the case, then any account we control can typically be used to access the host(s) in question, and we may be able to retrieve credentials from memory or find other sensitive data.

Custom cypher queries for use with Bloodhound. https://hausec.com/2019/09/09/bloodhound-cypher-cheatsheet/

KEEP IN MIND:

We have a great picture of the domain's layout, strengths, and weaknesses. We have credentials for several users and have enumerated a wealth of information such as users, groups, computers, GPOs, ACLs, local admin rights, access rights (RDP, WinRM, etc.), accounts configured with Service Principal Names (SPNs), and more. We have detailed notes and a wealth of output and experimented with many different tools to practice enumerating AD with and without credentials from Linux and Windows attack hosts. What happens if we are restricted with the shell we have or do not have the ability to import tools? Our client may ask us to perform all work from a managed host inside their network without internet access and no way to load our tools. We could land on a host as `SYSTEM` after a successful attack, but be in a position where it is very difficult or not possible to load tools. What do we do then?