02. Active Directory LDAP
02. Active Directory LDAP
This can be leveraged to move laterally and vertically within a network and gain
unauthorized access. AD is essentially a large database accessible to all users within the
domain, regardless of their privilege level. A basic AD user account with no added privileges
can be used to enumerate the majority of objects contained within AD, including but not
limited to:
Domain Computers
Domain Users
Domain Group Information
Default Domain Policy
Domain Functional Levels
Password Policy
Group Policy Objects (GPOs)
Kerberos Delegation
Domain Trusts
Access Control Lists (ACLs)
This data will paint a clear picture of the overall security posture of an Active Directory
environment. It can be used to quickly identify misconfigurations, overly permissive policies,
and other ways of escalating privileges within an AD environment. Many attacks exist that
merely leverage AD misconfigurations, bad practices, or poor administration, such as:
Kerberoasting / ASREPRoasting
NTLM Relaying
Network traffic poisoning
Password spraying
Kerberos delegation abuse
Domain trust abuse
Credential theft
Object control
Hardening Active Directory, along with a strong patching and configuration management
policy, and proper network segmentation should be prioritized. If an environment is tightly
managed and an adversary can gain a foothold and bypass EDR or other protections, proper
management of AD can prevent them from escalating privileges, moving laterally, and getting
to the crown jewels. Proper controls will help slow down an attacker and potentially force
them to become noisier and risk detection.
We can see this structure graphically by opening Active Directory Users and
Computers on a Domain Controller. In our lab domain INLANEFREIGHT.LOCAL , we see
various OUs such as Admin , Employees , Servers , Workstations , etc. Many of these
OUs have OUs nested within them, such as the Mail Room OU under Employees . This
helps maintain a clear and coherent structure within Active Directory, which is especially
important as we add Group Policy Objects (GPOs) to enforce settings throughout the
domain.
Module Exercises
Throughout this module, you will connect to various target hosts via the Remote Desktop
Protocol (RDP) to complete the exercises. Any necessary credentials will be provided with
each exercise, and the RDP connection can be made via xfreerdp from the Pwnbox as
follows:
Any necessary tools can be found in the c:\tools directory after logging in to the target
host.
Getting Started
Once we have a foothold in an AD environment, we should start by gathering several key
pieces of information, including but not limited to:
With this information in hand, we can look for any "quick wins" such as our current user or
the entire Domain Users group having RDP and/or local administrator access to one or
more hosts. This is common in large environments for many reasons, one being the
improper use of jump hosts and another being Citrix server Remote Desktop Services (RDS)
misconfigurations. We should also check what rights our current user has in the domain. Are
they a member of any privileged groups? Do they have any special rights delegated? Do
they have any control over another domain object such as a user, computer, or GPO?
The enumeration process is iterative. As we move through the AD environment,
compromising hosts and users, we will need to perform additional enumeration to see if we
have gained any further access to help us reach our goal.
AD contains many groups that grant their members powerful rights and privileges. Many of
these can be abused to escalate privileges within a domain and ultimately gain Domain
Admin or SYSTEM privileges on a Domain Controller (DC). Some of these groups are listed
below.
Group Description
Default Domain Admins and Enterprise Admins "super" groups.
Administrators
Server Members can modify services, access SMB shares, and backup files.
Operators
Backup Members are allowed to log onto DCs locally and should be
Operators considered Domain Admins. They can make shadow copies of the
SAM/NTDS database, read the registry remotely, and access the file
system on the DC via SMB. This group is sometimes added to the
local Backup Operators group on non-DCs.
Print Operators Members are allowed to logon to DCs locally and "trick" Windows into
loading a malicious driver.
Hyper-V If there are virtual DCs, any virtualization admins, such as members
Administrators of Hyper-V Administrators, should be considered Domain Admins.
Account Members can modify non-protected accounts and groups in the
Operators domain.
Remote Members are not given any useful permissions by default but are
Desktop Users often granted additional rights such as Allow Login Through Remote
Desktop Services and can move laterally using the RDP protocol.
Remote Members are allowed to logon to DCs with PSRemoting (This group is
Management sometimes added to the local remote management group on non-
Users DCs).
Group Policy Members can create new GPOs but would need to be delegated
Creator Owners additional permissions to link GPOs to a container such as a domain
or OU.
Schema Admins Members can modify the Active Directory schema structure and can
backdoor any to-be-created Group/GPO by adding a compromised
account to the default object ACL.
Group Description
DNS Admins Members have the ability to load a DLL on a DC but do not have the
necessary permissions to restart the DNS server. They can load a
malicious DLL and wait for a reboot as a persistence mechanism.
Loading a DLL will often result in the service crashing. A more reliable
way to exploit this group is to create a WPAD record.
adminCount : 1
CanonicalName : INLANEFREIGHT.LOCAL/Users/Schema Admins
CN : Schema Admins
Created : 7/26/2020 4:14:37 PM
createTimeStamp : 7/26/2020 4:14:37 PM
Deleted :
Description : Designated administrators of the schema
DisplayName :
DistinguishedName : CN=Schema
Admins,CN=Users,DC=INLANEFREIGHT,DC=LOCAL
dSCorePropagationData : {7/29/2020 11:52:30 PM, 7/29/2020
11:09:16 PM, 7/27/2020 9:45:00 PM, 7/27/2020
9:34:13 PM...}
GroupCategory : Security
GroupScope : Universal
groupType : -2147483640
HomePage :
instanceType : 4
isCriticalSystemObject : True
isDeleted :
LastKnownParent :
ManagedBy :
member : {CN=Jenna Smith,OU=Server
Team,OU=IT,OU=Employees,DC=INLANEFREIGHT,DC=LOCAL,
CN=Administrator,CN=Users,DC=INLANEFREIGHT,DC=LOCAL}
MemberOf : {CN=Denied RODC Password Replication
Group,CN=Users,DC=INLANEFREIGHT,DC=LOCAL}
Members : {CN=Jenna Smith,OU=Server
Team,OU=IT,OU=Employees,DC=INLANEFREIGHT,DC=LOCAL,
CN=Administrator,CN=Users,DC=INLANEFREIGHT,DC=LOCAL}
Modified : 7/30/2020 2:04:05 PM
modifyTimeStamp : 7/30/2020 2:04:05 PM
Name : Schema Admins
nTSecurityDescriptor :
System.DirectoryServices.ActiveDirectorySecurity
ObjectCategory :
CN=Group,CN=Schema,CN=Configuration,DC=INLANEFREIGHT,DC=LOCAL
ObjectClass : group
ObjectGUID : 36eef5cb-92b1-47d2-a25d-b9d73783ed1e
objectSid : S-1-5-21-2974783224-3764228556-
2640795941-518
ProtectedFromAccidentalDeletion : False
SamAccountName : Schema Admins
sAMAccountType : 268435456
sDRightsEffective : 15
SID : S-1-5-21-2974783224-3764228556-
2640795941-518
SIDHistory : {}
uSNChanged : 66825
uSNCreated : 12336
whenChanged : 7/30/2020 2:04:05 PM
whenCreated : 7/26/2020 4:14:37 PM
Typing the command whoami /priv will give you a listing of all user rights assigned to your
current user. Some rights are only available to administrative users and can only be
listed/leveraged when running an elevated cmd or PowerShell session. These concepts of
elevated rights and User Account Control (UAC) are security features introduced with
Windows Vista to default to restricting applications from running with full permissions unless
absolutely necessary. If we compare and contrast the rights available to us as an admin in a
non-elevated console vs. an elevated console, we will see that they differ drastically. Let's try
this out as the htb-student user on the lab machine.
PRIVILEGES INFORMATION
----------------------
PRIVILEGES INFORMATION
----------------------
PRIVILEGES INFORMATION
----------------------
User rights increase based on the groups they are placed in and/or their assigned privileges.
Below is an example of the rights granted to users in the Backup Operators group. Users
in this group do have other rights that are currently restricted by UAC. Still, we can see from
this command that they have the SeShutdownPrivilege , which means that they can shut
down a domain controller that could cause a massive service interruption should they log
onto a domain controller locally (not via RDP or WinRM).
PRIVILEGES INFORMATION
----------------------
As attackers and defenders, we need to review the membership of these groups. It's not
uncommon to find seemingly low privileged users added to one or more of these groups,
which can be used to further access or compromise the domain.
Note: When spawning your target, we ask you to wait for 3 minutes until the whole lab with
all the configurations is set up so that the connection to your target works flawlessly.
RSAT Background
The Remote Server Administration Tools ( RSAT ) have been part of Windows since the
days of Windows 2000. RSAT allows systems administrators to remotely manage Windows
Server roles and features from a workstation running Windows 10, Windows 8.1, Windows 7,
or Windows Vista. RSAT can only be installed on Professional or Enterprise editions of
Windows. In an enterprise environment, RSAT can remotely manage Active Directory, DNS,
and DHCP. RSAT also allows us to manage installed server roles and features, File
Services, and Hyper-V. The full listing of tools included with RSAT is:
This script can be used to install RSAT in Windows 10 1809, 1903, and 1909. Installation
instructions for other versions of Windows, as well as additional information about RSAT, can
be found here. RSAT can be installed easily with PowerShell as well.
We can check which, if any, RSAT tools are installed using PowerShell.
Name State
---- -----
Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0 NotPresent
Rsat.BitLocker.Recovery.Tools~~~~0.0.1.0 NotPresent
Rsat.CertificateServices.Tools~~~~0.0.1.0 NotPresent
Rsat.DHCP.Tools~~~~0.0.1.0 NotPresent
Rsat.Dns.Tools~~~~0.0.1.0 NotPresent
Rsat.FailoverCluster.Management.Tools~~~~0.0.1.0 NotPresent
Rsat.FileServices.Tools~~~~0.0.1.0 NotPresent
Rsat.GroupPolicy.Management.Tools~~~~0.0.1.0 NotPresent
Rsat.IPAM.Client.Tools~~~~0.0.1.0 NotPresent
Rsat.LLDP.Tools~~~~0.0.1.0 NotPresent
Rsat.NetworkController.Tools~~~~0.0.1.0 NotPresent
Rsat.NetworkLoadBalancing.Tools~~~~0.0.1.0 NotPresent
Rsat.RemoteAccess.Management.Tools~~~~0.0.1.0 NotPresent
Rsat.RemoteDesktop.Services.Tools~~~~0.0.1.0 NotPresent
Rsat.ServerManager.Tools~~~~0.0.1.0 NotPresent
Rsat.Shielded.VM.Tools~~~~0.0.1.0 NotPresent
Rsat.StorageMigrationService.Management.Tools~~~~0.0.1.0 NotPresent
Rsat.StorageReplica.Tools~~~~0.0.1.0 NotPresent
Rsat.SystemInsights.Management.Tools~~~~0.0.1.0 NotPresent
Rsat.VolumeActivation.Tools~~~~0.0.1.0 NotPresent
Rsat.WSUS.Tools~~~~0.0.1.0 NotPresent
From here, we can choose to install all available tools using the following command:
Once installed, all of the tools will be available under Administrative Tools in the
Control Panel .
Domain Context for Enumeration
Many tools are missing credential and context parameters and instead get those values
directly from the current context. There are a few ways to alter a user's context in Windows if
you have access to a password or a hash, such as:
Using " runas /netonly " to leverage the built-in runas.exe command line tool.
Other tools that we will discuss in later modules, such as Rubeus and mimikatz can be
passed cleartext credentials or an NTLM password hash.
Alternatively, we can enumerate the domain from a non-domain joined host (provided that it
is in a subnet that communicates with a domain controller) by launching any RSAT snap-ins
using " runas " from the command line. This is particularly useful if we find ourselves
performing an internal assessment, gain valid AD credentials, and would like to perform
enumeration from a Windows VM.
We can also open the MMC Console from a non-domain joined computer using the following
command syntax:
Type the target domain into the Change domain dialogue box, here
freightlogistics.local . From here, we can now freely enumerate the domain using any
of the AD RSAT snapins.
While these graphical tools are useful and easy to use, they are very inefficient when trying
to enumerate a large domain. In the next few sections, we will introduce LDAP and various
types of search filters that we can use to enumerate AD using PowerShell. The topics that
we cover in these sections will help us gain a better understanding of how AD works and
how to search for information efficiently, which will ultimately better inform us on the usage of
the more "automated" tools and scripts that we will cover in the next two AD Enumeration
modules.
There are several ways to gain SYSTEM-level access on a host, including but not limited to:
Enumerate the domain and gather data such as information about domain users and
groups, local administrator access, domain trusts, ACLs, user and computer properties,
etc., using BloodHound , and PowerView / SharpView .
Perform Kerberoasting / ASREPRoasting attacks.
Run tools such as Inveigh to gather Net-NTLM-v2 hashes or perform relay attacks.
Perform token impersonation to hijack a privileged domain user account.
Carry out ACL attacks.
LDAP Overview
LDAP is an open-source and cross-platform protocol used for authentication against various
directory services (such as AD). As discussed in the previous section, AD stores user
account information and security information such as passwords and facilitates sharing this
information with other devices on the network. LDAP is the language that applications use to
communicate with other servers that also provide directory services. In other words, LDAP is
a way that systems in the network environment can "speak" to AD.
An LDAP session begins by first connecting to an LDAP server, also known as a Directory
System Agent . The Domain Controller in AD actively listens for LDAP requests, such as
security authentication requests.
The relationship between AD and LDAP can be compared to Apache and HTTP. The same
way Apache is a web server that uses the HTTP protocol, Active Directory is a directory
server that uses the LDAP protocol.
While uncommon, you may come across organizations while performing an assessment that
does not have AD but does have LDAP, meaning that they most likely use another type of
LDAP server such as OpenLDAP.
AD LDAP Authentication
LDAP is set up to authenticate credentials against AD using a "BIND" operation to set the
authentication state for an LDAP session. There are two types of LDAP authentication.
LDAP Queries
We can communicate with the directory service using LDAP queries to ask the service for
information. For example, the following query can be used to find all workstations in a
network (objectCategory=computer) while this query can be used to find all domain
controllers: (&(objectCategory=Computer)
(userAccountControl:1.2.840.113556.1.4.803:=8192)) .
LDAP queries can be used to perform user-related searches, such as " (&
(objectCategory=person)(objectClass=user)) " which searches for all users, as well as
group related searches such as " (objectClass=group) " which returns all groups. Here is
one example of a simple query to find all AD groups using the " Get-ADObject " cmdlet and
the " LDAPFilter parameter ".
name
--
Administrators
Users
Guests
Print Operators
Backup Operators
Replicator
Remote Desktop Users
Network Configuration Operators
Performance Monitor Users
Performance Log Users
Distributed COM Users
IIS_IUSRS
Cryptographic Operators
Event Log Readers
Certificate Service DCOM Access
RDS Remote Access Servers
RDS Endpoint Servers
RDS Management Servers
Hyper-V Administrators
Access Control Assistance Operators
Remote Management Users
<SNIP>
We can also use LDAP queries to perform more detailed searches. This query searches the
domain for all administratively disabled accounts.
samaccountname
useraccountcontrol
-------------- ---
---------------
Guest ACCOUNTDISABLE, PASSWD_NOTREQD, NORMAL_ACCOUNT,
DONT_EXPIRE_PASSWORD
DefaultAccount ACCOUNTDISABLE, PASSWD_NOTREQD, NORMAL_ACCOUNT,
DONT_EXPIRE_PASSWORD
krbtgt ACCOUNTDISABLE, NORMAL_ACCOUNT,
DONT_EXPIRE_PASSWORD
caroline.ali ACCOUNTDISABLE, PASSWD_NOTREQD,
NORMAL_ACCOUNT
$SH2000-FPNHUU487JP0 ACCOUNTDISABLE, PASSWD_NOTREQD,
NORMAL_ACCOUNT
SM_00390f38b41e488ab ACCOUNTDISABLE,
NORMAL_ACCOUNT
SM_e081bc60d79c4597b ACCOUNTDISABLE,
NORMAL_ACCOUNT
SM_a9a4eed7ad2d4369a ACCOUNTDISABLE,
NORMAL_ACCOUNT
SM_d836f82078bf4cf89 ACCOUNTDISABLE,
NORMAL_ACCOUNT
SM_6a24f488535649558 ACCOUNTDISABLE,
NORMAL_ACCOUNT
SM_08a2324990674a87b ACCOUNTDISABLE,
NORMAL_ACCOUNT
SM_d1fea2710dc146b1b ACCOUNTDISABLE,
NORMAL_ACCOUNT
SM_b56189681baa441db ACCOUNTDISABLE,
NORMAL_ACCOUNT
SM_b72a918d27554863b ACCOUNTDISABLE,
NORMAL_ACCOUNT
More examples of basic and more advanced LDAP queries for AD can be found at the
following links:
LDAP queries are extremely powerful tools for querying Active Directory. We can harness
their power to gather a wide variety of information, map out the AD environment, and hunt for
misconfigurations. LDAP queries can be combined with filters to perform even more granular
searches. The next two sections will cover both AD and LDAP search filters in-depth to
prepare us for introducing a variety of AD enumeration tools in subsequent modules.
Note: When spawning your target, we ask you to wait for 3 minutes until the whole lab with
all the configurations is set up so that the connection to your target works flawlessly.
The next two sections will cover the Filter and LDAPFilter parameters used by the
ActiveDirectory PowerShell module cmdlets. It is important to know how to build proper filter
syntax for querying Active Directory using PowerShell . This knowledge gives us a deeper
understanding of how our tools such as PowerView function under the hood and how we
can further harness their power when enumerating Active Directory. It is also useful to
understand how to formulate filters if you find yourself in a situation during an assessment
without any of your tools available to you. Armed with this knowledge, you will be able to
effectively "live off the land" and utilize built-in PowerShell cmdlets to perform your
enumeration tasks (albeit slower than using many of the tools we will cover in this module).
PowerShell Filters
Filters in PowerShell allow you to process piped output more efficiently and retrieve exactly
the information you need from a command. Filters can be used to narrow down specific data
in a large result or retrieve data that can then be piped to another command.
We can use filters with the Filter parameter. A basic example is querying a computer for
installed software:
IdentifyingNumber : {748D3A12-9B82-4B08-A0FF-CFDE83612E87}
Name : VMware Tools
Vendor : VMware, Inc.
Version : 10.3.2.9925305
Caption : VMware Tools
IdentifyingNumber : {EA8CB806-C109-4700-96B4-F1F268E5036C}
Name : Local Administrator Password Solution
Vendor : Microsoft Corporation
Version : 6.2.0.0
Caption : Local Administrator Password Solution
IdentifyingNumber : {2CD849A7-86A1-34A6-B8F9-D72F5B21A9AE}
Name : Microsoft Visual C++ 2017 x64 Additional Runtime -
14.12.25810
Vendor : Microsoft Corporation
Version : 14.12.25810
Caption : Microsoft Visual C++ 2017 x64 Additional Runtime -
14.12.25810
<SNIP>
The above command can provide considerable output. We can use the Filter parameter
with the notlike operator to filter out all Microsoft software (which may be useful when
enumerating a system for local privilege escalation vectors).
IdentifyingNumber : {748D3A12-9B82-4B08-A0FF-CFDE83612E87}
Name : VMware Tools
Vendor : VMware, Inc.
Version : 10.3.2.9925305
Caption : VMware Tools
Operators
The Filter operator requires at least one operator, which can help narrow down search
results or reduce a large amount of command output to something more digestible. Filtering
properly is important, especially when enumerating large environments and looking for very
specific information in the command output. The following operators can be used with the
Filter parameter:
Filter Meaning
-eq Equal to
-le Less than or equal to
-ge Greater than or equal to
-ne Not equal to
-lt Less than
-gt Greater than
-approx Approximately equal to
-bor Bitwise OR
-band Bitwise AND
-recursivematch Recursive match
-like Like
-notlike Not like
-and Boolean AND
-or Boolean OR
-not Boolean NOT
As seen above, the property value (here, sally jones ) can be wrapped in single or double-
quotes. The asterisk ( * ) can be used as a wildcard when performing queries. The
command Get-ADUser -filter {name -like "joe*"} using a wildcard would return all
domain users whose name start with joe (joe, joel, etc.). When using filters, certain
characters must be escaped:
Let's try out some of these filters to enumerate the INLANEFREIGHT.LOCAL domain. We can
search all domain computers for interesting hostnames. SQL servers are a particularly juicy
target on internal assessments. The below command searches all hosts in the domain using
Get-ADComputer , filtering on the DNSHostName property that contains the word SQL .
DistinguishedName : CN=SQL01,OU=SQL
Servers,OU=Servers,DC=INLANEFREIGHT,DC=LOCAL
DNSHostName : SQL01.INLANEFREIGHT.LOCAL
Enabled : True
Name : SQL01
ObjectClass : computer
ObjectGUID : 42cc9264-1655-4bfa-b5f9-21101afb33d0
SamAccountName : SQL01$
SID : S-1-5-21-2974783224-3764228556-2640795941-1104
UserPrincipalName :
Next, let's search for administrative groups. We can do this by filtering on the adminCount
attribute. The group with this attribute set to 1 are protected by AdminSDHolder and known
as protected groups. AdminSDHolder is owned by the Domain Admins group. It has the
privileges to change the permissions of objects in Active Directory. As discussed above, we
can pipe the filtered command output and select just the group names.
Name
----
Administrators
Print Operators
Backup Operators
Replicator
Domain Controllers
Schema Admins
Enterprise Admins
Domain Admins
Server Operators
Account Operators
Read-only Domain Controllers
Security Operations
We can also combine filters. Let's search for all administrative users with the
DoesNotRequirePreAuth attribute set, meaning that they can be ASREPRoasted (this
attack will be covered in-depth in later modules). Here we are selecting all domain users and
specifying two conditions with the -eq operator.
Finally, let's see an example of combining filters and piping output multiple times to find our
desired information. The following command can be used to find all administrative users with
the " servicePrincipalName " attribute set, meaning that they can likely be subject to a
Kerberoasting attack. This example applies the Filter parameter to find accounts with the
adminCount attribute set to 1 , pipes this output to find all accounts with a Service Principal
Name (SPN), and finally selects a few attributes about the accounts, including the account
name, group membership, and the SPN.
SamAccountName : krbtgt
MemberOf : {CN=Denied RODC Password Replication
Group,CN=Users,DC=INLANEFREIGHT,DC=LOCAL}
ServicePrincipalName : {kadmin/changepw}
SamAccountName : sqlqa
MemberOf : {CN=Domain
Admins,CN=Users,DC=INLANEFREIGHT,DC=LOCAL}
ServicePrincipalName : {MSSQL_svc_qa/inlanefreight.local:1443}
It would take an extremely long time to enumerate an Active Directory environment using
many combinations of the commands above. This last example could be performed quickly
and easily with tools such as PowerView or Rubeus . Nevertheless, it is important to apply
filters competently when enumerating AD as the output from tools like PowerView can even
be further filtered to provide us with precise results.
Note: When spawning your target, we ask you to wait for 3 minutes until the whole lab with
all the configurations is set up so that the connection to your target works flawlessly.
LDAP filters must have one or more criteria. If more than one criteria exist, they can be
concatenated together using logical AND or OR operators. These operators are always
placed in the front of the criteria (operands), which is also referred to as Polish Notation.
Filter rules are enclosed in parentheses and can be grouped by surrounding the group in
parentheses and using one of the following comparison operators:
Operator Function
& and
` `
! not
AND Operation:
OR Operation:
We can also have nested operations, for example " (|(& (..C1..) (..C2..))(& (..C3..)
(..C4..))) " translates to " (C1 AND C2) OR (C3 AND C4) ".
Search Criteria
When writing an LDAP search filter, we need to specify a rule requirement for the LDAP
attribute in question (i.e. " (displayName=william) "). The following rules can be used to
specify our search criteria:
This link contains a large listing of User Attributes, and the below is a list of all Base
Attributes.
We can clarify the above OIDs with some examples. Let's take the following LDAP query:
(&(objectCategory=person)(objectClass=user)
(userAccountControl:1.2.840.113556.1.4.803:=2))
This query will return all administratively disabled user accounts, or ACCOUNTDISABLE (2).
We can combine this query as an LDAP search filter with the " Get-ADUser " cmdlet against
our target domain. The LDAP query can be shortened as follows:
name
----
Guest
DefaultAccount
krbtgt
Exchange Online-ApplicationAccount
SystemMailbox{1f05a927-35b9-4cc9-bbe1-11e28cddb180}
SystemMailbox{bb558c35-97f1-4cb9-8ff7-d53741dc928c}
SystemMailbox{e0dc1c29-89c3-4034-b678-e6c29d823ed9}
DiscoverySearchMailbox {D919BA05-46A6-415f-80AD-7E09334BB852}
Migration.8f3e7716-2011-43e4-96b1-aba62d229136
FederatedEmail.4c1f4d8b-8179-4148-93bf-00a95fa1e042
SystemMailbox{D0E409A0-AF9B-4720-92FE-AAC869B0D201}
SystemMailbox{2CE34405-31BE-455D-89D7-A7C7DA7A0DAA}
SystemMailbox{8cc370d3-822a-4ab8-a926-bb94bd0641a9}
Now let's look at an example of the extensible match rule " 1.2.840.113556.1.4.1941 ".
Consider the following query:
(member:1.2.840.113556.1.4.1941:=CN=Harry Jones,OU=Network
Ops,OU=IT,OU=Employees,DC=INLANEFREIGHT,DC=LOCAL)
This matching rule will find all groups that the user Harry Jones (" CN=Harry
Jones,OU=Network Ops,OU=IT,OU=Employees,DC=INLANEFREIGHT,DC=LOCAL ") is a
member of. Using this filter with the " Get-ADGroup " cmdlet gives us the following output:
Name
----
Administrators
Backup Operators
Domain Admins
Denied RODC Password Replication Group
LAPS Admins
Security Operations
Help Desk
Network Team
Operator Meaning
= Equal to
~= Approximately equal to
>= Greater than or equal to
<= Less than or equal to
We can use the filter " (&(objectCategory=user)(description=*)) " to find all user
accounts that do not have a blank description field. This is a useful search that should be
performed on every internal network assessment as it not uncommon to find passwords for
users stored in the user description attribute in AD (which can be read by all AD users).
Combining this with the " Get-ADUser " cmdlet, we can search for all domain users that do
not have a blank description field and, in this case, find a service account password!
samaccountname description
-------------- -----------
Administrator Built-in account for administering the computer/domain
Guest Built-in account for guest access to the computer/domain
DefaultAccount A user account managed by the system.
krbtgt Key Distribution Center Service Account
svc-sccm **Do not change password** 03/04/2015 N3ssu$_svc2014!
Name : sqldev
memberof : {CN=Protected
Users,CN=Users,DC=INLANEFREIGHT,DC=LOCAL}
servicePrincipalName : {MSSQL_svc_dev/inlanefreight.local:1443}
TrustedForDelegation : True
DistinguishedName : CN=DC01,OU=Domain
Controllers,DC=INLANEFREIGHT,DC=LOCAL
servicePrincipalName : {exchangeAB/DC01,
exchangeAB/DC01.INLANEFREIGHT.LOCAL, TERMSRV/DC01,
TERMSRV/DC01.INLANEFREIGHT.LOCAL...}
TrustedForDelegation : True
DistinguishedName : CN=SQL01,OU=SQL
Servers,OU=Servers,DC=INLANEFREIGHT,DC=LOCAL
servicePrincipalName : {MSSQLsvc/SQL01.INLANEFREIGHT.LOCAL:1433,
TERMSRV/SQL01, TERMSRV/SQL01.INLANEFREIGHT.LOCAL,
RestrictedKrbHost/SQL01...}
TrustedForDelegation : True
Lastly, let's search for all users with the " adminCount " attribute set to 1 whose "
useraccountcontrol " attribute is set with the flag " PASSWD_NOTREQD ," meaning that the
account can have a blank password set. To do this, we must combine two LDAP search
filters as follows:
(&(objectCategory=person)(objectClass=user)
(userAccountControl:1.2.840.113556.1.4.803:=32))(adminCount=1)
While uncommon, we find accounts without a password set from time to time, so it is always
important to enumerate accounts with the PASSWD_NOTREQD flag set and check to see if they
indeed do not have a password set. This could happen intentionally (perhaps as a
timesaver) or accidentally if a user with this flag set changes their password via command
line and accidentally presses enter before typing in a password. All organizations should
perform periodic account audits and remove this flag from any accounts that have no valid
business reason to have it set.
Try out building some filters of your own. This guide Active Directory: LDAP Syntax Filters is
a great starting point.
Recursive Match
We can use the " RecursiveMatch " parameter in a similar way that we use the matching
rule OID " 1.2.840.113556.1.4.1941 ". A good example of this is to find all of the groups
that an AD user is a part of, both directly and indirectly. This is also known as "nested group
membership." For example, the user bob.smith may not be a direct member of the Domain
Admins group but has derivative Domain Admin rights because the group Security
Operations is a member of the Domain Admins group. We can see this graphically by
looking at Active Directory Computers and Users .
We can enumerate this with PowerShell several ways, one way being the " Get-
ADGroupMember " cmdlet.
As we can see above, the Security Operations group is indeed "nested" within the
Domain Admins group. Therefore any of its members are effectively Domain Admins.
Searching for a user's group membership using Get-ADUser focusing on the property
memberof will not directly show this information.
memberof
--------
{CN=Network Team,CN=Users,DC=INLANEFREIGHT,DC=LOCAL, CN=Help
Desk,OU=Microsoft Exchange Security
Groups,DC=INLANEFREIGHT,DC=LOCAL, CN=Security
Operations,CN=Users,DC=INLANEFREIGHT,DC=LOCAL, CN=LAPS
Admins,CN=Users,DC=INLANEFREIGHT,DC=LOCAL...}
We can find nested group membership with the matching rule OID and the RecursiveMatch
parameter, as seen in the following examples. The first example shows an AD filter and the
RecursiveMatch to recursively query for all groups that the user harry.jones is a member
of.
name
----
Administrators
Backup Operators
Domain Admins
Denied RODC Password Replication Group
LAPS Admins
Security Operations
Help Desk
Network Team
Another way to return this same information is by using an LDAPFilter and the matching
rule OID.
Name
----
Administrators
Backup Operators
Domain Admins
Denied RODC Password Replication Group
LAPS Admins
Security Operations
Help Desk
Network Team
We can improve the performance of our enumeration commands and scripts and reduce the
volume of objects returned by scoping our searches using the " SearchBase " parameter.
This parameter specifies an Active Directory path to search under and allows us to begin
searching for a user account in a specific OU. The " SearchBase " parameter accepts an
OUs distinguished name (DN) such as "OU=Employees,DC=INLANEFREIGHT,DC=LOCAL" .
" SearchScope " allows us to define how deep into the OU hierarchy we would like to search.
This parameter has three levels:
When querying AD using " SearchScope " we can specify the name or the number (i.e.,
SearchScope Onelevel is interpreted the same as " SearchScope 1 ".)
In the above example, with the SearchBase set to
OU=Employees,DC=INLANEFREIGHT,DC=LOCAL, a SearchScope set to Base would
attempt to query the OU object ( Employees ) itself. A SearchScope set to OneLevel would
search within the Employees OU only. Finally, a SearchScope set to SubTree would query
the Employees OU and all of the OUs underneath it, such as Accounting , Contractors ,
etc. OUs under those OUs (child containers).
970
However, if we specify " Base " with " Get-ADObject " we will get just the object (Employees
OU) returned to us.
If we specify OneLevel as the SearchScope, we get one user returned to us, as expected
per the image above.
DistinguishedName : CN=Amelia
Matthews,OU=Employees,DC=INLANEFREIGHT,DC=LOCAL
Enabled : True
GivenName : amelia
Name : Amelia Matthews
ObjectClass : user
ObjectGUID : 3f04328f-eb2e-487c-85fe-58dd598159c0
SamAccountName : amelia.matthews
SID : S-1-5-21-2974783224-3764228556-2640795941-1412
Surname : matthews
UserPrincipalName : amelia.matthews@inlanefreight
As stated above, the SearchScope values are interchangeable, so the same result is
returned when specifying 1 as the SearchScope value.
PowerShell - Searchscope 1
DistinguishedName : CN=Amelia
Matthews,OU=Employees,DC=INLANEFREIGHT,DC=LOCAL
Enabled : True
GivenName : amelia
Name : Amelia Matthews
ObjectClass : user
ObjectGUID : 3f04328f-eb2e-487c-85fe-58dd598159c0
SamAccountName : amelia.matthews
SID : S-1-5-21-2974783224-3764228556-2640795941-1412
Surname : matthews
UserPrincipalName : amelia.matthews@inlanefreight
Finally, if we specify Subtree as the SearchBase, we will get all objects within all child
containers, which matches the user count we established above.
970
Conclusion
This section, as well as the PowerShell Filters section, covered the many ways we can use
search filters combined with built-in AD cmdlets to enhance our enumeration by "living off the
land." In later sections, we will cover tools that make enumeration much quicker and easier
and be combined with filters to be even more powerful. Regardless of if we are using built-in
tools, custom scripts or, third-party tools, it is important to understand what they are doing
and to be able to understand and use the output of our enumeration to help us achieve our
goal.
Note: When spawning your target, we ask you to wait for 3 minutes until the whole lab with
all the configurations is set up so that the connection to your target works flawlessly.
Proper enumeration is key for all penetration testing and red teaming assessments.
Enumerating AD, especially large corporate environments with many hosts, users, and
services, can be quite a daunting task and provide an overwhelming amount of data. Several
built-in Windows tools can be used by sysadmins and pentesters to enumerate AD. Open
source tools have been created based on the same enumeration techniques. Many of these
tools (such as SharpView, BloodHound, and, PingCastle) can be utilized to expedite the
enumeration process and accurately present the data in a consumable and actionable
format. Knowledge of multiple tools and "offense in-depth" is important if you must live off the
land on an assessment or detections are in place for certain tools.
Name useraccountcontrol
---- ------------------
Administrator 66048
krbtgt 66050
daniel.carter 512
sqlqa 512
svc-backup 66048
svc-secops 66048
cliff.moore 66048
svc-ata 512
svc-sccm 512
mrb3n 512
sarah.lafferty 512
Jenna Smith 4260384
Harry Jones 66080
pixis 512
Cry0l1t3 512
knightmare 512
We still need to convert the useraccountcontrol values into their corresponding flags to
interpret them. This can be done with this script. Let's take the user Jenna Smith with
useraccountcontrol value 4260384 as an example.
PS C:\htb> .\Convert-UserAccountControlValues.ps1
Name Value
---- -----
PASSWD_NOTREQD 32
NORMAL_ACCOUNT 512
DONT_EXPIRE_PASSWORD 65536
DONT_REQ_PREAUTH 4194304
We can also use PowerView (which will be covered in-depth in subsequent modules) to
enumerate these values. We can see that some of the users match the default value of 512
or Normal_Account while others would need to be converted. The value for jenna.smith
does match what our conversion script provided.
PowerView can be found in the c:\tools directory on the target host. To load the tool,
open a PowerShell console, navigate to the tools directory, and import PowerView using the
command Import-Module .\PowerView.ps1 .
samaccountname
useraccountcontrol
-------------- -------
-----------
Administrator NORMAL_ACCOUNT,
DONT_EXPIRE_PASSWORD
krbtgt ACCOUNTDISABLE, NORMAL_ACCOUNT,
DONT_EXPIRE_PASSWORD
daniel.carter
NORMAL_ACCOUNT
sqlqa
NORMAL_ACCOUNT
svc-backup NORMAL_ACCOUNT,
DONT_EXPIRE_PASSWORD
svc-secops NORMAL_ACCOUNT,
DONT_EXPIRE_PASSWORD
cliff.moore NORMAL_ACCOUNT,
DONT_EXPIRE_PASSWORD
svc-ata
NORMAL_ACCOUNT
svc-sccm
NORMAL_ACCOUNT
mrb3n
NORMAL_ACCOUNT
sarah.lafferty
NORMAL_ACCOUNT
jenna.smith PASSWD_NOTREQD, NORMAL_ACCOUNT, DONT_EXPIRE_PASSWORD,
DONT_REQ_PREAUTH
harry.jones PASSWD_NOTREQD, NORMAL_ACCOUNT,
DONT_EXPIRE_PASSWORD
pixis
NORMAL_ACCOUNT
Cry0l1t3
NORMAL_ACCOUNT
knightmare
NORMAL_ACCOUNT
DS Tools is available by default on all modern Windows operating systems but required
domain connectivity to perform enumeration activities.
DS Tools
samid pwdneverexpires
svc-backup yes
svc-scan yes
svc-secops yes
sql-test yes
cliff.moore yes
margaret.harris yes
<SNIP>
dsget succeeded
The PowerShell Active Directory module is a group of cmdlets used to manage Active
Directory. The installation of the AD PowerShell module requires administrative access.
AD PowerShell Module
DistinguishedName : CN=wilford.stewart,OU=Admin,DC=INLANEFREIGHT,DC=LOCAL
Enabled : True
GivenName :
Name : wilford.stewart
ObjectClass : user
ObjectGUID : 1f54c02c-2fb4-48b6-a89c-38b6b0c54147
SamAccountName : wilford.stewart
SID : S-1-5-21-2974783224-3764228556-2640795941-2121
Surname :
UserPrincipalName :
DistinguishedName : CN=trisha.duran,OU=Admin,DC=INLANEFREIGHT,DC=LOCAL
Enabled : True
GivenName :
Name : trisha.duran
ObjectClass : user
ObjectGUID : 7a8db2bb-7b24-4f79-a3fe-7b49408bc7bf
SamAccountName : trisha.duran
SID : S-1-5-21-2974783224-3764228556-2640795941-2122
Surname :
UserPrincipalName :
<SNIP>
Windows Management Instrumentation (WMI) can also be used to access and query
objects in Active Directory. Many scripting languages can interact with the WMI AD provider,
but PowerShell makes this very easy.
Caption Name
------- ----
INLANEFREIGHT\Cert Publishers Cert Publishers
INLANEFREIGHT\RAS and IAS Servers RAS and IAS Servers
INLANEFREIGHT\Allowed RODC Password Replication Group Allowed RODC
Password Replication Group
INLANEFREIGHT\Denied RODC Password Replication Group Denied RODC Password
Replication Group
INLANEFREIGHT\DnsAdmins DnsAdmins
INLANEFREIGHT\$6I2000-MBUUOKUK1E1O $6I2000-MBUUOKUK1E1O
INLANEFREIGHT\Cloneable Domain Controllers Cloneable Domain
Controllers
INLANEFREIGHT\Compliance Management Compliance
Management
INLANEFREIGHT\Delegated Setup Delegated Setup
INLANEFREIGHT\Discovery Management Discovery Management
INLANEFREIGHT\DnsUpdateProxy DnsUpdateProxy
INLANEFREIGHT\Domain Admins Domain Admins
INLANEFREIGHT\Domain Computers Domain Computers
INLANEFREIGHT\Domain Controllers Domain Controllers
INLANEFREIGHT\Domain Guests Domain Guests
INLANEFREIGHT\Domain Users Domain Users
INLANEFREIGHT\Enterprise Admins Enterprise Admins
INLANEFREIGHT\Enterprise Key Admins Enterprise Key
Admins
INLANEFREIGHT\Enterprise Read-only Domain Controllers Enterprise Read-only
Domain Controllers
INLANEFREIGHT\Exchange Servers Exchange Servers
INLANEFREIGHT\Exchange Trusted Subsystem Exchange Trusted
Subsystem
INLANEFREIGHT\Exchange Windows Permissions Exchange Windows
Permissions
INLANEFREIGHT\ExchangeLegacyInterop
ExchangeLegacyInterop
INLANEFREIGHT\Group Policy Creator Owners Group Policy Creator
Owners
INLANEFREIGHT\Help Desk Help Desk
INLANEFREIGHT\Hygiene Management Hygiene Management
INLANEFREIGHT\Key Admins Key Admins
INLANEFREIGHT\LAPS Admins LAPS Admins
INLANEFREIGHT\Managed Availability Servers Managed Availability
Servers
INLANEFREIGHT\Organization Management Organization
Management
INLANEFREIGHT\Protected Users Protected Users
<SNIP>
Active Directory Service Interfaces (ADSI) is a set of COM interfaces that can query
Active Directory. PowerShell again provides an easy way to interact with it.
Path
----
LDAP://CN=DC01,OU=Domain Controllers,DC=INLANEFREIGHT,DC=LOCAL
LDAP://CN=EXCHG01,OU=Mail Servers,OU=Servers,DC=INLANEFREIGHT,DC=LOCAL
LDAP://CN=SQL01,OU=SQL Servers,OU=Servers,DC=INLANEFREIGHT,DC=LOCAL
LDAP://CN=WS01,OU=Staff
Workstations,OU=Workstations,DC=INLANEFREIGHT,DC=LOCAL
LDAP://CN=DC02,OU=Servers,DC=INLANEFREIGHT,DC=LOCAL
Note: When spawning your target, we ask you to wait for 3 minutes until the whole lab with
all the configurations is set up so that the connection to your target works flawlessly.
When an LDAP server allows anonymous base binds, an attacker does not need to know a
base object to query a considerable amount of information from the domain. This can also be
leveraged to mount a password spraying attack or read information such as passwords
stored in account description fields. Tools such as windapsearch and ldapsearch can be
utilized to enumerate domain information via an anonymous LDAP bind. Information that we
obtain from an anonymous LDAP bind can be leveraged to mount a password spraying or
AS-REPRoasting attack, read information such as passwords stored in account description
fields.
We can use Python to quickly check if we can interact with LDAP without credentials.
<SNIP>
dnsHostName:
DC01.INLANEFREIGHT.LOCAL
ldapServiceName:
INLANEFREIGHT.LOCAL:[email protected]
serverName:
CN=DC01,CN=Servers,CN=Default-First-Site-
Name,CN=Sites,CN=Configuration,DC=INLANEFREIGHT,DC=LOCAL
isSynchronized:
TRUE
isGlobalCatalogReady:
TRUE
domainFunctionality:
7
forestFunctionality:
7
domainControllerFunctionality:
7
Using Ldapsearch
We can confirm anonymous LDAP bind with ldapsearch and retrieve all AD objects from
LDAP.
ldapsearch -H ldap://10.129.1.207 -x -b "dc=inlanefreight,dc=local"
# extended LDIF
#
# LDAPv3
# base <dc=inlanefreight,dc=local> with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#
# INLANEFREIGHT.LOCAL
dn: DC=INLANEFREIGHT,DC=LOCAL
objectClass: top
objectClass: domain
objectClass: domainDNS
distinguishedName: DC=INLANEFREIGHT,DC=LOCAL
instanceType: 5
whenCreated: 20200726201343.0Z
whenChanged: 20200827025341.0Z
subRefs: DC=LOGISTICS,DC=INLANEFREIGHT,DC=LOCAL
subRefs: DC=ForestDnsZones,DC=INLANEFREIGHT,DC=LOCAL
subRefs: DC=DomainDnsZones,DC=INLANEFREIGHT,DC=LOCAL
subRefs: CN=Configuration,DC=INLANEFREIGHT,DC=LOCAL
Using Windapsearch
Windapsearch is a Python script used to perform anonymous and authenticated LDAP
enumeration of AD users, groups, and computers using LDAP queries. It is an alternative to
tools such as ldapsearch , which require you to craft custom LDAP queries. We can use it
to confirm LDAP NULL session authentication but providing a blank username with -u ""
and add --functionality to confirm the domain functional level.
[*] Bye!
We can pull a listing of all domain users to use in a password spraying attack.
cn: Guest
cn: DefaultAccount
cn: LOGISTICS$
cn: sqldev
cn: sqlprod
cn: svc-scan
<SNIP>
cn: DC01
operatingSystem: Windows Server 2016 Standard
operatingSystemVersion: 10.0 (14393)
dNSHostName: DC01.INLANEFREIGHT.LOCAL
cn: EXCHG01
operatingSystem: Windows Server 2016 Standard
operatingSystemVersion: 10.0 (14393)
dNSHostName: EXCHG01.INLANEFREIGHT.LOCAL
cn: SQL01
operatingSystem: Windows Server 2016 Standard
operatingSystemVersion: 10.0 (14393)
dNSHostName: SQL01.INLANEFREIGHT.LOCAL
cn: WS01
operatingSystem: Windows Server 2016 Standard
operatingSystemVersion: 10.0 (14393)
dNSHostName: WS01.INLANEFREIGHT.LOCAL
cn: DC02
dNSHostName: DC02.INLANEFREIGHT.LOCAL
[*] Bye!
This process can be repeated to pull group information and more detailed information such
as unconstrained users and computers, GPO information, user and computer attributes, and
more.
Other Tools
There are many other tools and helper scripts for retrieving information from LDAP. This
script ldapsearch-ad.py is similar to windapsearch .
python3 ldapsearch-ad.py -h
usage: ldapsearch-ad.py [-h] -l LDAP_SERVER [-ssl] -t REQUEST_TYPE [-d
DOMAIN] [-u USERNAME] [-p PASSWORD]
[-s SEARCH_FILTER] [-z SIZE_LIMIT] [-o
OUTPUT_FILE] [-v]
[search_attributes [search_attributes ...]]
positional arguments:
search_attributes LDAP attributes to look for (default is all).
optional arguments:
-h, --help show this help message and exit
-l LDAP_SERVER, --server LDAP_SERVER
IP address of the LDAP server.
-ssl, --ssl Force an SSL connection?.
-t REQUEST_TYPE, --type REQUEST_TYPE
Request type: info, whoami, search, search-large,
trusts, pass-pols, show-admins,
show-user, show-user-list, kerberoast, all
-d DOMAIN, --domain DOMAIN
Authentication account's FQDN. Example:
"contoso.local".
-u USERNAME, --username USERNAME
Authentication account's username.
-p PASSWORD, --password PASSWORD
Authentication account's password.
-s SEARCH_FILTER, --search-filter SEARCH_FILTER
Search filter (use LDAP format).
-z SIZE_LIMIT, --size_limit SIZE_LIMIT
Size limit (default is 100, or server' own limit).
-o OUTPUT_FILE, --output OUTPUT_FILE
Write results in specified file too.
-v, --verbose Turn on debug mode
We can use it to pull domain information and confirm a NULL bind. This particular tool
requires valid domain user credentials to perform additional enumeration.
Note: Tools necessary for completing this section can be found in the `/opt` directory on the
Pwnbox.
Note: When spawning your target, we ask you to wait for 3 minutes until the whole lab with
all the configurations is set up so that the connection to your target works flawlessly.
cn: Administrator
userPrincipalName: [email protected]
cn: daniel.carter
cn: sqlqa
cn: svc-backup
cn: svc-secops
cn: cliff.moore
cn: svc-ata
cn: svc-sccm
cn: mrb3n
cn: sarah.lafferty
cn: pixis
cn: Cry0l1t3
cn: knightmare
cn: Administrator
userPrincipalName: [email protected]
cn: daniel.carter
cn: sqlqa
cn: svc-backup
cn: svc-secops
<SNIP>
Some additional useful options, including pulling users and computers with unconstrained
delegation.
CN=sqldev,OU=Service Accounts,OU=IT,OU=Employees,DC=INLANEFREIGHT,DC=LOCAL
[*] Bye!
Ldapsearch-ad
This tool can perform all of the standard enumeration and a few built-in searches to simplify
things. We can quickly obtain the password policy.
servicePrincipalName: CIFS/roguecomputer.inlanefreight.local
servicePrincipalName: MSSQLSvc/sql01:1433
servicePrincipalName: MSSQL_svc_qa/inlanefreight.local:1443
servicePrincipalName: MSSQL_svc_test/inlanefreight.local:1443
servicePrincipalName: IIS_dev/inlanefreight.local:80
LDAP Wrap-up
We can use tools such as the two shown in this section to perform a considerable amount of
AD enumeration using LDAP. The tools have many built-in queries to simplify searching and
provide us with the most useful and actionable data. We can also combine these tools with
the custom LDAP search filters that we learned about earlier in the module. These are great
tools to keep in our arsenal, especially when we are in a position where most an AD
assessment has to be performed from a Linux attack box.
Note: When spawning your target, we ask you to wait for 3 minutes until the whole lab with
all the configurations is set up so that the connection to your target works flawlessly.
Connect to the target host and perform the enumeration tasks listed below to complete this
module.
Note: When spawning your target, we ask you to wait for 3 minutes until the whole lab with
all the configurations is set up so that the connection to your target works flawlessly.