First Time Seen AWS Secret Value Accessed in Secrets Manager

An adversary with access to a compromised AWS service such as an EC2 instance, Lambda function, or other service may attempt to leverage the compromised service to access secrets in AWS Secrets Manager. This rule looks for the first time a specific user identity has programmatically retrieved a specific secret value from Secrets Manager using the GetSecretValue action.

This rule assumes that AWS services such as Lambda functions and EC2 instances are setup with IAM role's assigned that have the necessary permissions to access the secrets in Secrets Manager. An adversary with access to a compromised AWS service such as an EC2 instance, Lambda function, or other service would rely on the compromised service's IAM role to access the secrets in Secrets Manager.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2020/07/06"
  3integration = ["aws"]
  4maturity = "production"
  5min_stack_comments = "AWS integration breaking changes, bumping version to ^2.0.0"
  6min_stack_version = "8.9.0"
  7updated_date = "2024/04/14"
  8
  9[rule]
 10author = ["Nick Jones", "Elastic"]
 11description = """
 12An adversary with access to a compromised AWS service such as an EC2 instance, Lambda function, or other service may attempt to leverage the compromised service to access secrets in AWS Secrets Manager. This rule looks for the first time a specific user identity has programmatically retrieved a specific secret value from Secrets Manager using the `GetSecretValue` action.
 13
 14This rule assumes that AWS services such as Lambda functions and EC2 instances are setup with IAM role's assigned that have the necessary permissions to access the secrets in Secrets Manager. An adversary with access to a compromised AWS service such as an EC2 instance, Lambda function, or other service would rely on the compromised service's IAM role to access the secrets in Secrets Manager.
 15"""
 16false_positives = [
 17    """
 18    Verify whether the user identity, user agent, and/or hostname should be using GetSecretString API for the specified
 19    SecretId. If known behavior is causing false positives, it can be exempted from the rule.
 20    """,
 21]
 22from = "now-60m"
 23index = ["filebeat-*", "logs-aws.cloudtrail-*"]
 24interval = "10m"
 25language = "kuery"
 26license = "Elastic License v2"
 27name = "First Time Seen AWS Secret Value Accessed in Secrets Manager"
 28note = """## Triage and analysis
 29
 30### Investigating First Time Seen AWS Secret Value Accessed in Secrets Manager
 31
 32AWS Secrets Manager is a service that enables the replacement of hardcoded credentials in code, including passwords, with an API call to Secrets Manager to retrieve the secret programmatically.
 33
 34This rule looks for the retrieval of credentials using `GetSecretValue` action in Secrets Manager programmatically. This is a [New Terms](https://www.elastic.co/guide/en/security/master/rules-ui-create.html#create-new-terms-rule) rule indicating this is the first time a specific user identity has successfuly retrieved a specific secret value from Secrets Manager within the last 15 days.
 35
 36#### Possible investigation steps
 37
 38- Identify the account and its role in the environment, and inspect the related policy.
 39- Identify the applications that should use this account.
 40- Investigate other alerts associated with the user account during the past 48 hours.
 41- Investigate abnormal values in the `user_agent.original` field by comparing them with the intended and authorized usage and historical data. Suspicious user agent values include non-SDK, AWS CLI, custom user agents, etc.
 42- Assess whether this behavior is prevalent in the environment by looking for similar occurrences involving other users.
 43- Contact the account owner and confirm whether they are aware of this activity.
 44- Considering the source IP address and geolocation of the user who issued the command:
 45    - Do they look normal for the calling user?
 46    - If the source is an EC2 IP address, is it associated with an EC2 instance in one of your accounts or is the source IP from an EC2 instance that's not under your control?
 47    - If it is an authorized EC2 instance, is the activity associated with normal behavior for the instance role or roles? Are there any other alerts or signs of suspicious activity involving this instance?
 48- Review IAM permission policies for the user identity and specific secrets accessed.
 49- Examine the request parameters. These might indicate the source of the program or the nature of its tasks.
 50- 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.
 51
 52### False positive analysis
 53
 54- False positives may occur due to the intended usage of the service. Tuning is needed in order to have higher confidence. Consider adding exceptions — preferably with a combination of user agent and IP address conditions.
 55
 56### Response and remediation
 57
 58- Initiate the incident response process based on the outcome of the triage.
 59- Disable or limit the account during the investigation and response.
 60- Identify the possible impact of the incident and prioritize accordingly; the following actions can help you gain context:
 61    - Identify the account role in the cloud environment.
 62    - Assess the criticality of affected services and servers.
 63    - Work with your IT team to identify and minimize the impact on users.
 64    - Identify if the attacker is moving laterally and compromising other accounts, servers, or services.
 65    - Identify any regulatory or legal ramifications related to this activity.
 66- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Rotate secrets 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.
 67- Check if unauthorized new users were created, remove unauthorized new accounts, and request password resets for other IAM users.
 68- Consider enabling multi-factor authentication for users.
 69- Review the permissions assigned to the implicated user to ensure that the least privilege principle is being followed.
 70- Implement security best practices [outlined](https://aws.amazon.com/premiumsupport/knowledge-center/security-best-practices/) by AWS.
 71- Take the actions needed to return affected systems, data, or services to their normal operational levels.
 72- Identify the initial vector abused by the attacker and take action to prevent reinfection via the same vector.
 73- 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).
 74
 75## Setup
 76
 77The AWS Fleet integration, Filebeat module, or similarly structured data is required to be compatible with this rule."""
 78references = [
 79    "https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html",
 80    "https://detectioninthe.cloud/ttps/credential_access/access_secret_in_secrets_manager/",
 81    "https://cloud.hacktricks.xyz/pentesting-cloud/aws-security/aws-services/aws-secrets-manager-enum"
 82]
 83risk_score = 47
 84rule_id = "a00681e3-9ed6-447c-ab2c-be648821c622"
 85severity = "medium"
 86tags = [
 87    "Domain: Cloud",
 88    "Data Source: AWS",
 89    "Data Source: Amazon Web Services",
 90    "Tactic: Credential Access",
 91    "Resources: Investigation Guide",
 92]
 93timestamp_override = "event.ingested"
 94type = "new_terms"
 95
 96query = '''
 97event.dataset:aws.cloudtrail and event.provider:secretsmanager.amazonaws.com and
 98    event.action:GetSecretValue and event.outcome:success and aws.cloudtrail.user_identity.session_context.session_issuer.type: Role and
 99    not user_agent.name: ("Chrome" or "Firefox" or "Safari" or "Edge" or "Brave" or "Opera")
100'''
101
102
103[[rule.threat]]
104framework = "MITRE ATT&CK"
105[[rule.threat.technique]]
106id = "T1528"
107name = "Steal Application Access Token"
108reference = "https://attack.mitre.org/techniques/T1528/"
109
110
111[rule.threat.tactic]
112id = "TA0006"
113name = "Credential Access"
114reference = "https://attack.mitre.org/tactics/TA0006/"
115
116[rule.new_terms]
117field = "new_terms_fields"
118value = ["user.id", "aws.cloudtrail.request_parameters"]
119[[rule.new_terms.history_window_start]]
120field = "history_window_start"
121value = "now-15d"

