๐Ÿ—„๏ธLDAP

LDAP Queries

Groups

Code

Get-ADObject -LDAPFilter '(objectClass=group)' | select cn

Example

cn
--
Administrators
Users
Guests
Print Operators
Backup Operators
Replicator
Remote Desktop Users
Network Configuration Operators

Administratively Disabled Account

Code

Reference

AD Powershell Filters

Filter Installed Software

Code

Filter Out Microsoft Software

Code

Filter for SQL

Code

Filter Administrative Groups

Code

  • The group with this attribute set to 1 are protected by AdminSDHolderarrow-up-right 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.

Filter Administrative Users (DoesNotRequiredPreAuth)

Code

  • Administrative users with the DoesNotRequirePreAuth attribute set can be ASREPRoasted.

Find Administrative Users with the ServicePrincipalName

Code

Operators

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

Example

Wildcard *

Code

Escaping Characters

Character
Escaped As
Note

โ€œ

`โ€

Only needed if the data is enclosed in double-quotes.

โ€˜

\โ€™

Only needed if the data is enclosed in single quotes.

NUL

\00

Standard LDAP escape sequence.

\

\5c

Standard LDAP escape sequence.

*

\2a

Escaped automatically, but only in -eq and -ne comparisons. Use -like and -notlike operators for wildcard comparison.

(

/28

Escaped automatically.

)

/29

Escaped automatically.

/

/2f

Escaped automatically.

LDAP Search Filters

Description Field

Code

Find Trusted Users

Code

Find Trusted Computers

Code

Users With Blank Password

Code

Reference

Recursive Match - Powershell

Members Of A Group

Code

User's Group Membership

Code

All Groups of User

Code

Recursvie Match - LDAP Query

All Groups of User

Basic Operators

Operator
Function

&

and

|

or

!

not

AND Operation Example

  • One criteria: (& (..C1..) (..C2..))

  • More than two criteria: (& (..C1..) (..C2..) (..C3..))

OR Operation Example

  • One criteria: (| (..C1..) (..C2..))

  • More than two criteria: (| (..C1..) (..C2..) (..C3..))

Nested Operations Example

  • "(|(& (..C1..) (..C2..))(& (..C3..) (..C4..)))" translates to "(C1 AND C2) OR (C3 AND C4)".

Search Criteria

Criteria
Rule
Example

Equal to

(attribute=123)

(&(objectclass=user)(displayName=Smith)

Not equal to

(!(attribute=123))

!objectClass=group)

Present

(attribute=*)

(department=*)

Not present

(!(attribute=*))

(!homeDirectory=*)

Greater than

(attribute>=123)

(maxStorage=100000)

Less than

(attribute<=123)

(maxStorage<=100000)

Approximate match

(attribute~=123)

(sAMAccountName~=Jason)

Wildcards

(attribute=*A)

(givenName=*Sam)

Object Identifiers (OIDs)

Matching rule OID
String identifier
Description

LDAP_MATCHING_RULE_BIT_AND

A match is found only if all bits from the attribute match the value. This rule is equivalent to a bitwise AND operator.

LDAP_MATCHING_RULE_BIT_OR

A match is found if any bits from the attribute match the value. This rule is equivalent to a bitwise OR operator.

LDAP_MATCHING_RULE_IN_CHAIN

This rule is limited to filters that apply to the DN. This is a special "extended" match operator that walks the chain of ancestry in objects all the way to the root until it finds a match.

Reference

Filter Disabled User Accounts

Code

Find All Groups

Code

Filter Types

Operator
Meaning

=

Equal to

~=

Approximately equal to

>=

Greater than or equal to

<=

Less than or equal to

Item Types

Type

Meaning

=

Simple

=*

Present

=something*

Substring

Extensible

varies depending on type

Escaping Characters

Character
Represented as Hex

*

\2a

(

\28

)

\29

\

\5c

NUL

\00

SearchScope

Name
Level
Description

Base

0

The object is specified as the SearchBase. For example, if we ask for all users in an OU defining a base scope, we get no results. If we specify a user or use Get-ADObject we get just that user or object returned.

OneLevel

1

Searches for objects in the container defined by the SearchBase but not in any sub-containers.

SubTree

2

Searches for objects contained by the SearchBase and all child containers, including their children, recursively all the way down the AD hierarchy.

  • SearchScope Onelevel is interpreted the same as "SearchScope 1".

Count of All AD Users - PowerShell

Code

Built-in Tools

User Account Control (UAC) - PowerShell

Code

Convert UAC Values - Scriptarrow-up-right

Code

Example

Domain Accounts - PowerView

Code

DS Tools

Code

AD PowerShell Module

Code

Windows Management Instrumentation (WMI)

Code

AD Service Interfaces (ADSI)

Code

LDAP Anonymous Bind

Verify Using Python

Example

chevron-right<snip>hashtag

Ldapsearch

Code

Windapsearch

Code

Ldapsearch-ad

Asreproast

Code

Pass-pols

Code

Kerberoasting

Code

-t search --search-filter '(objectClass=domainDNS)'

code

Credentialed LDAP Enumeration

Last updated