Hacking Notes logo Hacking Notes

In order to obtain information about our target domain we need to enumerate it. There are several ways to enumerate the domain with some kali tools, but in this section we are going to use PowerShell and the .NET framework.

$ADClass = [System.DirectoryServices.ActiveDirectory.Domain]
$ADClass::GetCurrentDomain()

Exists multiple scripts to enumerate the domain.

Powerview on Linux

There are some alternatives based on linux systems.

First we need to obtain a TGT, to do that task we can use impacket-getTGT.

impacket-getTGT domain/user:pass -dc-ip 10.10.10.10

Use klist to get the info about the ticket.

klist example.ccache

We can save the ticket on a variable or we can specify it on each command:

Note: pywerview needs the FULL hostname in SPN to work properly.

export KRB5CCNAME=example.ccache
ython3 pywerview.py get-netcomputer -t srv-ad.contoso.com -u stormtroopers -k

KRB5CCNAME=example.ccache python3 pywerview.py get-netcomputer -t srv-ad -u stormtroopers -k

Importing the module

First of all the module needs to be imported. Normally is not detected by AV, in case of detection, AMSI will need be evaded.

Import-Module .\PowerView.ps1
. .\PowerView.ps1

Its important to import first a .dll file if RSAT is not installed on the machine.

Import-Module .\Microsoft.ActiveDirectory.Management.dll
Import-Module .\ActiveDirectory\ActiveDirectory.psd1

Current Domain

Identify current user domain

(Get-ADDomain).DNSRoot

Identify current computer domain

(Get-WmiObject Win32_ComputerSystem).Domain

Another Domain

Domain SID

(Get-ADDomain).DomainSID
Get-ADDomain | select DNSRoot,NetBIOSName,DomainSID

Domain Policy

Domain Controllers

Users & their Properties / Attributes

Note: Some sysadmins paste the password on the description field.

Note: Service accounts stores the password on the LSAS in clear text.

Search a particular string in users’s attributes

Valuable info can be found in user’s attributes such as description.

Computers in the domain

Domain Groups

Get-NetGroup *admin*

Note: It is also possible search for all groups containing a word:

Get-ADGroup -Filter 'Name -like "*admin*"' | select Name

Find memberships

Local Groups

To do that task needs administrator privs on non-dc machines.

The following command shows the members of all the local groups on a machine.

Get-NetLocalGroup -ComputerName filesrv1.corp.local -ListGroups -Recurse

Logged Users (User has a session on)

Like local groups to do that task needs administrator privs on non-dc machines.

Get actively logged users on a computer (needs local admin rights on the target)

Get-NetLoggedon -ComputerName filesrv1.corp.local

Get locally logged users on a computer (needs remote registry on the target (by default))

Get-LoggedonLocal -ComputerName filesrv1.corp.local

Get the last logged user on a computer (needs local admin rights and remote registry on the target (by default))

Get-LastLoggedOn -ComputerName filesrv1.corp.local

Find important targets

Shares

Sensitive Files

File servers

Group Policy (GPO)

Group Policy provides the ability to manage configuration and changes easily and centrally in active directory.

Users on Localgroups

We can also get users which are in a local group of a machine using GPO.

Or we can find machines where a user is member of a specific group.

Organization Unit (OU)

To read which GPO is aplied to each OU, use the gplink value extracted from Get-NetOU.

To know which computers are inside a OU:

Access Control List (ACL)

Enables control on the ability of a process to access objects and other resources in active diectory based on:

It’s a list of Access Control Entities (ACE) which corresponds to an individual permission or audits access. Determines who has permission and what can be done on an object.

Exists two types:

ACLs are vital to security architecture of Active Directory.

We can list the ACLs associated to a specified object, with a specified prefix, specified LDAP search or to specific path.

PowerView has a module named ACLScanner that finds interesting ACL such as ACL that are modified or ones which determines where and which object we can modify.

Domain Trust Mapping

We can get a list of all domain trusts for a domain.

Forest Mapping

A Forest is like a tree of domains (domain and subdomains) and the name of the forest is the name as the root domain of the tree.

We can get details about a forest:

We can get all domains in a forest:

We can get all global catalogs of a forest:

