Detecting Rogue Service Principal Secrets & Certificate Additions in Entra Logs
Rather than registering an obvious brand-new rogue app, sophisticated intruders append a second client secret or X.509 certificate onto an existing high-privilege Entra Enterprise Application or App Registration—emitting "Add service principal credentials" or "Update application – Certificates and secrets management". AuditVane rule AV-005 flags every credential addition.
Detection Objective & Threat Scope
Creating a new malicious App Registration named "BackdoorSync" triggers immediate scrutiny from SIEM rules and enterprise application inventories. Advanced adversaries skip creating new apps altogether and instead target an existing, fully authorized internal automation app—such as an HR sync connector or Microsoft 365 backup tool that already holds `Mail.ReadWrite` or `Directory.ReadWrite.All`.
Because Microsoft Entra ID allows an application object or service principal to carry multiple simultaneous active `PasswordCredentials` (client secrets) and `KeyCredentials` (X.509 certificates), adding a second 24-month secret breaks zero production workflows and grants the attacker silent, passwordless daemon API access.
Monitor Entra Directory Audit logs and Purview RecordType 8 closely for `Add service principal credentials`, `Update application - Certificates and secrets management`, and `Update service principal`. Inside `ModifiedProperties`, inspect `KeyDescription`, `KeyType` (`Password` vs. `AsymmetricX509Cert`), `KeyUsage`, and `KeyIdentifier` (thumbprint/GUID).
Crucially, attackers don’t need Global Administrator to plant this backdoor: Application Administrator, Cloud Application Administrator, or simply being listed as an **Owner** of a powerful App Registration suffices!
Forensic Telemetry Fields & High-Signal Indicators
| Telemetry Field / Pattern | Meaning in M365 / Entra | High-Signal Threat Indicator |
|---|---|---|
Add service principal credentials | Client secret or cert added onto Service Principal | Flagged High by AuditVane AV-005; check KeyId |
Update application - Certificates and secrets | Secret/cert added onto App Registration | Very rare outside scheduled CI secret rotation |
KeyType = AsymmetricX509Cert | Public key certificate uploaded for app-only auth | Allows silent certificate-signed JWT assertion logins |
KeyType = Password | New client secret generated | Verify change ticket with listed Application Owner |
Add owner to application / service principal | Attacker added themselves as app owner | Precursor enabling future secret injection |
Service Principal Sign-Ins | Daemon client_credentials token acquisitions | Spot anomalous external IPs using the AppId |
Sweep Multi-Secret Apps & Audit Credential Additions via Graph
Connect-MgGraph -Scopes "Application.Read.All","AuditLog.Read.All"
# 1. List App Registrations carrying multiple active secrets or certificates:
Get-MgApplication -All | Where-Object { $_.PasswordCredentials.Count -gt 1 -or $_.KeyCredentials.Count -gt 1 } |
Select-Object DisplayName, AppId, @{N="Secrets";E={$_.PasswordCredentials.Count}}, @{N="Certs";E={$_.KeyCredentials.Count}}
# 2. Inspect exact secret creation timestamps & display names on a target app:
(Get-MgApplication -Filter "displayName eq 'HR-Workday-Connector'").PasswordCredentials | Format-Table DisplayName, KeyId, StartDateTime, EndDateTime
Sample Multi-Secret Anomaly Output
DisplayName StartDateTime EndDateTime KeyId
----------- ------------- ----------- -----
Prod-Workday-Key 2026-01-10T00:00:00Z 2027-01-10T00:00:00Z 1111aaaa-2222-bbbb-3333-cccc4444dddd
ci-temp-key 2026-12-02T14:22:00Z 2028-12-02T14:22:00Z 9999ffff-8888-eeee-7777-dddd6666cccc <-- ROGUE
New Rogue App vs. Secret Injection on Existing Trusted App
| Technique | Visibility in Enterprise Apps List | Key Detection Signal |
|---|---|---|
| Create Brand-New Malicious App | High — new unverified displayName stands out | Add application + Consent to application |
| Inject Secret/Cert on Existing App | Stealthy — existing trusted vendor/internal name unchanged | Add service principal credentials / Update application - Certificates and secrets |
Service Principal Credential Backdoor Event in Entra Audit JSON
{
"activityDateTime": "2026-12-02T14:22:00Z",
"activityDisplayName": "Add service principal credentials",
"category": "ApplicationManagement",
"initiatedBy": { "user": { "userPrincipalName": "devops.lead@contoso-demo.invalid", "ipAddress": "185.220.101.45" } },
"targetResources": [{
"displayName": "HR-Workday-Connector",
"id": "sp-object-id-9912",
"modifiedProperties": [{ "displayName": "KeyDescription", "newValue": "[KeyIdentifier=9999ffff...,KeyType=Password,KeyUsage=Verify]" }]
}]
}
Notice `KeyIdentifier` inside `ModifiedProperties` identifies the exact `KeyId` added (`9999ffff...`) so engineers can surgically remove the malicious secret without breaking `Prod-Workday-Key` during business hours.
Real-World Incident Walkthrough
An attacker compromises a DevOps engineer who was left listed as an Owner on a legacy `HR-Workday-Connector` App Registration holding `User.ReadWrite.All` and `Mail.Read` app roles. The attacker runs a single Graph API call adding a new client secret named `ci-temp-key` valid for two years.
HR sync continues working uninterrupted, yet the attacker uses that client secret with `client_credentials` OAuth flow from a foreign VPS to query employee data—caught only when the SOC sweeps Entra logs in AuditVane (`AV-005`) and checks `ServicePrincipalSignInLogs` for unexpected source IPs.
Step-by-Step Triage, Containment & Verification
- Load Entra Directory Audit JSON and Purview UAL CSV into AuditVane and inspect all AV-005 findings.
- Verify every `Add service principal credentials` and `Update application - Certificates and secrets` event against CI/CD rotation tickets.
- Run the PowerShell sweep above across ALL App Registrations and Enterprise Service Principals holding multiple secrets/certificates.
- Audit `Add owner to application` and `Add owner to service principal` events to catch owner-level privilege escalation.
- Remove unrecognized `KeyId` credentials via `Remove-MgApplicationPassword` / `Remove-MgServicePrincipalPassword` and check `Service Principal Sign-Ins` for that `AppId`.
- Enforce Entra App Governance / Credential Policies banning >1-year secrets and migrating internal apps to certificate or Federated Workload Identity credentials.
How to Verify Containment Completed Cleanly
- Unrecognized secrets and certificates removed by exact KeyId.
- Service Principal Sign-Ins for affected AppIds confirmed clean of foreign VPS IPs.
- App Registration Ownership restricted to dedicated engineering groups rather than individual accounts.
Analyst Blind Spots, Licensing Quirks & False Positives
Remember that secrets added directly onto the **Service Principal** object (`Add service principal credentials`) do NOT appear on the parent **App Registration** blade in Entra Portal! Always inspect both `Get-MgApplication` AND `Get-MgServicePrincipal` credentials during an audit.
If a rogue secret was added to a multi-tenant Microsoft-owned or SaaS vendor ServicePrincipal, verify via `Get-MgServicePrincipal -ServicePrincipalId <id>`.
Frequently Asked Questions
Does adding a second client secret disrupt the legitimate application?
No! That is precisely why attackers abuse it—the legitimate app continues authenticating smoothly with Key #1 while the attacker authenticates silently with Key #2.
Does Purview UAL log service principal credential additions?
Yes, RecordType 8 captures both Add service principal credentials and Update application certificate/secret updates inside Purview UAL.
How do I check if a rogue secret was actually used to access data?
Export Entra Service Principal Sign-In logs (`AADServicePrincipalSignInLogs`) filtered by that AppId and inspect source IP addresses.
Who can add secrets to an App Registration?
Global Admins, Application Administrators, Cloud Application Administrators, and any regular user listed as an Owner of that specific App Registration.