Skip to main content

OAuth Redirect Abuse Detection Lab

A hands-on lab deploying detection and hardening for OAuth redirect abuse โ€” the technique Microsoft warned about in their March 2026 advisory.

Cost: Uses existing Sentinel workspace (no additional resources) Cleanup: Delete analytics rules and workbook from Sentinel, remove CA policy from Entra

Blog Post: For detailed explanations of the attack technique and detection logic, see Detecting OAuth Redirect Abuse with Microsoft Sentinel and Entra ID.

GitHub: j-dahl7/oauth-redirect-abuse-sentinel


What Gets Deployed

ResourceTypeDetails
4 Analytics RulesSentinel ScheduledOAuth consent after risky sign-in, suspicious redirect URI, OAuth error patterns, bulk consent
1 WorkbookAzure WorkbookOAuth Security Dashboard (consent timeline, error patterns, URI changes, top apps)
1 CA PolicyEntra IDOptional report-only step-up policy for risky OAuth-related sign-ins
5 Hunting QueriesKQL filesDelegated permissions audit, non-corporate IPs, new high-priv apps, URI inventory, token replay
1 Audit ScriptPowerShellEnumerate all OAuth apps for suspicious redirect URIs and overprivileged permissions

Prerequisites

  • Azure subscription with an existing Microsoft Sentinel workspace
  • Azure CLI configured (az login)
  • PowerShell 7+ (pwsh)
  • Security Administrator or Sentinel Contributor role on the workspace
  • Conditional Access Administrator role (only if applying hardening with -ApplyHardening)
  • Application.Read.All Graph permission (for the OAuth audit, skip with -SkipAudit)

Quick Start

1. Clone the Repository

git clone https://github.com/j-dahl7/oauth-redirect-abuse-sentinel.git
cd oauth-redirect-abuse-sentinel

2. Deploy

./scripts/Deploy-Lab.ps1 -ResourceGroup "rg-sentinel-lab" -WorkspaceName "law-sentinel-lab"

Optional tenant hardening:

./scripts/Deploy-Lab.ps1 -ResourceGroup "rg-sentinel-lab" -WorkspaceName "law-sentinel-lab" -ApplyHardening

The script will:

  1. Verify the Sentinel workspace exists and Sentinel is enabled
  2. Deploy 4 scheduled analytics rules via the Sentinel REST API
  3. Deploy the OAuth Security Dashboard workbook
  4. Skip tenant hardening unless -ApplyHardening is present
  5. Run the OAuth app audit and save a CSV report

3. Verify Deployment

Open Microsoft Defender portal > Microsoft Sentinel > Analytics:

  • You should see 4 new rules prefixed with “LAB -”
  • All rules should show as Enabled with Scheduled type

Open Workbooks:

  • Find “OAuth Security Dashboard” in the list

Analytics Rules

Correlates SigninLogs risk indicators with AuditLogs consent events within a 15-minute window.

MITRE: T1566.002 (Spearphishing Link)

Rule 2: Suspicious OAuth Redirect URI Registered (Medium)

Watches for app registrations adding redirect URIs to tunneling services, free hosting, URL shorteners, or non-HTTPS endpoints.

MITRE: T1098 (Account Manipulation)

Rule 3: OAuth Error-Based Redirect Pattern (High)

Detects the Entra errors most closely associated with redirect abuse. The strongest signals are AADSTS65001 and AADSTS65004; additional OAuth failures are included as supporting context when they cluster around the same app and time window.

MITRE: T1566.002 (Spearphishing Link), T1204.001 (User Execution: Malicious Link)

Fires when 3+ users consent to the same app within 1 hour.

MITRE: T1566.002 (Spearphishing Link)


Hunting Queries

Import the queries from detection/hunting-queries.kql into Sentinel Hunting:

HuntPurposeLookback
1. Enumerate Delegated PermissionsBaseline audit of all user-granted permissions90 days
2. Non-Corporate IP Sign-insOAuth app auth from unexpected locations30 days
3. New High-Privilege AppsRecently registered apps with sensitive scopes14 days
4. Redirect URI InventoryFull audit trail of redirect URI changes90 days
5. Token Replay After ErrorError redirect followed by successful auth from different IP7 days