We can get the map trusts of a forest:

User Hunting

Local Admin Check

Find all machines on the current domain where the current user has local admin access.

Note: This function queries the domain controller for a list of computers Get-NetComputer and then use multi-threaded Invoke-CheckLocalAdminAccess on each machine. MAKE A LOT OF NOISE

In case Find-PSRemotingLocalAdminAccess.ps1 is blocked you can use:

Import-Module .\Find-WMILocalAdminAccess.ps1
Find-WMILocalAdminAccess -ComputerName machine01.corp.local
Find-WMILocalAdminAccess -ComputerFile .\computers.txt -Verbose

NOTE: WMI needs ADMIN PRIV to work, so if we get an error is that the user has not enough privileges.

Get Local Admins (Local Admin Priv. needed)

We can find local admins on all machines of the domain but we need administrator privileges on non-dc machines.

Sessions opened on a machine

Returns session information for a computer where CName is the source IP.

We can find computers where a domain admin or another specified user or group has an active session:

We can also confirm the admin access with:

RedTeam Note: To prevent of beeing detected by the Microsoft ATA (Advanced Thread Analytics) that analyzes the traffic of the DC, use a list of computers and remove the DC from it.

Get-NetComputer Invoke-UserHunter -ComputerFile hosts.txt

BlueTeam Note: Netcease.ps1 is a script which change permission on the NetSessionEnum by removing permission to Authenticated Users group. This Script should be executed on the DC. https://github.com/p0w3rsh3ll/NetCease.

To revert the effect: .\Netcease.ps1 -Revert

After any modfification we need to restart the server: Restart-Service -Name Server -Force

The binary net.exe uses SAMR protocol, exists another script which hardens a server. https://vulners.com/n0where/N0WHERE:139229

SQLServers

We can provide a list of all SQL servers which have a SPN register on the domain controller.

Note: This not mean that is a SQL Server running or listening, that means htat there are a MSSQL on a SPN.

BloodHound

Provides GUI for AD entities and relationships for the data collected by its ingestors (SharpHound.ps1).

https://github.com/BloodHoundAD/BloodHound

First we need to run ingestors on a machine in order to collect data.

. .\SharpHound.ps1
Invoke-BloodHound -CollectionMethod All -Verbose

SharpHound has a number of different collection methods (all documented on the repository):

Sometimes BloodHound miss to check the sessions so we can execute it manually.

Invoke-BloodHound -CollectionMethod LoggedOn -Verbose

Note: Remember that we can append the invoke command at the end of the file an executed it out of memory with iex (iwr ...)

RedTeam Note: We can avoid detections like ATA with:

Invoke-BloodHound -CollectionMethod All -ExcludeDC

After execution download the .zip file and drop to BloodHound in order to import it.

BloodHound

OPSEC Alert: Running collections method such as LocalAdmin, RDP, DCOM, PSRemote and LoggedOn will allow SharpHound to enumerate every single computer in the domain.

Collecting this information is useful to BloodHound and without it you may see fewer paths.

To use on LDAP queries we can use DcOnly collection method.

Invoke-BloodHound -CollectionMethod DcOnly

Raw queries

Executing raw queries is useful for finding nodes that have particular properties or to help specific attack paths.

MATCH (u:User {hasspn:true}) RETURN u
MATCH (u:User {dontreqpreauth:true}) RETURN u
MATCH (c:Computer), (t:Computer), p=((c)-[:AllowedToDelegate]->(t)) RETURN p
MATCH (c:Computer {unconstraineddelegation:true}) RETURN c
MATCH (c:Computer), (t:Computer), p=((c)-[:AllowedToDelegate]->(t)) RETURN p
MATCH (u:User), (t:Computer), p=((u)-[:AllowedToDelegate]->(t)) RETURN p
MATCH (gr:Group), (gp:GPO), p=((gr)-[:GenericWrite]->(gp)) RETURN p
MATCH (g1:Group {name:"RDP USERS@CORP.LOCAL"}), (g2:Group), p=((g1)-[:GenericAll]->(g2)) RETURN p
MATCH p=(u:User)-[:SQLAdmin]->(c:Computer) RETURN p