Microsoft Defender XDR HuntingQuery
Certified
Run a Microsoft Defender XDR advanced hunting query
Microsoft Defender XDR HuntingQuery
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.
type: io.kestra.plugin.microsoft365.defender.HuntingQueryExamples
Store a day of PowerShell process events for a device
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
query *string
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
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.
io.kestra.core.models.assets.AssetsDeclaration
IGNOREFAILWARNAsset 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.
Whether to auto-register assets referenced dynamically at runtime that are not statically declared in inputs or outputs.
The assets consumed as inputs.
io.kestra.core.models.assets.AssetIdentifier
1The assets produced as outputs.
io.kestra.plugin.ee.assets.Dataset
1150{}1150io.kestra.plugin.ee.assets.File
1150{}1150io.kestra.plugin.ee.assets.Table
1150{}1150io.kestra.plugin.ee.assets.VM
1150{}1150io.kestra.core.models.assets.External
1150{}1150io.kestra.core.models.assets.Custom
11501Custom asset type
{}1150clientId string
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.
clientSecret string
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.
fetchType string
STORESTOREFETCHFETCH_ONENONEHow 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.
pemCertificate string
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.
tenantId string
Tenant ID
timespan string
PT168HTime 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.
Outputs
count integer
0Number of rows returned
row object
First row (FETCH_ONE)
rows array
Rows (FETCH)
schema array
Query schema
Column names and Kusto types, as name and type.
uri string
uriURI of the ION file with the rows (STORE)