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.
| Resource | Relationship | Content |
|---|---|---|
security | alerts | Older alert type from Azure and Microsoft 365 Defender security providers |
security | alerts_v2 | Enriched version of alerts, with extra information and related alert collections |
security | incidents | Correlated alerts and data that make up the attack story |
security | secureScores | Daily security score at tenant and control level |
security | cases/eDiscoveryCases | Custodians, searches and review sets from Purview eDiscovery Premium |
identityProtection | riskDetections | User risk and sign-in risk detections from Entra ID |
deviceManagement | auditEvents, managedDevices, detectedApps | Audit 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:
- Register an application and note the Application (client) ID and the Directory (tenant) ID.
- Under Certificates & secrets choose New client secret and copy the secret value right away. The interface will not show it again.
- Under API permissions choose Microsoft Graph, then Application permissions, and add the permissions from the table.
- An administrator account gives Grant admin consent for the tenant.
| Data | Endpoint | Application permission |
|---|---|---|
| Alerts | /security/alerts_v2 | SecurityAlert.Read.All |
| Incidents | /security/incidents | SecurityIncident.Read.All |
| Intune audit | deviceManagement/auditEvents | DeviceManagementApps.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.
| Option | Default | Allowed values and meaning |
|---|---|---|
enabled | yes | yes, no |
only_future_events | yes | yes, no; collects events from the module start |
interval | 1d | Number with suffix s, m, h, d; wait time between scans |
curl_max_size | 1M | Maximum API response size, suffixes b, k, m, g, minimum 1K |
page_size | 50 | From 1 to 50 items per page in each request |
time_delay | 30s | Value from 0, suffixes s, m, h, d, w |
run_on_start | yes | yes, no; forces a run at start |
version | v1.0 | v1.0, beta; the documentation recommends v1.0 for production |
api_auth\api_type | none | global, 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 fullintervalbefore the first scan, unlessrun_on_startisyes. That option is on by default, so the first scan starts right away. The documentation example uses5m. only_future_events. Withyes, the module collects only events from the start. The first scan beginstime_delaybefore 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_sizeis 1 MB. The documentation does not describe the behavior when the limit is exceeded, and the configuration examples use10M. With many incidents, tunepage_sizeandcurl_max_sizetogether. - 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_authblock inside one<ms-graph>, one per tenant. The module queries every configuredresourcefor every tenant, and alerts from all tenants carry the name of the manager or agent the module runs on. After a restart,ossec.logcontains aScanning tenant '<TENANT_ID>'line for each tenant.resourceblocks 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_authwithoutclient_id, makeswazuh-modulesdlog an error and stop with a configuration error. After a change, checkossec.log, because the token warning does not stop the process and is easy to miss. - Secret in the file. You write
secret_valuestraight intoossec.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.
| Rule | Level | Condition |
|---|---|---|
| 99500 | 0 | Decoder json-msgraph, integration equal to ms-graph |
| 99501 | 3 | Relationship alerts or alerts_v2 |
| 99502 | 3 | Relationship incidents |
| 99503 | 6 | Child of 99501 and 99502: status other than resolved and classification other than falsePositive |
| 99516, 99517 | 6 | Children of 99503: severity equal to informational, low |
| 99518 | 12 | Child of 99503: severity equal to medium |
| 99519 | 15 | Child of 99503: severity equal to high |
| 99611, 99612 | 15 | Children of 99503: determination equal to multiStagedAttack, compromisedAccount |
| 99631 | 3 | Classification falsePositive |
| 99633 | 3 | Status 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_sizeis 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,intervaland thecreatedDateTimeandlastUpdateDateTimefields of Graph objects. serviceSourcevalues other thanmicrosoftDefenderForOffice365from the example.- Defender XDR naming: in the sources the product is called Microsoft 365 Defender.
Sources
- https://documentation.wazuh.com/4.14/cloud-security/azure/monitoring-ms-graph.html
- https://documentation.wazuh.com/4.14/cloud-security/azure/ms-graph-api-setup.html
- https://documentation.wazuh.com/4.14/user-manual/reference/ossec-conf/ms-graph-module.html
- https://documentation.wazuh.com/4.14/cloud-security/azure/platform-and-services/graph.html
- https://learn.microsoft.com/en-us/graph/api/security-list-alerts_v2?view=graph-rest-1.0
- https://learn.microsoft.com/en-us/graph/api/security-list-incidents?view=graph-rest-1.0
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.11/ruleset/rules/0995-microsoft-graph_rules.xml
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.11/ruleset/decoders/0006-json_decoders.xml
- https://documentation.wazuh.com/4.14/user-manual/reference/ossec-conf/alerts.html
- https://documentation.wazuh.com/4.14/user-manual/ruleset/rules/custom.html
- https://documentation.wazuh.com/4.14/user-manual/ruleset/rules/rules-classification.html