PL EN
WB-7895F48ETLP:CLEARWazuh 4

Microsoft Graph in Wazuh: Defender XDR alerts and incidents from the ms-graph module

The Wazuh 4.14 ms-graph module pulls Microsoft Graph alerts_v2 and Defender incidents: permissions, ossec.conf options, built-in 995xx rules and a custom rule.

The <ms-graph> module in Wazuh 4.14 polls the Microsoft Graph REST API and turns Defender alerts and incidents into events that go through the usual decoder, rule and alert chain. Below: what data the module collects, which permissions to give the application, how the interval, only_future_events and time_delay options work, how the built-in rules in the 99500-99700 range rate severity, and how to raise the level of high-severity incidents with a custom rule.

The Wazuh documentation and Microsoft Learn call the product Microsoft 365 Defender, and the Wazuh module also covers Entra ID Protection and Intune. Identifiers, secrets and custom rule IDs in the examples are synthetic.

What the module collects

Every query is GET https://graph.microsoft.com/{version}/{resource}/{relationship}?{query-parameters}. In the configuration you give a resource (name) and one or more relationship values. The documentation lists the following combinations.

ResourceRelationshipContent
securityalertsOlder alert type from Azure and Microsoft 365 Defender security providers
securityalerts_v2Enriched version of alerts, with extra information and related alert collections
securityincidentsCorrelated alerts and data that make up the attack story
securitysecureScoresDaily security score at tenant and control level
securitycases/eDiscoveryCasesCustodians, searches and review sets from Purview eDiscovery Premium
identityProtectionriskDetectionsUser risk and sign-in risk detections from Entra ID
deviceManagementauditEvents, managedDevices, detectedAppsAudit log, devices and applications from Intune

The documentation treats the security resource as mature, because it was tested with the ready-made rules. Other resources can be ingested, but the built-in rule file covers only security, deviceManagement and identityProtection. The reference example also uses auditLogs with the signIns relationship, for which this file has no built-in rules.

Alerts and incidents are two different objects. An incident groups alerts with the same attack technique or from the same attacker. The sample incident from Microsoft Learn has the fields status, classification, determination, severity, assignedTo and priorityScore. The Wazuh documentation shows an alerts_v2 alert with the fields category, serviceSource and mitreTechniques.

Entra ID application and permissions

Wazuh authenticates as a registered application, so you need three values: tenant_id, client_id and secret_value. The procedure from the documentation:

  1. Register an application and note the Application (client) ID and the Directory (tenant) ID.
  2. Under Certificates & secrets choose New client secret and copy the secret value right away. The interface will not show it again.
  3. Under API permissions choose Microsoft Graph, then Application permissions, and add the permissions from the table.
  4. An administrator account gives Grant admin consent for the tenant.
DataEndpointApplication permission
Alerts/security/alerts_v2SecurityAlert.Read.All
Incidents/security/incidentsSecurityIncident.Read.All
Intune auditdeviceManagement/auditEventsDeviceManagementApps.Read.All

Microsoft Learn names SecurityAlert.Read.All and SecurityIncident.Read.All as the least privileged permissions for these methods. The ReadWrite.All variants are higher permissions and are not needed for reading alone. Both methods support the OData parameters $count, $filter, $skip and $top (for incidents also $expand) and paging through @odata.nextLink.

Configuration in ossec.conf

The block goes into /var/ossec/etc/ossec.conf on the manager or agent. The configuration below pulls alerts_v2 alerts and incidents every 5 minutes.

<ms-graph>
  <enabled>yes</enabled>
  <only_future_events>yes</only_future_events>
  <run_on_start>yes</run_on_start>
  <interval>5m</interval>
  <time_delay>30s</time_delay>
  <page_size>50</page_size>
  <curl_max_size>10M</curl_max_size>
  <version>v1.0</version>
  <api_auth>
    <tenant_id>example-tenant-id</tenant_id>
    <client_id>example-client-id</client_id>
    <secret_value>example-secret-value</secret_value>
    <api_type>global</api_type>
  </api_auth>
  <resource>
    <name>security</name>
    <relationship>alerts_v2</relationship>
    <relationship>incidents</relationship>
  </resource>
</ms-graph>

After the change, restart the matching service: systemctl restart wazuh-manager on the server or systemctl restart wazuh-agent on the agent.

OptionDefaultAllowed values and meaning
enabledyesyes, no
only_future_eventsyesyes, no; collects events from the module start
interval1dNumber with suffix s, m, h, d; wait time between scans
curl_max_size1MMaximum API response size, suffixes b, k, m, g, minimum 1K
page_size50From 1 to 50 items per page in each request
time_delay30sValue from 0, suffixes s, m, h, d, w
run_on_startyesyes, no; forces a run at start
versionv1.0v1.0, beta; the documentation recommends v1.0 for production
api_auth\api_typenoneglobal, gcc-high, dod; global means a commercial tenant or GCC

