Azure Service Principal Addition

Identifies when a new service principal is added in Azure. An application, hosted service, or automated tool that accesses or modifies resources needs an identity created. This identity is known as a service principal. For security reasons, it's always recommended to use service principals with automated tools rather than allowing them to log in with a user identity.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2020/12/14"
  3integration = ["azure"]
  4maturity = "production"
  5updated_date = "2024/05/21"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10Identifies when a new service principal is added in Azure. An application, hosted service, or automated tool that
 11accesses or modifies resources needs an identity created. This identity is known as a service principal. For security
 12reasons, it's always recommended to use service principals with automated tools rather than allowing them to log in with
 13a user identity.
 14"""
 15false_positives = [
 16    """
 17    A service principal may be created by a system or network administrator. Verify whether the username, hostname,
 18    and/or resource name should be making changes in your environment. Service principal additions from unfamiliar users
 19    or hosts should be investigated. If known behavior is causing false positives, it can be exempted from the rule.
 20    """,
 21]
 22from = "now-25m"
 23index = ["filebeat-*", "logs-azure*"]
 24language = "kuery"
 25license = "Elastic License v2"
 26name = "Azure Service Principal Addition"
 27note = """## Triage and analysis
 28
 29### Investigating Azure Service Principal Addition
 30
 31Service Principals are identities used by applications, services, and automation tools to access specific resources. They grant specific access based on the assigned API permissions. Most organizations that work a lot with Azure AD make use of service principals. Whenever an application is registered, it automatically creates an application object and a service principal in an Azure AD tenant.
 32
 33This rule looks for the addition of service principals. This behavior may enable attackers to impersonate legitimate service principals to camouflage their activities among noisy automations/apps.
 34
 35#### Possible investigation steps
 36
 37- Identify the user account that performed the action and whether it should perform this kind of action.
 38- Investigate other alerts associated with the user account during the past 48 hours.
 39- Consider the source IP address and geolocation for the user who issued the command. Do they look normal for the user?
 40- Consider the time of day. If the user is a human, not a program or script, did the activity take place during a normal time of day?
 41- Check if this operation was approved and performed according to the organization's change management policy.
 42- Contact the account owner and confirm whether they are aware of this activity.
 43- Examine the account's commands, API calls, and data management actions in the last 24 hours.
 44- If you suspect the account has been compromised, scope potentially compromised assets by tracking servers, services, and data accessed by the account in the last 24 hours.
 45
 46### False positive analysis
 47
 48If this rule is noisy in your environment due to expected activity, consider adding exceptions — preferably with a combination of user and device conditions.
 49
 50### Response and remediation
 51
 52- Initiate the incident response process based on the outcome of the triage.
 53- Disable or limit the account during the investigation and response.
 54- Identify the possible impact of the incident and prioritize accordingly; the following actions can help you gain context:
 55    - Identify the account role in the cloud environment.
 56    - Assess the criticality of affected services and servers.
 57    - Work with your IT team to identify and minimize the impact on users.
 58    - Identify if the attacker is moving laterally and compromising other accounts, servers, or services.
 59    - Identify any regulatory or legal ramifications related to this activity.
 60- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords or delete API keys as needed to revoke the attacker's access to the environment. Work with your IT teams to minimize the impact on business operations during these actions.
 61- Check if unauthorized new users were created, remove unauthorized new accounts, and request password resets for other IAM users.
 62- Consider enabling multi-factor authentication for users.
 63- Follow security best practices [outlined](https://docs.microsoft.com/en-us/azure/security/fundamentals/identity-management-best-practices) by Microsoft.
 64- Determine the initial vector abused by the attacker and take action to prevent reinfection via the same vector.
 65- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
 66
 67## Setup
 68
 69The Azure Fleet integration, Filebeat module, or similarly structured data is required to be compatible with this rule."""
 70references = [
 71    "https://msrc-blog.microsoft.com/2020/12/13/customer-guidance-on-recent-nation-state-cyber-attacks/",
 72    "https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal",
 73]
 74risk_score = 21
 75rule_id = "60b6b72f-0fbc-47e7-9895-9ba7627a8b50"
 76severity = "low"
 77tags = [
 78    "Domain: Cloud",
 79    "Data Source: Azure",
 80    "Use Case: Identity and Access Audit",
 81    "Resources: Investigation Guide",
 82    "Tactic: Defense Evasion",
 83]
 84timestamp_override = "event.ingested"
 85type = "query"
 86
 87query = '''
 88event.dataset:azure.auditlogs and azure.auditlogs.operation_name:"Add service principal" and event.outcome:(success or Success)
 89'''
 90
 91
 92[[rule.threat]]
 93framework = "MITRE ATT&CK"
 94[[rule.threat.technique]]
 95id = "T1550"
 96name = "Use Alternate Authentication Material"
 97reference = "https://attack.mitre.org/techniques/T1550/"
 98[[rule.threat.technique.subtechnique]]
 99id = "T1550.001"
100name = "Application Access Token"
101reference = "https://attack.mitre.org/techniques/T1550/001/"
102
103
104
105[rule.threat.tactic]
106id = "TA0005"
107name = "Defense Evasion"
108reference = "https://attack.mitre.org/tactics/TA0005/"

Triage and analysis

Investigating Azure Service Principal Addition

Service Principals are identities used by applications, services, and automation tools to access specific resources. They grant specific access based on the assigned API permissions. Most organizations that work a lot with Azure AD make use of service principals. Whenever an application is registered, it automatically creates an application object and a service principal in an Azure AD tenant.

This rule looks for the addition of service principals. This behavior may enable attackers to impersonate legitimate service principals to camouflage their activities among noisy automations/apps.

Possible investigation steps

  • Identify the user account that performed the action and whether it should perform this kind of action.
  • Investigate other alerts associated with the user account during the past 48 hours.
  • Consider the source IP address and geolocation for the user who issued the command. Do they look normal for the user?
  • Consider the time of day. If the user is a human, not a program or script, did the activity take place during a normal time of day?
  • Check if this operation was approved and performed according to the organization's change management policy.
  • Contact the account owner and confirm whether they are aware of this activity.
  • Examine the account's commands, API calls, and data management actions in the last 24 hours.
  • If you suspect the account has been compromised, scope potentially compromised assets by tracking servers, services, and data accessed by the account in the last 24 hours.

False positive analysis

If this rule is noisy in your environment due to expected activity, consider adding exceptions — preferably with a combination of user and device conditions.

Response and remediation

  • Initiate the incident response process based on the outcome of the triage.
  • Disable or limit the account during the investigation and response.
  • Identify the possible impact of the incident and prioritize accordingly; the following actions can help you gain context:
    • Identify the account role in the cloud environment.
    • Assess the criticality of affected services and servers.
    • Work with your IT team to identify and minimize the impact on users.
    • Identify if the attacker is moving laterally and compromising other accounts, servers, or services.
    • Identify any regulatory or legal ramifications related to this activity.
  • Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords or delete API keys as needed to revoke the attacker's access to the environment. Work with your IT teams to minimize the impact on business operations during these actions.
  • Check if unauthorized new users were created, remove unauthorized new accounts, and request password resets for other IAM users.
  • Consider enabling multi-factor authentication for users.
  • Follow security best practices outlined by Microsoft.
  • Determine the initial vector abused by the attacker and take action to prevent reinfection via the same vector.
  • Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).

Setup

The Azure Fleet integration, Filebeat module, or similarly structured data is required to be compatible with this rule.

References

Related rules

to-top