Skip to content

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 data
  • Vulnerability.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

  1. Authenticates via OAuth2 client credentials at https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token
  2. Retrieves all machines from https://api.security.microsoft.com/api/machines
  3. Filters machines by lastSeen date, keeping only those seen within the DAYS_OLD threshold
  4. For each qualifying machine, fetches vulnerabilities from https://api.security.microsoft.com/api/machines/{id}/vulnerabilities
  5. Constructs Faraday JSON with host details (computer name, OS, IP) and vulnerability data (CVE ID, CVSS v3 score, description)

Setting Up Azure AD Permissions

  1. Go to Azure Portal > App registrations > New registration
  2. Create an application and note the Client ID and Tenant ID
  3. Under Certificates & secrets, create a new client secret
  4. Under API permissions, add:
  5. Microsoft Threat Protection > Application > Machine.Read.All
  6. Microsoft Threat Protection > Application > Vulnerability.Read.All
  7. Click Grant admin consent for your organization

Notes

  • The executor uses rate limiting (40 requests/minute) via requests_ratelimiter to comply with Microsoft API limits
  • DAYS_OLD controls the recency filter — set to 7 for weekly imports, 30 for monthly
  • Only machines with a lastSeen timestamp within the threshold are processed