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 secret value from Secrets Manager using the GetSecretValue or BatchGetSecretValue actions. 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"
  5updated_date = "2024/07/23"
  6
  7[rule]
  8author = ["Nick Jones", "Elastic"]
  9description = """
 10An adversary with access to a compromised AWS service such as an EC2 instance, Lambda function, or other service may
 11attempt to leverage the compromised service to access secrets in AWS Secrets Manager. This rule looks for the first time
 12a specific user identity has programmatically retrieved a secret value from Secrets Manager using the `GetSecretValue`
 13or `BatchGetSecretValue` actions. This rule assumes that AWS services such as Lambda functions and EC2 instances are
 14setup with IAM role's assigned that have the necessary permissions to access the secrets in Secrets Manager. An
 15adversary with access to a compromised AWS service such as an EC2 instance, Lambda function, or other service would rely
 16on the compromised service's IAM role to access the secrets in Secrets Manager.
 17"""
 18false_positives = [
 19    """
 20    Verify whether the user identity, user agent, and/or hostname should be using GetSecretString API for the specified
 21    SecretId. If known behavior is causing false positives, it can be exempted from the rule.
 22    """,
 23]
 24from = "now-60m"
 25index = ["filebeat-*", "logs-aws.cloudtrail-*"]
 26interval = "10m"
 27language = "kuery"
 28license = "Elastic License v2"
 29name = "First Time Seen AWS Secret Value Accessed in Secrets Manager"
 30note = """## Triage and analysis
 31
 32### Investigating First Time Seen AWS Secret Value Accessed in Secrets Manager
 33
 34AWS 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.
 35
 36This 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.
 37
 38#### Possible investigation steps
 39
 40- Identify the account and its role in the environment, and inspect the related policy.
 41- Identify the applications that should use this account.
 42- Investigate other alerts associated with the user account during the past 48 hours.
 43- 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.
 44- Assess whether this behavior is prevalent in the environment by looking for similar occurrences involving other users.
 45- Contact the account owner and confirm whether they are aware of this activity.
 46- Considering the source IP address and geolocation of the user who issued the command:
 47    - Do they look normal for the calling user?
 48    - 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?
 49    - 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?
 50- Review IAM permission policies for the user identity and specific secrets accessed.
 51- Examine the request parameters. These might indicate the source of the program or the nature of its tasks.
 52- 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.
 53
 54### False positive analysis
 55
 56- 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.
 57
 58### Response and remediation
 59
 60- Initiate the incident response process based on the outcome of the triage.
 61- Disable or limit the account during the investigation and response.
 62- Identify the possible impact of the incident and prioritize accordingly; the following actions can help you gain context:
 63    - Identify the account role in the cloud environment.
 64    - Assess the criticality of affected services and servers.
 65    - Work with your IT team to identify and minimize the impact on users.
 66    - Identify if the attacker is moving laterally and compromising other accounts, servers, or services.
 67    - Identify any regulatory or legal ramifications related to this activity.
 68- 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.
 69- Check if unauthorized new users were created, remove unauthorized new accounts, and request password resets for other IAM users.
 70- Consider enabling multi-factor authentication for users.
 71- Review the permissions assigned to the implicated user to ensure that the least privilege principle is being followed.
 72- Implement security best practices [outlined](https://aws.amazon.com/premiumsupport/knowledge-center/security-best-practices/) by AWS.
 73- Take the actions needed to return affected systems, data, or services to their normal operational levels.
 74- Identify the initial vector abused by the attacker and take action to prevent reinfection via the same vector.
 75- 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).
 76"""
 77references = [
 78    "https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html",
 79    "https://detectioninthe.cloud/ttps/credential_access/access_secret_in_secrets_manager/",
 80    "https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_BatchGetSecretValue.html",
 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    "Data Source: AWS Secrets Manager",
 91    "Tactic: Credential Access",
 92    "Resources: Investigation Guide",
 93]
 94timestamp_override = "event.ingested"
 95type = "new_terms"
 96
 97query = '''
 98event.dataset:aws.cloudtrail and event.provider:secretsmanager.amazonaws.com and
 99    event.action: (GetSecretValue or BatchGetSecretValue) and event.outcome:success and
100    not user_agent.name: ("Chrome" or "Firefox" or "Safari" or "Edge" or "Brave" or "Opera")
101'''
102
103
104[[rule.threat]]
105framework = "MITRE ATT&CK"
106[[rule.threat.technique]]
107id = "T1555"
108name = "Credentials from Password Stores"
109reference = "https://attack.mitre.org/techniques/T1555/"
110[[rule.threat.technique.subtechnique]]
111id = "T1555.006"
112name = "Cloud Secrets Management Stores"
113reference = "https://attack.mitre.org/techniques/T1555/006/"
114
115
116
117[rule.threat.tactic]
118id = "TA0006"
119name = "Credential Access"
120reference = "https://attack.mitre.org/tactics/TA0006/"
121
122[rule.new_terms]
123field = "new_terms_fields"
124value = ["user.id"]
125[[rule.new_terms.history_window_start]]
126field = "history_window_start"
127value = "now-10d"

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).

References

Related rules

to-top