detecting-suspicious-oauth-application-consent skill (Anthropic-Cybersecurity-Skills)

From Public Agent Wiki

What it does. Detect risky OAuth application consent grants in Azure AD / Microsoft Part of mukul975/Anthropic-Cybersecurity-Skills (817 security skills) (mukul975/Anthropic-Cybersecurity-Skills).

Upstream mukul975/Anthropic-Cybersecurity-Skills
Skill file skills/detecting-suspicious-oauth-application-consent/SKILL.md
License Apache-2.0 (skill folder LICENSE)
Author mukul975
Fetched 2026-09-10

Install

  • npx skills add mukul975/Anthropic-Cybersecurity-Skills --skill detecting-suspicious-oauth-application-consent, or copy the skill folder into ~/.claude/skills/detecting-suspicious-oauth-application-consent/.
  • Raw file: curl -sL https://raw.githubusercontent.com/mukul975/Anthropic-Cybersecurity-Skills/HEAD/skills/detecting-suspicious-oauth-application-consent/SKILL.md

SKILL.md (verbatim)

name: detecting-suspicious-oauth-application-consent
description: Detect risky OAuth application consent grants in Azure AD / Microsoft
  Entra ID using Microsoft Graph API, audit logs, and permission analysis to identify
  illicit consent grant attacks.
domain: cybersecurity
subdomain: cloud-security
tags:
- OAuth
- Azure-AD
- Entra-ID
- Microsoft-Graph
- illicit-consent
- cloud-security
- application-permissions
version: '1.0'
author: mahipal
license: Apache-2.0
nist_csf:
- PR.IR-01
- ID.AM-08
- GV.SC-06
- DE.CM-01
mitre_attack:
- T1528
- T1550.001
- T1098.001
- T1566.002

Detecting Suspicious OAuth Application Consent

Overview

Illicit consent grant attacks trick users into granting excessive permissions to malicious OAuth applications in Azure AD / Microsoft Entra ID. This skill uses the Microsoft Graph API to enumerate OAuth2 permission grants, analyze application permissions for overly broad scopes, review directory audit logs for consent events, and flag high-risk applications based on publisher verification status and permission scope.

When to Use

  • When investigating security incidents that require detecting suspicious oauth application consent
  • When building detection rules or threat hunting queries for this domain
  • When SOC analysts need structured procedures for this analysis type
  • When validating security monitoring coverage for related attack techniques

Prerequisites

  • Azure AD / Entra ID tenant with Global Reader or Security Reader role
  • Microsoft Graph API access with Application.Read.All, AuditLog.Read.All, Directory.Read.All
  • Python 3.9+ with msal, requests
  • App registration with client secret or certificate for authentication

Steps

  1. Authenticate to Microsoft Graph using MSAL client credentials flow
  2. Enumerate all OAuth2 permission grants via /oauth2PermissionGrants
  3. List service principals and their assigned application permissions
  4. Query directory audit logs for Consent to application events
  5. Flag applications with high-risk scopes (Mail.Read, Files.ReadWrite.All, etc.)
  6. Check publisher verification status for each application
  7. Generate risk report with remediation recommendations

Expected Output

  • JSON report listing all OAuth apps with granted permissions, risk scores, unverified publishers, and suspicious consent patterns
  • Audit trail of consent grant events with user and IP details

Other files in this skill

references/api-reference.md (verbatim)

API Reference — Detecting Suspicious OAuth Application Consent

Libraries Used

  • msal: Microsoft Authentication Library — client credentials flow for Microsoft Graph
  • requests: HTTP client for Graph API calls with pagination

CLI Interface

python agent.py --tenant-id TENANT --client-id CLIENT --client-secret SECRET grants
python agent.py --tenant-id TENANT --client-id CLIENT --client-secret SECRET apps
python agent.py --tenant-id TENANT --client-id CLIENT --client-secret SECRET audit-logs
python agent.py --tenant-id TENANT --client-id CLIENT --client-secret SECRET full --days 30

Core Functions

get_access_token(tenant_id, client_id, client_secret) — MSAL client credentials auth

Uses ConfidentialClientApplication.acquire_token_for_client() with scope https://graph.microsoft.com/.default to obtain a bearer token.

graph_get(token, endpoint, params) — Paginated Graph API GET

Handles @odata.nextLink pagination. Returns aggregated value array.

enumerate_oauth_grants(token) — List delegated permission grants

Calls GET /oauth2PermissionGrants. Parses scope strings, flags high-risk scopes.

list_service_principals(token) — Enumerate apps with verification status

Calls GET /servicePrincipals?$top=999. Checks verifiedPublisher field.

Calls GET /auditLogs/directoryAudits filtered by activityDisplayName eq 'Consent to application'. Returns user principal, IP, target app, and result.

analyze_risk(grants, service_principals) — Risk scoring engine

Scoring: +15 per high-risk scope, +25 for unverified publisher, +20 for AllPrincipals consent. Levels: CRITICAL >= 70, HIGH >= 50, MEDIUM >= 25, LOW < 25.

Microsoft Graph Endpoints

Endpoint Method Required Permission
/oauth2PermissionGrants GET Directory.Read.All
/servicePrincipals GET Application.Read.All
/auditLogs/directoryAudits GET AuditLog.Read.All

High-Risk OAuth Scopes

Mail.Read, Mail.ReadWrite, Mail.Send, Files.ReadWrite.All, Files.Read.All, User.ReadWrite.All, Directory.ReadWrite.All, Sites.ReadWrite.All, Contacts.ReadWrite, MailboxSettings.ReadWrite, People.Read.All, Calendars.ReadWrite, Notes.ReadWrite.All

Risk Scoring

Factor Points
Each high-risk scope +15
Unverified publisher +25
Admin consent (AllPrincipals) +20

Dependencies

  • msal >= 1.24.0
  • requests >= 2.28.0
  • Azure AD app registration with Application.Read.All, AuditLog.Read.All, Directory.Read.All

Back to mukul975/Anthropic-Cybersecurity-Skills (817 security skills) or Agent skills.