Microsoft Defender XDR HuntingQuery

Microsoft Defender XDR HuntingQuery

Certified

Run a Microsoft Defender XDR advanced hunting query

Runs a KQL query with Microsoft Graph runHuntingQuery and returns the rows with typed values (dates, numbers, booleans) according to the query schema. Requires the Microsoft Graph application permission ThreatHunting.Read.All.

yaml
type: io.kestra.plugin.microsoft365.defender.HuntingQuery

Store a day of PowerShell process events for a device

yaml
id: defender_hunting
namespace: company.security

inputs:
  - id: deviceName
    type: STRING
    # Device names only, so the input cannot change the KQL query below
    validator: "^[A-Za-z0-9._-]+$"

tasks:
  - id: hunt
    type: io.kestra.plugin.microsoft365.defender.HuntingQuery
    tenantId: "{{ secret('AZURE_TENANT_ID') }}"
    clientId: "{{ secret('AZURE_CLIENT_ID') }}"
    clientSecret: "{{ secret('AZURE_CLIENT_SECRET') }}"
    timespan: P1D
    query: |
      DeviceProcessEvents
      | where DeviceName == "{{ inputs.deviceName }}"
      | where FileName =~ "powershell.exe"
      | project Timestamp, AccountName, ProcessCommandLine

  - id: log
    type: io.kestra.plugin.core.log.Log
    message: "{{ outputs.hunt.count }} rows stored in {{ outputs.hunt.uri }}"
Installation

Our standard Docker images already include this plugin. If you use a -slim image or another setup, install it with the following command:

kestractl plugins get io.kestra.plugin:plugin-microsoft365 --compatible-for $KESTRA_VERSION

For kestractl, use your Kestra version with --compatible-for, or specify an exact plugin version.

Properties

KQL query

Advanced hunting query in Kusto Query Language (KQL). The query is sent as rendered, so validate any input templated into it (for example with an input validator): a value containing " could otherwise change the query.

Assets this task consumes as inputs or produces as outputs, for lineage tracking and the asset graph (Enterprise Edition). A flow declaring this property on a task is rejected in the open-source edition.

Definitions
assetFailureBehaviorstring
Possible Values
IGNOREFAILWARN

Asset failure behavior

Behavior applied to the task state when a declared asset fails to render, emit, or be persisted (e.g. a lock conflict): FAIL escalates it to FAILED, WARN (default) warns it if it would otherwise succeed, IGNORE leaves the state untouched.

enableAutobooleanstring

Whether to auto-register assets referenced dynamically at runtime that are not statically declared in inputs or outputs.

inputsarray

The assets consumed as inputs.

id*string
Min length1
typestring
outputs

The assets produced as outputs.

id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*object
descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150
id*string
Min length1
Max length150
type*string
Min length1

Custom asset type

descriptionstring
displayNamestring
metadataobject
Default{}
namespacestring
Min length1
Max length150

Client ID

Client ID of the Azure service principal. If you don't have a service principal, refer to create a service principal with Azure CLI.

Client Secret

Service principal client secret. Use this for Client Secret authentication. Provide clientId, tenantId, and clientSecret. Either clientSecret OR pemCertificate must be provided, not both.

DefaultSTORE
Possible Values
STOREFETCHFETCH_ONENONE

How to output the rows

FETCH - outputs the rows as rows FETCH_ONE - outputs the first row as row STORE - stores the rows in an ION file and outputs its uri NONE - only outputs count and schema

Default STORE.

PEM Certificate

Alternative authentication method using certificate-based authentication.
Use this for Client Certificate authentication. Provide clientId, tenantId, and pemCertificate.
Either clientSecret OR pemCertificate must be provided, not both.

Tenant ID

DefaultPT168H

Time span

How far back the query looks, as an ISO-8601 duration. Default P7D. Microsoft Graph defaults to 30 days when no time span is sent. This task always sends one.

Default0

Number of rows returned

First row (FETCH_ONE)

SubTypeobject

Rows (FETCH)

SubTypeobject

Query schema

Column names and Kusto types, as name and type.

Formaturi

URI of the ION file with the rows (STORE)