Configuration pitfalls

  • Interval and first scan. With the default 1d, scans are a day apart, so a new alert can wait up to 24 hours to be pulled. After Wazuh starts, the module waits a full interval before the first scan, unless run_on_start is yes. That option is on by default, so the first scan starts right away. The documentation example uses 5m.
  • only_future_events. With yes, the module collects only events from the start. The first scan begins time_delay before the start, so events older by that much are included too. By default the module will not pull history from before the deployment.
  • Response size. The default curl_max_size is 1 MB. The documentation does not describe the behavior when the limit is exceeded, and the configuration examples use 10M. With many incidents, tune page_size and curl_max_size together.
  • One instance. The module runs on Windows, Linux and macOS. The documentation recommends enabling it on one manager or agent, so logs are not duplicated.
  • Multiple tenants. Add another api_auth block inside one <ms-graph>, one per tenant. The module queries every configured resource for every tenant, and alerts from all tenants carry the name of the manager or agent the module runs on. After a restart, ossec.log contains a Scanning tenant '<TENANT_ID>' line for each tenant. resource blocks can also be repeated.
  • Bad credentials vs a bad block. Invalid credentials end in a warning at the access token request. A badly built block, for example api_auth without client_id, makes wazuh-modulesd log an error and stop with a configuration error. After a change, check ossec.log, because the token warning does not stop the process and is easy to miss.
  • Secret in the file. You write secret_value straight into ossec.conf, as in the documentation example. Restrict the file permissions and do not copy it into repositories (recommendation).

The Azure module (<wodle name="azure-logs"> with a <graph> section) also reads Graph endpoints, for example auditLogs/directoryAudits, but it is a separate module with its own configuration and credentials file. This post covers only <ms-graph>.

How the built-in rules rate events

The file 0995-microsoft-graph_rules.xml (tag v4.14.11, ID range 99500-99700) works on events recognized by the json-msgraph decoder. The decoder from 0006-json_decoders.xml catches the prematch "integration":"ms-graph" and discards fields with a null value (json_null_field = discard). The rules refer to ms-graph.* fields, for example ms-graph.severity and ms-graph.relationship.

RuleLevelCondition
995000Decoder json-msgraph, integration equal to ms-graph
995013Relationship alerts or alerts_v2
995023Relationship incidents
995036Child of 99501 and 99502: status other than resolved and classification other than falsePositive
99516, 995176Children of 99503: severity equal to informational, low
9951812Child of 99503: severity equal to medium
9951915Child of 99503: severity equal to high
99611, 9961215Children of 99503: determination equal to multiStagedAttack, compromisedAccount
996313Classification falsePositive
996333Status resolved

Below the severity rules sit the category rules (99521-99595, separate for informational, low, medium and high), and below rule 99503 the rules with the determination field (99606-99619). For high, all category rules have level 14 or 15. Rules 99506-99511 (level 4) detect the value unknownFutureValue and, according to their description, point to a logging configuration error. For Intune there are rules 99651-99654, and for Identity Protection 99656-99658, all at level 3.

Two consequences follow directly from the condition of rule 99503. An alert with status resolved ends as 99633 at level 3, as in the documentation example (a Defender for Office 365 alert with informational severity). Level 3 is the default log_alert_level threshold, covered in the post on rule levels. An active incident with high severity gets 15, and a resolved one only 3.

The files from tags v4.14.0 and v4.14.11 differ. In v4.14.0 the falsePositive condition in rule 99503 uses the ms-graph.classification field, in v4.14.11 a PCRE2 expression, and some rules carry MITRE tactic identifiers (TA0011) where the newer file has techniques (T1071). Check the file from the installed version. Events below the log_alert_level threshold are not alerts, but with logall enabled they land in the archives, as the post on archives and alerts describes.

A custom rule for high-severity incidents

The built-in rule 99519 gives level 15 to both single alerts and incidents. Level 16 is the highest severity in the Wazuh classification: no default rule uses it, and it is meant for custom rules. Recommendation: separate incidents (correlated alerts) from single alerts, and keep level 16 for incidents that are still open.

<group name="ms-graph,">
  <rule id="100520" level="16">
    <if_sid>99519</if_sid>
    <field name="ms-graph.relationship">incidents</field>
    <description>MS Graph: high severity Defender incident is not resolved.</description>
  </rule>
</group>

The rule is a child of 99519, so it fires only when the event has ms-graph.severity equal to high, a status other than resolved and a classification other than falsePositive. The ms-graph.relationship field is also checked by the built-in rules 99501, 99502 and 99652. ID 100520 falls in the 100000-120000 range reserved for custom rules. Put the file in /var/ossec/etc/rules/ (the loading rules are described in the post on rule loading).

Before restarting the manager, check the rule in wazuh-logtest (post on logtest). Paste a JSON event with "integration":"ms-graph" and fields nested under ms-graph, and phase 3 should show rule 100520 at level 16. The documentation does not give the raw form of the event passed to analysis, so build it from a previously saved alert. An alert at level 16 meets every level threshold in the integration filter, as the post on the integrator describes.

What the documentation does not specify

  • Module behavior under request throttling (HTTP 429) and when curl_max_size is exceeded.
  • The raw JSON event form passed to analysis (the documentation shows only the decoded alert).
  • How the access token is renewed and how an expiring application secret is handled.
  • Whether an alert with a changed status is sent again and how Wazuh deduplicates such events.
  • The relation between only_future_events, interval and the createdDateTime and lastUpdateDateTime fields of Graph objects.
  • serviceSource values other than microsoftDefenderForOffice365 from the example.
  • Defender XDR naming: in the sources the product is called Microsoft 365 Defender.

Sources

↑↓ select Enter open Esc close