Skip to content
WETNav

Discovery · Windows

dsquery.exe

Directory Service Query

Queries Active Directory for users, computers, groups and other objects. It is part of RSAT, so it is unusual on ordinary workstations.

Legitimate use

Directory admins use it to search AD from the command line.

Worst caseMedium

Subcommands

user

Searches for user accounts.

Low
computer

Searches for computer accounts.

Low
group

Searches for groups.

Low
server

Searches for domain controllers.

Low
site

Searches for AD sites.

Low
subnet

Searches for AD subnets, which shows the network layout.

Low
*

Runs a raw LDAP filter against the directory.

Medium

Switches

-filter<value>

LDAP filter for a * query.

Medium
-attr<value>

Attributes to return.

Low
-limit<value>

Maximum number of results. 0 means no limit.

Low

Command lines to worry about

  • Medium

    Unbounded directory query

    Pulls every matching object from AD. Bulk exports like this are typical of domain mapping.

    Detection regexdsquery(\.exe)?\s+\*.*-limit\s+0

    T1087.002

Where it is recorded

  • Security4688Process creation with the full command line, when command-line auditing is enabled.
  • Sysmon1Process creation with command line, hashes and parent process.

Community detections

2 SigmaHQ rules for dsquery.exe. The explainer checks every pasted command line against all of them.

  • High
    Webshell Detection With Command Line Keywords

    Detects certain command line parameters often used during reconnaissance activity via web shells

    T1505.003T1018T1033T1087by Florian Roth (Nextron Systems), Jonhnathan Ribeiro, Anton Kutepov, oscd.community, Chad Hudson, Matt Anderson

  • Medium
    Domain Trust Discovery Via Dsquery

    Detects execution of "dsquery.exe" for domain trust discovery

    T1482by E.M. Anhaus, Tony Lambert, oscd.community, omkar72

Rules from SigmaHQ (rules/windows/process_creation), Detection Rule License (DRL) 1.1. Each rule links to its source and credits its authors.