Active Directory / ARTICLE

AD manual Enumeration

بسم الله والصلاة والسلام على رسول الله 
اللهم علمنا ما ينفعنا وانفعنا بما علمتنا وقنا عذاب النار

Enumeration with net.exe

enumerate domain users

net user /domain 

Now you can start enumerating users one by one.

net user "<user>" /domain 

We found here that victim1 is a member of the group_nesting group.

Any user account that has not been logged into for a long time will have its last login date shown as 1/1/1601 according to Microsoft.In many cases, such accounts may be used as honeypots so that attackers discover them during enumeration.

We found that the MySQL password was written in the comment because the admin forgot it there.

enumerate domain groups

net group /domain 

enumerate “group_nesting” group

/net group "group_nesting" /domain 

enumerate “Domain Admins” group

/net group "Domain Admins" /domain 

members of Domain Admins group

collected info

domain : DC1.hunters404.com

users : 
administrator 
Guest 
hacker
IIS_Service
krbtgt
mysql => password : Passw0rd
victim1 => member of group_nesting 
victim2
victim3
victim4

Domain Admin :
victim4 - victim2 - IIS_Service - Administrator


Enumeration Using LDAP

DirectorySearcher & DirectoryEntry classes

DirectorySearcher is a class in .NET that allows you to search for specific objects or information. However, it requires a starting point, which is represented by the LDAP path “DirectoryEntry”

The general syntax for an AD LDAP path is :

LDAP://HostName[:PortNumber][/DistinguishedName]
ex : LDAP://$PDC/$DN
# PDC => primary DC

get a DistinguishedName from AD

get a DistinguishedName for DC

([adsi]"").DistinguishedName 

Active Directory Service Interfaces (ADSI) is a set of COM interfaces used to access the features of directory services from different network providers

https://learn.microsoft.com/en-us/windows/win32/adsi/active-directory-service-interfaces-adsi

Get a PDC (primary Domain Controller)

[system.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()

select pdcRoleOwner property

[system.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().pdcRoleOwner.name

more info

final command

LDAP://[system.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().pdcRoleOwner.name/([adsi]"").DistinguishedName 

or

$pdc = [system.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().pdcRoleOwner.name

$DN = ([adsi]"").DistinguishedName 

$LDAP = "LDAP://$pdc/$DN"
$LDAP

After that, I take the path that was returned and pass it to DirectoryEntry, because we will then pass it to DirectorySearcher.

$DirEnt = New-Object System.DirectoryServices.DirectoryEntry("$LDAP")

pass DirectoryEntry To DirectorySearch

$DirSea = New-Object System.DirectoryServices.DirectorySearcher($DirEnt)

extract all AD Objects

$DirSea.FINDALL()

organize it

$DirSea = New-Object System.DirectoryServices.DirectorySearcher($DirEnt,"samAccountType=<num>")

samAccountType

SAM_DOMAIN_OBJECT 0x0
SAM_GROUP_OBJECT 0x10000000
SAM_NON_SECURITY_GROUP_OBJECT 0x10000001
SAM_ALIAS_OBJECT 0x20000000
SAM_NON_SECURITY_ALIAS_OBJECT 0x20000001
SAM_USER_OBJECT 0x30000000
SAM_NORMAL_USER_ACCOUNT 0x30000000
SAM_MACHINE_ACCOUNT 0x30000001
SAM_TRUST_ACCOUNT 0x30000002
SAM_APP_BASIC_GROUP 0x40000000
SAM_APP_QUERY_GROUP 0x40000001
SAM_ACCOUNT_TYPE_MAX 0x7fffffff

https://learn.microsoft.com/en-us/windows/win32/adschema/a-samaccounttype

print all SAM_USER_OBJECT , convert 0x30000000 to decimal

extract cn only

$DirSea.FINDALL().cn

memberof

$DirSea.FINDALL().memberof

find all groups name

$DirSea = New-Object System.DirectoryServices.DirectorySearcher($DirEnt,"samAccountType=268435456")

machines name

$DirSea = New-Object System.DirectoryServices.DirectorySearcher($DirEnt,"samAccountType=805306369")
$DirSea.FINDALL().cn

list OS Versio


resources

https://www.hackingarticles.in/active-directory-enumeration-net-rpc/

https://blog.smallsec.ca/windows-network-enumeration/

https://gist.github.com/its-a-feature/1a34f597fb30985a2742bb16116e74e0


// Some code
← All journal articles
Scroll to Top
Home