Microsoft Defender for Endpoint Executor¶
Category: Network and Vulnerability Scanners
Script: microsoft_defender.py
Integration: REST API (OAuth2 Client Credentials)
Faraday Plugin: Raw JSON (no plugin — generates Faraday JSON directly)
Website: https://www.microsoft.com/en-us/security/business/endpoint-security/microsoft-defender-endpoint
Description¶
Authenticates with Microsoft Defender for Endpoint via OAuth2 (client credentials flow), retrieves all managed machines, filters by a "last seen" time threshold, fetches vulnerabilities for each machine, and constructs Faraday JSON with CVE and CVSS v3 data.
Prerequisites¶
- Microsoft Defender for Endpoint license (E5 or standalone)
- Azure AD application registration with the following API permissions:
Machine.Read.All— Read machine dataVulnerability.Read.All— Read vulnerability data- Azure AD Tenant ID, Client ID, and Client Secret
Configuration¶
Environment Variables (Setup)¶
| Variable | Required | Description |
|---|---|---|
TENANT_ID |
Yes | Azure Active Directory Tenant ID |
CLIENT_ID |
Yes | Azure AD Application (Client) ID |
CLIENT_SECRET |
Yes | Azure AD Application Client Secret |
Execution Arguments¶
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
DAYS_OLD |
string | Yes | Only include machines seen within this many days (integer > 0) |
Common Agent Parameters Supported¶
AGENT_CONFIG_VULN_TAG, AGENT_CONFIG_HOSTNAME_TAG
YAML Configuration Example¶
executors:
defender_scan:
repo_executor: microsoft_defender.py
max_size: 65536
varenvs:
TENANT_ID: "${AZURE_TENANT_ID}"
CLIENT_ID: "${AZURE_CLIENT_ID}"
CLIENT_SECRET: "${AZURE_CLIENT_SECRET}"
params:
DAYS_OLD:
mandatory: true
type: string
base: string
How It Works¶
- Authenticates via OAuth2 client credentials at
https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token - Retrieves all machines from
https://api.security.microsoft.com/api/machines - Filters machines by
lastSeendate, keeping only those seen within theDAYS_OLDthreshold - For each qualifying machine, fetches vulnerabilities from
https://api.security.microsoft.com/api/machines/{id}/vulnerabilities - Constructs Faraday JSON with host details (computer name, OS, IP) and vulnerability data (CVE ID, CVSS v3 score, description)
Setting Up Azure AD Permissions¶
- Go to Azure Portal > App registrations > New registration
- Create an application and note the Client ID and Tenant ID
- Under Certificates & secrets, create a new client secret
- Under API permissions, add:
Microsoft Threat Protection > Application > Machine.Read.AllMicrosoft Threat Protection > Application > Vulnerability.Read.All- Click Grant admin consent for your organization
Notes¶
- The executor uses rate limiting (40 requests/minute) via
requests_ratelimiterto comply with Microsoft API limits DAYS_OLDcontrols the recency filter — set to7for weekly imports,30for monthly- Only machines with a
lastSeentimestamp within the threshold are processed