Hunt 2 requires customization โ€” replace the CorporateNetworks variable with your organization’s IP ranges.


Hardening Policies

The Set-OAuthHardening.ps1 script restricts user consent to:

  • Low-risk permissions only (e.g., User.Read, openid, profile)
  • Apps from verified publishers and trusted tenant-owned workflows
  • Everything else requires admin approval
  • Existing managePermissionGrantsForOwnedResource.* entries are preserved when the policy is updated

Conditional Access Policy

Creates a report-only lab CA policy that applies when:

  • Sign-in risk is Medium or High
  • Grant controls require MFA
  • Session sign-in frequency is set to Every time

Review the policy for 7 days before enforcing it.

OAuth App Audit

Run the audit independently:

./hardening/Audit-OAuthApps.ps1 -OutputPath "./oauth-audit-report.csv"

The audit checks every app registration for:

  • Suspicious redirect URI domains (ngrok, herokuapp, workers.dev, etc.)
  • Non-HTTPS redirect URIs (excluding localhost)
  • High-privilege delegated permissions (Mail.Read, Files.ReadWrite.All, etc.)
  • User-consented vs admin-consented permissions
  • Multi-tenant app registrations

Output is a CSV sorted by risk score.


File Structure

oauth-redirect-abuse-sentinel/
โ”œโ”€โ”€ README.md                             # Lab documentation
โ”œโ”€โ”€ detection/
โ”‚   โ”œโ”€โ”€ analytics-rules.kql            # 4 Sentinel analytics rules (full KQL)
โ”‚   โ””โ”€โ”€ hunting-queries.kql            # 5 proactive hunting queries
โ”œโ”€โ”€ hardening/
โ”‚   โ”œโ”€โ”€ Set-OAuthHardening.ps1         # Consent restriction + CA policy
โ”‚   โ””โ”€โ”€ Audit-OAuthApps.ps1            # OAuth app security audit
โ””โ”€โ”€ scripts/
    โ””โ”€โ”€ Deploy-Lab.ps1                 # Main deployment orchestrator

Cleanup

Remove Sentinel Resources

Delete the analytics rules from Microsoft Defender portal > Microsoft Sentinel > Analytics:

  • Select rules prefixed with “LAB -” and delete

Delete the workbook from Workbooks > “OAuth Security Dashboard”

Remove Hardening (if applied)

Revert consent policy: Restore the permissionGrantPoliciesAssigned collection you recorded before running the lab. Do not overwrite the collection with a single legacy value if your tenant already uses managePermissionGrantsForOwnedResource.* entries.

Delete CA policy:

az rest --method DELETE `
    --url 'https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies/<policy-id>'

Troubleshooting

Rules Don’t Fire

Analytics rules need matching data in SigninLogs and AuditLogs. If you don’t have OAuth consent events or risky sign-ins in your tenant, the rules will be silent. Test by:

  1. Registering a test app with a redirect URI containing webhook.site (triggers Rule 2)
  2. Checking that AuditLogs contains “Add application” events

Workbook Shows No Data

Ensure the workspace has AuditLogs and SigninLogs data connectors enabled. Check:

AuditLogs | take 1
SigninLogs | take 1

Hardening Script Fails

The hardening script requires Conditional Access Administrator and Policy.ReadWrite.ConditionalAccess Graph permission. Run with -WhatIf to preview changes:

./hardening/Set-OAuthHardening.ps1 -WhatIf

Resources

Keyboard Shortcuts

Navigation
Ctrl + K Open search / command palette
? Show this help
ESC Close dialogs
Actions
G then H Go to Home
G then B Go to Blog
G then A Go to About
G then C Go to Contact
G then T Go to Threat Feeds
G then G Go to Glossary
Shift + C Copy page URL
Easter Eggs
โ†‘โ†‘โ†“โ†“โ†โ†’โ†โ†’BA Konami code
Click cat 9ร— Nine lives activation
Click logo 9ร— Cat Burglar mode