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