AWS S3 Object Encryption Using External KMS Key
Identifies CopyObject
events within an S3 bucket using an AWS KMS key from an external account for encryption. Adversaries with access to a misconfigured S3 bucket and the proper permissions may encrypt objects with an external KMS key to deny their victims access to their own data.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2024/07/02"
3integration = ["aws"]
4maturity = "production"
5min_stack_comments = "ES|QL rule type in technical preview as of 8.13"
6min_stack_version = "8.13.0"
7updated_date = "2024/10/09"
8
9[rule]
10author = ["Elastic"]
11description = """
12Identifies `CopyObject` events within an S3 bucket using an AWS KMS key from an external account for encryption. Adversaries with access to a misconfigured S3 bucket and the proper permissions may encrypt objects with an external KMS key to deny their victims access to their own data.
13"""
14false_positives = [
15 """
16 Administrators within an AWS Organization structure may legitimately encrypt bucket objects with a key from an account different from the target bucket. Ensure that this behavior is not part of a legitimate operation before taking action.
17 """,
18]
19from = "now-9m"
20language = "esql"
21license = "Elastic License v2"
22name = "AWS S3 Object Encryption Using External KMS Key"
23note = """
24
25## Triage and Analysis
26
27### Investigating AWS S3 Object Encryption Using External KMS Key
28
29This rule detects the use of an external AWS KMS key to encrypt objects within an S3 bucket. Adversaries with access to a misconfigured S3 bucket may use an external key to copy objects within a bucket and deny victims the ability to access their own data.
30This rule uses [ES|QL](https://www.elastic.co/guide/en/security/master/rules-ui-create.html#create-esql-rule) to look for use of the `CopyObject` operation where the target bucket's `cloud.account.id` is different from the `key.account.id` dissected from the AWS KMS key used for encryption.
31
32#### Possible Investigation Steps:
33
34- **Identify the Actor**: Review the `aws.cloudtrail.user_identity.arn` and `aws.cloudtrail.user_identity.access_key_id` fields to identify who performed the action. Verify if this actor typically performs such actions and if they have the necessary permissions.
35- **Review the Request Details**: Examine the `aws.cloudtrail.request_parameters` to understand the specific details of the `CopyObject` action. Look for any unusual parameters that could suggest unauthorized or malicious modifications or usage of an unknown KMS keyId.
36- **Analyze the Source of the Request**: Investigate the `source.ip` and `source.geo` fields to determine the geographical origin of the request. An external or unexpected location might indicate compromised credentials or unauthorized access.
37- **Contextualize with Timestamp**: Use the `@timestamp` field to check when the object was copied. Changes during non-business hours or outside regular maintenance windows might require further scrutiny.
38- **Correlate with Other Activities**: Search for related CloudTrail events before and after this action to see if the same actor or IP address engaged in other potentially suspicious activities.
39- **Check for Object Deletion or Access**: Look for `DeleteObject`, `DeleteObjects`, or `GetObject` API calls to the same S3 bucket that may indicate the adversary accessing and destroying objects including older object versions.
40- **Interview Relevant Personnel**: If the copy event was initiated by a user, verify the intent and authorization for this action with the person or team responsible for managing S3 buckets.
41
42### False Positive Analysis:
43
44- **Legitimate Administrative Actions**: Confirm if the `CopyObject` action aligns with scheduled updates, maintenance activities, or legitimate administrative tasks documented in change management systems.
45- **Consistency Check**: Compare the action against historical data of similar activities performed by the user or within the organization. If the action is consistent with past legitimate activities, it might indicate a false alarm.
46
47### Response and Remediation:
48
49- **Immediate Review**: If the activity was unauthorized, search for potential ransom note placed in S3 bucket and review the bucket's access logs for any suspicious activity.
50- **Enhance Monitoring and Alerts**: Adjust monitoring systems to alert on similar `CopyObject` actions, especially those involving sensitive data or unusual file extensions.
51- **Educate and Train**: Provide additional training to users with administrative rights on the importance of security best practices concerning S3 bucket management and the risks of ransomware.
52- **Audit S3 Bucket Policies and Permissions**: Conduct a comprehensive audit of all S3 bucket policies and associated permissions to ensure they adhere to the principle of least privilege.
53- **Incident Response**: If there's an indication of malicious intent or a security breach, initiate the incident response protocol to mitigate any damage and prevent future occurrences.
54
55### Additional Information:
56
57For further guidance on managing S3 bucket security and protecting against ransomware, refer to the [AWS S3 documentation](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) and AWS best practices for security. Additionally, consult the following resources for specific details on S3 ransomware protection:
58- [ERMETIC REPORT - AWS S3 Ransomware Exposure in the Wild](https://s3.amazonaws.com/bizzabo.file.upload/PtZzA0eFQwV2RA5ysNeo_ERMETIC%20REPORT%20-%20AWS%20S3%20Ransomware%20Exposure%20in%20the%20Wild.pdf)
59- [S3 Ransomware Part 1: Attack Vector](https://rhinosecuritylabs.com/aws/s3-ransomware-part-1-attack-vector/)
60"""
61references = [
62 "https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingKMSEncryption.html/",
63 "https://docs.aws.amazon.com/kms/latest/APIReference/API_GenerateDataKey.html/",
64 "https://www.gem.security/post/cloud-ransomware-a-new-take-on-an-old-attack-pattern/",
65 "https://rhinosecuritylabs.com/aws/s3-ransomware-part-1-attack-vector/",
66]
67risk_score = 47
68rule_id = "ab8f074c-5565-4bc4-991c-d49770e19fc9"
69setup = "AWS S3 data event types need to be enabled in the CloudTrail trail configuration."
70severity = "medium"
71tags = [
72 "Domain: Cloud",
73 "Data Source: AWS",
74 "Data Source: Amazon Web Services",
75 "Data Source: AWS S3",
76 "Data Source: AWS KMS",
77 "Use Case: Threat Detection",
78 "Tactic: Impact",
79]
80timestamp_override = "event.ingested"
81type = "esql"
82
83query = '''
84from logs-aws.cloudtrail-* metadata _id, _version, _index
85
86// any successful copy event
87| where event.dataset == "aws.cloudtrail"
88 and event.provider == "s3.amazonaws.com"
89 and event.action == "CopyObject"
90 and event.outcome == "success"
91
92// abstract key account id, key id, encrypted object bucket name and object name
93| dissect aws.cloudtrail.request_parameters "{%{?bucketName}=%{target.bucketName},%{?x-amz-server-side-encryption-aws-kms-key-id}=%{?arn}:%{?aws}:%{?kms}:%{?region}:%{key.account.id}:%{?key}/%{keyId},%{?Host}=%{?tls.client.server_name},%{?x-amz-server-side-encryption}=%{?server-side-encryption},%{?x-amz-copy-source}=%{?bucket.objectName},%{?key}=%{target.objectName}}"
94
95// filter for s3 objects whose account id is different from the encryption key's account id
96// add exceptions based on key.account.id or keyId for known external accounts or encryption keys
97| where cloud.account.id != key.account.id
98
99// keep relevant fields
100| keep @timestamp, aws.cloudtrail.user_identity.arn, cloud.account.id, event.action, target.bucketName, key.account.id, keyId, target.objectName
101'''
102
103[[rule.threat]]
104framework = "MITRE ATT&CK"
105[[rule.threat.technique]]
106id = "T1486"
107name = "Data Encrypted for Impact"
108reference = "https://attack.mitre.org/techniques/T1486/"
109
110
111[rule.threat.tactic]
112id = "TA0040"
113name = "Impact"
114reference = "https://attack.mitre.org/tactics/TA0040/"
Triage and Analysis
Investigating AWS S3 Object Encryption Using External KMS Key
This rule detects the use of an external AWS KMS key to encrypt objects within an S3 bucket. Adversaries with access to a misconfigured S3 bucket may use an external key to copy objects within a bucket and deny victims the ability to access their own data.
This rule uses ES|QL to look for use of the CopyObject
operation where the target bucket's cloud.account.id
is different from the key.account.id
dissected from the AWS KMS key used for encryption.
Possible Investigation Steps:
- Identify the Actor: Review the
aws.cloudtrail.user_identity.arn
andaws.cloudtrail.user_identity.access_key_id
fields to identify who performed the action. Verify if this actor typically performs such actions and if they have the necessary permissions. - Review the Request Details: Examine the
aws.cloudtrail.request_parameters
to understand the specific details of theCopyObject
action. Look for any unusual parameters that could suggest unauthorized or malicious modifications or usage of an unknown KMS keyId. - Analyze the Source of the Request: Investigate the
source.ip
andsource.geo
fields to determine the geographical origin of the request. An external or unexpected location might indicate compromised credentials or unauthorized access. - Contextualize with Timestamp: Use the
@timestamp
field to check when the object was copied. Changes during non-business hours or outside regular maintenance windows might require further scrutiny. - Correlate with Other Activities: Search for related CloudTrail events before and after this action to see if the same actor or IP address engaged in other potentially suspicious activities.
- Check for Object Deletion or Access: Look for
DeleteObject
,DeleteObjects
, orGetObject
API calls to the same S3 bucket that may indicate the adversary accessing and destroying objects including older object versions. - Interview Relevant Personnel: If the copy event was initiated by a user, verify the intent and authorization for this action with the person or team responsible for managing S3 buckets.
False Positive Analysis:
- Legitimate Administrative Actions: Confirm if the
CopyObject
action aligns with scheduled updates, maintenance activities, or legitimate administrative tasks documented in change management systems. - Consistency Check: Compare the action against historical data of similar activities performed by the user or within the organization. If the action is consistent with past legitimate activities, it might indicate a false alarm.
Response and Remediation:
- Immediate Review: If the activity was unauthorized, search for potential ransom note placed in S3 bucket and review the bucket's access logs for any suspicious activity.
- Enhance Monitoring and Alerts: Adjust monitoring systems to alert on similar
CopyObject
actions, especially those involving sensitive data or unusual file extensions. - Educate and Train: Provide additional training to users with administrative rights on the importance of security best practices concerning S3 bucket management and the risks of ransomware.
- Audit S3 Bucket Policies and Permissions: Conduct a comprehensive audit of all S3 bucket policies and associated permissions to ensure they adhere to the principle of least privilege.
- Incident Response: If there's an indication of malicious intent or a security breach, initiate the incident response protocol to mitigate any damage and prevent future occurrences.
Additional Information:
For further guidance on managing S3 bucket security and protecting against ransomware, refer to the AWS S3 documentation and AWS best practices for security. Additionally, consult the following resources for specific details on S3 ransomware protection:
References
Related rules
- Potential AWS S3 Bucket Ransomware Note Uploaded
- AWS S3 Object Versioning Suspended
- AWS S3 Bucket Policy Added to Share with External Account
- AWS S3 Bucket Replicated to Another Account
- AWS RDS DB Instance or Cluster Deletion Protection Disabled