Skip to main content

Overview

This lab deploys detection and hunting capabilities for non-human identity (NHI) abuse in Microsoft Entra ID. Non-human identities โ€” service principals, managed identities, and app registrations โ€” outnumber human users 100:1 in most enterprise environments and are the fastest-growing attack surface in cloud security.

The lab maps detections to the OWASP Non-Human Identity Top 10 framework.

Prerequisites

  • Azure subscription with Microsoft Sentinel enabled on a Log Analytics workspace
  • Entra ID diagnostic settings sending AuditLogs, ServicePrincipalSignInLogs, and ManagedIdentitySignInLogs to the workspace
  • PowerShell 7.0+ with Azure CLI installed and authenticated
  • Roles required: Microsoft Sentinel Contributor, Security Reader (for test NHI creation: Application Administrator)

Quick Start

# Deploy analytics rules and workbook
./labs/nhi-hunting/scripts/Deploy-Lab.ps1 \
    -ResourceGroup "rg-sentinel-lab" \
    -WorkspaceName "law-sentinel-lab"

# Deploy with test NHIs for lab telemetry
./labs/nhi-hunting/scripts/Deploy-Lab.ps1 \
    -ResourceGroup "rg-sentinel-lab" \
    -WorkspaceName "law-sentinel-lab" \
    -CreateTestNHIs

# Generate test detections
./labs/nhi-hunting/scripts/Test-NHIDetections.ps1 \
    -TenantId "your-tenant-id"

What Gets Deployed

ResourceTypeOWASP NHI
LAB - Credential Added to Existing ApplicationAnalytics RuleNHI2, NHI7
LAB - Service Principal Sign-in from Anomalous IPAnalytics RuleNHI1, NHI2
LAB - NHI Granted High-Privilege Directory RoleAnalytics RuleNHI5
LAB - Dormant Service Principal ReactivationAnalytics RuleNHI1
NHI Posture DashboardWorkbookAll
7 hunting queriesKQL (manual)NHI1-NHI10

Test Scenarios (with -CreateTestNHIs)

ScenarioWhat HappensRule Triggered
Add credential to stale appNew secret added to lab-nhi-stale-abandoned-appCredential Added
SP sign-in from your IPOverprivileged SP authenticates from new IPAnomalous IP
Assign directory role to SPSecurity Reader assigned to lab-nhi-excessive-perms-appHigh-Privilege Role

Cost Estimate

  • Sentinel analytics rules: Included in existing Sentinel pricing (query cost)
  • Diagnostic logs: Entra ID sign-in and audit logs incur Log Analytics ingestion costs (~$2.76/GB)
  • Test NHIs: No cost (Entra ID app registrations are free)

Estimated additional cost: < $5/month for lab workloads.

Cleanup

# Remove test NHIs
az ad app list --filter "startswith(displayName,'lab-nhi-')" \
    --query '[].appId' -o tsv | \
    ForEach-Object { az ad app delete --id $_ }

# Analytics rules and workbook: delete from Sentinel portal

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