PIVTR-D
RAzure playbook · Identity and access

Stolen service principal credential used to change permissions

An attacker signs in as a service principal with a stolen client secret or certificate, adds a credential of their own, and grants the application roles or permissions. The attacker keeps access after you rotate the stolen secret if their added credential survives. Disable the service principal first, which keeps its credentials as evidence, then remove what the attacker added.

Look here

LogSearch for
AADServicePrincipalSignInLogsNew IP addresses for the app, and the credential each sign-in used. ServicePrincipalCredentialKeyId names the credential, and ServicePrincipalCredentialThumbprint names a certificate: AADServicePrincipalSignInLogs | where AppId == "<app-id>" | summarize count() by IPAddress, ServicePrincipalCredentialKeyId, ServicePrincipalCredentialThumbprint, ResourceDisplayName, ResultType
AuditLogs, credentialsSecrets and certificates added. Add service principal credentials covers the service principal. The app registration activity contains an en dash, so match it with has: Update application – Certificates and secrets management
AuditLogs, roles and ownersRoles, owners and consents added: Add member to role, Add eligible member to role, Add owner to application, Consent to application and Add app role assignment to service principal
AuditLogs, queryThese activities with their initiator and target: AuditLogs | where OperationName has_any ("Add service principal credentials", "Certificates and secrets management", "Add app role assignment to service principal", "Add member to role", "Add eligible member to role") | project TimeGenerated, OperationName, InitiatedBy, TargetResources
AzureActivityAzure role assignments and custom roles the app created, logged under Microsoft.Authorization as roleAssignments/write and roleDefinitions/write. Query the assignments: AzureActivity | where OperationNameValue =~ "Microsoft.Authorization/roleAssignments/write" | project TimeGenerated, Caller, CallerIpAddress, _ResourceId, Properties_d
MicrosoftGraphActivityLogsGraph calls by the app: MicrosoftGraphActivityLogs | where AppId == "<app-id>" | project TimeGenerated, IPAddress, RequestMethod, RequestUri, ResponseStatusCode
SecurityAlertDefender for Resource Manager alerts, by AlertType: ARM_AnomalousRBACRoleAssignment and ARM_AnomalousServiceOperation.CredentialAccess

Contain

#Item
1Record the app registration's secrets, then run the same command with --cert for its certificates: az ad app credential list --id <app-id>
2Record the service principal's secrets, then run the same command with --cert: az ad sp credential list --id <sp-object-id>
3Disable the service principal, which keeps its credentials and assignments as evidence: Update-MgServicePrincipal -ServicePrincipalId <sp-object-id> -AccountEnabled:$false
4Remove Azure role assignments added in the window: az role assignment delete --ids <assignment-id>
5Find the service principal's directory roles: Get-MgRoleManagementDirectoryRoleAssignment -Filter "principalId eq '<sp-object-id>'"
6Remove the directory roles the attacker added: Remove-MgRoleManagementDirectoryRoleAssignment -UnifiedRoleAssignmentId <id>
7Find the application permissions granted to it: Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId <sp-object-id>
8Remove the application permissions the attacker added: Remove-MgServicePrincipalAppRoleAssignment -ServicePrincipalId <sp-object-id> -AppRoleAssignmentId <id>
9Delete the attacker's credential on the app registration destructive, after recording. Add --cert for a certificate: az ad app credential delete --id <app-id> --key-id <key-id>
10Delete the attacker's credential on the service principal destructive, after recording. Add --cert for a certificate: az ad sp credential delete --id <sp-object-id> --key-id <key-id>

Eradicate and recover

#Item
1Search AuditLogs for credentials added to any other application in the window and remove unknown ones
2Remove owners added through Add owner to application or Add owner to service principal
3Issue one new credential to the workload's secret store: az ad app credential reset --id <app-id> --append
4Re-enable the service principal: Update-MgServicePrincipal -ServicePrincipalId <sp-object-id> -AccountEnabled:$true
5Block the service principal outside known IP ranges with a Conditional Access location policy (single-tenant apps, Workload Identities Premium license)
Watch out
  • az ad app credential reset without --append clears every existing secret and certificate on the app. Record them as evidence first.
  • An application and its service principal each have their own credentials. Check and clean both lists.
  • Disabling the service principal blocks new tokens only. Tokens already issued keep working for up to 90 minutes, so remove its role assignments too and keep watching its sign-ins.

Microsoft Learn: Entra audit log activity reference; AADServicePrincipalSignInLogs, AuditLogs, AzureActivity and MicrosoftGraphActivityLogs table references; access token lifetime; Conditional Access for workload identities; Azure CLI reference for az ad app credential and az ad sp credential; Microsoft Graph PowerShell reference for the cmdlets used. Checked October 2026. Defender for Cloud alerts for Resource Manager: checked October 2026.

Adapts material from Dynamic Incident Response: A Framework for Security Teams by Joshua Wright, © 2026 The Escal Institute of Advanced Technologies, Inc. d/b/a SANS Institute, licensed under CC BY 4.0. Figures reproduced under that license. Changes were made. Not published by, endorsed by, or affiliated with the SANS Institute.