Triage and analysis

Investigating First Time Seen AWS Secret Value Accessed in Secrets Manager

AWS Secrets Manager is a service that enables the replacement of hardcoded credentials in code, including passwords, with an API call to Secrets Manager to retrieve the secret programmatically.

This rule looks for the retrieval of credentials using GetSecretValue action in Secrets Manager programmatically. This is a New Terms rule indicating this is the first time a specific user identity has successfuly retrieved a specific secret value from Secrets Manager within the last 15 days.

Possible investigation steps

  • Identify the account and its role in the environment, and inspect the related policy.
  • Identify the applications that should use this account.
  • Investigate other alerts associated with the user account during the past 48 hours.
  • Investigate abnormal values in the user_agent.original field by comparing them with the intended and authorized usage and historical data. Suspicious user agent values include non-SDK, AWS CLI, custom user agents, etc.
  • Assess whether this behavior is prevalent in the environment by looking for similar occurrences involving other users.
  • Contact the account owner and confirm whether they are aware of this activity.
  • Considering the source IP address and geolocation of the user who issued the command:
    • Do they look normal for the calling user?
    • If the source is an EC2 IP address, is it associated with an EC2 instance in one of your accounts or is the source IP from an EC2 instance that's not under your control?
    • If it is an authorized EC2 instance, is the activity associated with normal behavior for the instance role or roles? Are there any other alerts or signs of suspicious activity involving this instance?
  • Review IAM permission policies for the user identity and specific secrets accessed.
  • Examine the request parameters. These might indicate the source of the program or the nature of its tasks.
  • 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

  • False positives may occur due to the intended usage of the service. Tuning is needed in order to have higher confidence. Consider adding exceptions — preferably with a combination of user agent and IP address 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. Rotate secrets 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.
  • Review the permissions assigned to the implicated user to ensure that the least privilege principle is being followed.
  • Implement security best practices outlined by AWS.
  • Take the actions needed to return affected systems, data, or services to their normal operational levels.
  • Identify 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 AWS Fleet integration, Filebeat module, or similarly structured data is required to be compatible with this rule.

References

Related rules

to-top