-
Notifications
You must be signed in to change notification settings - Fork 625
[Rule Tuning] December-January AWS Rule Tuning #4425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5e0e3ec
[Rule Tuning] AWS Monthly Rule Tunings
terrancedejesus 3cd6b54
Adding several more AWS tunings
terrancedejesus 76d5d11
toml lint
terrancedejesus 245a325
Merge branch 'main' into rule-tuning-aws-december-2024
terrancedejesus 0837f4a
updating patch version
terrancedejesus 5c3f33e
updating non-ecs type to boolean
terrancedejesus 62d9b50
fixed cloudtrail index
terrancedejesus 30a762a
Merge branch 'main' into rule-tuning-aws-december-2024
terrancedejesus c25b23e
Merge branch 'main' into rule-tuning-aws-december-2024
terrancedejesus 46b4ead
Merge branch 'main' into rule-tuning-aws-december-2024
terrancedejesus 96ee12d
Merge branch 'main' into rule-tuning-aws-december-2024
terrancedejesus 2713287
Merge branch 'main' into rule-tuning-aws-december-2024
terrancedejesus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
rules/integrations/aws/discovery_ec2_userdata_request_for_ec2_instance.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| [metadata] | ||
| creation_date = "2024/04/14" | ||
| integration = ["aws"] | ||
| maturity = "production" | ||
| updated_date = "2025/01/27" | ||
|
|
||
| [rule] | ||
| author = ["Elastic"] | ||
| description = """ | ||
| Identifies discovery request `DescribeInstanceAttribute` with the attribute userData and instanceId in AWS CloudTrail | ||
| logs. This may indicate an attempt to retrieve user data from an EC2 instance. Adversaries may use this information to | ||
| gather sensitive data from the instance such as hardcoded credentials or to identify potential vulnerabilities. This is | ||
| a [New Terms](https://www.elastic.co/guide/en/security/master/rules-ui-create.html#create-new-terms-rule) rule that | ||
| identifies when `aws.cloudtrail.user_identity.arn` requests the user data for a specific | ||
| `aws.cloudtrail.flattened.request_parameters.instanceId` from an EC2 instance in the last 14 days. | ||
| """ | ||
| from = "now-9m" | ||
| index = ["filebeat-*", "logs-aws.cloudtrail-*"] | ||
| language = "kuery" | ||
| license = "Elastic License v2" | ||
| name = "AWS EC2 User Data Retrieval for EC2 Instance" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a new rule, but renamed. logic adjusted and moved out of BBR. |
||
| note = """ | ||
| ## Triage and Analysis | ||
|
|
||
| ### Investigating AWS EC2 User Data Retrieval for EC2 Instance | ||
|
|
||
| This rule detects requests to retrieve the `userData` attribute of an EC2 instance using the `DescribeInstanceAttribute` API action. The `userData` field can contain sensitive information, such as hardcoded credentials or configuration scripts, that adversaries may exploit for further attacks. | ||
|
|
||
| #### Possible Investigation Steps | ||
|
|
||
| - **Identify the Target Instance**: | ||
| - **Instance ID**: Review the `aws.cloudtrail.flattened.request_parameters.instanceId` field to identify the EC2 instance targeted by the request. Confirm whether this instance should expose its `userData` and whether it is associated with sensitive workloads. | ||
| - **Analyze userData**: If possible, retrieve and inspect the `userData` field to identify sensitive information like hardcoded credentials or configuration scripts. | ||
|
|
||
| - **Review User Context**: | ||
| - **User Identity**: Inspect the `aws.cloudtrail.user_identity.arn` field to identify the user or role that executed the `DescribeInstanceAttribute` action. Investigate whether this user typically performs such actions. | ||
| - **Access Patterns**: Validate whether the user or role has the necessary permissions and whether the frequency of this action aligns with expected behavior. | ||
| - **Access Key ID**: Check the `aws.cloudtrail.user_identity.access_key_id` field to determine the key used to make the request as it may be compromised. | ||
|
|
||
| - **Analyze Request Details**: | ||
| - **Parameters**: Verify that the `attribute=userData` parameter was explicitly requested. This indicates intentional access to user data. | ||
| - **Source IP and Geolocation**: Check the `source.address` and `source.geo` fields to validate whether the request originated from a trusted location or network. Unexpected geolocations can indicate adversarial activity. | ||
|
|
||
| - **Review Source Tool**: | ||
| - **User Agent**: Inspect the `user_agent.original` field to determine the tool or client used (e.g., Terraform, AWS CLI). Legitimate automation tools may trigger this activity, but custom or unknown user agents may indicate malicious intent. | ||
|
|
||
| - **Check for Related Activity**: | ||
| - **IAM Changes**: Correlate this event with any IAM changes or temporary credential creation to identify potential privilege escalation attempts. | ||
| - **API Usage**: Look for other unusual API calls (e.g., `RunInstances`, `GetObject`, `AssumeRole`) by the same user or IP to detect lateral movement or data exfiltration attempts. | ||
|
|
||
| - **Validate Intent**: | ||
| - **Permissions and Justification**: Ensure that the user has the least privilege required to perform this action. Investigate whether there is a valid reason for accessing the `userData` field. | ||
|
|
||
| ### False Positive Analysis | ||
|
|
||
| - **Automation**: This event is often triggered by legitimate automation tools, such as Terraform or custom scripts, that require access to `userData` during instance initialization. | ||
| - **Maintenance Activity**: Verify whether this event aligns with expected administrative activities, such as debugging or instance configuration updates. | ||
|
|
||
| ### Response and Remediation | ||
|
|
||
| - **Revoke Excessive Permissions**: If unauthorized, immediately remove `DescribeInstanceAttribute` permissions from the user or role. | ||
| - **Quarantine the Target Instance**: If malicious behavior is confirmed, isolate the affected EC2 instance to limit further exposure. | ||
| - **Secure User Data**: | ||
| - Avoid storing sensitive information, such as credentials, in `userData`. Use AWS Secrets Manager or Parameter Store instead. | ||
| - Encrypt user data and ensure only authorized users can decrypt it. | ||
| - **Audit IAM Policies**: Regularly review IAM policies to ensure they adhere to the principle of least privilege. | ||
| - **Monitor and Detect**: Set up additional alerts for unexpected `DescribeInstanceAttribute` calls or other suspicious API activity. | ||
|
|
||
| ### Additional Information | ||
|
|
||
| For more details on managing EC2 user data securely, refer to the [AWS EC2 User Data Documentation](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html). | ||
| """ | ||
| references = [ | ||
| "https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstanceAttribute.html", | ||
| "https://hackingthe.cloud/aws/exploitation/local_ec2_priv_esc_through_user_data", | ||
| ] | ||
| risk_score = 47 | ||
| rule_id = "c1e79a70-fa6f-11ee-8bc8-f661ea17fbce" | ||
| severity = "medium" | ||
| tags = [ | ||
| "Domain: Cloud", | ||
| "Data Source: AWS", | ||
| "Data Source: Amazon Web Services", | ||
| "Data Source: Amazon EC2", | ||
| "Resources: Investigation Guide", | ||
| "Use Case: Log Auditing", | ||
| "Tactic: Discovery", | ||
| ] | ||
| timestamp_override = "event.ingested" | ||
| type = "new_terms" | ||
|
|
||
| query = ''' | ||
| event.dataset: "aws.cloudtrail" | ||
| and event.provider: "ec2.amazonaws.com" | ||
| and event.action: "DescribeInstanceAttribute" | ||
| and event.outcome: "success" | ||
| and aws.cloudtrail.request_parameters: (*attribute=userData* and *instanceId*) | ||
| and not aws.cloudtrail.user_identity.invoked_by: ( | ||
| "AWS Internal" or | ||
| "cloudformation.amazonaws.com" | ||
| ) | ||
| ''' | ||
|
|
||
|
|
||
| [[rule.threat]] | ||
| framework = "MITRE ATT&CK" | ||
| [[rule.threat.technique]] | ||
| id = "T1580" | ||
| name = "Cloud Infrastructure Discovery" | ||
| reference = "https://attack.mitre.org/techniques/T1580/" | ||
|
|
||
|
|
||
| [rule.threat.tactic] | ||
| id = "TA0007" | ||
| name = "Discovery" | ||
| reference = "https://attack.mitre.org/tactics/TA0007/" | ||
| [[rule.threat]] | ||
| framework = "MITRE ATT&CK" | ||
| [[rule.threat.technique]] | ||
| id = "T1552" | ||
| name = "Unsecured Credentials" | ||
| reference = "https://attack.mitre.org/techniques/T1552/" | ||
| [[rule.threat.technique.subtechnique]] | ||
| id = "T1552.005" | ||
| name = "Cloud Instance Metadata API" | ||
| reference = "https://attack.mitre.org/techniques/T1552/005/" | ||
|
|
||
|
|
||
|
|
||
| [rule.threat.tactic] | ||
| id = "TA0006" | ||
| name = "Credential Access" | ||
| reference = "https://attack.mitre.org/tactics/TA0006/" | ||
|
|
||
| [rule.new_terms] | ||
| field = "new_terms_fields" | ||
| value = ["aws.cloudtrail.user_identity.arn", "aws.cloudtrail.flattened.request_parameters.instanceId"] | ||
| [[rule.new_terms.history_window_start]] | ||
| field = "history_window_start" | ||
| value = "now-14d" | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that while this is a relatively small change, we note why we are unable to tune the rule at this time in the tuning meta. As a result, we want to encourage user's to add exceptions on
user.idto reduce FPs.