Skip to content

Commit 7ff2648

Browse files
authored
[Rule Tuning] SSM Session Started to EC2 Instance (#5068)
* [Rule Tuning] SSM Session Started to EC2 Instance Role/role session noise seen in telemetry due to new fields term using `aws.cloudtrail.user_identity.arn`, which is unique for each role session and does not isolate the role itself. - new fields term change to `cloud.account.id` and `user.name` combination to account for both IAMUsers and Roles across multiple accounts. - added AWS to the rule name - reduced execution window - small edits to description and IG - added reference from IG to Reference section * adding highlighted fields * added EC2 tag * Update lateral_movement_aws_ssm_start_session_to_ec2_instance.toml * Apply suggestions from code review
1 parent 76e083c commit 7ff2648

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

rules/integrations/aws/lateral_movement_aws_ssm_start_session_to_ec2_instance.toml

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,34 @@
22
creation_date = "2024/04/16"
33
integration = ["aws"]
44
maturity = "production"
5-
updated_date = "2025/01/15"
5+
updated_date = "2025/09/05"
66

77
[rule]
88
author = ["Elastic"]
99
description = """
10-
Identifies the first occurrence of an AWS resource establishing a session via SSM to an EC2 instance. Adversaries may
11-
use AWS Systems Manager to establish a session to an EC2 instance to execute commands on the instance. This can be used
12-
to gain access to the instance and perform actions such as privilege escalation. This rule helps detect the first
13-
occurrence of this activity for a given AWS resource.
10+
Identifies the first occurrence of an AWS user or role establishing a session via SSM to an EC2 instance. Adversaries may use AWS Session Manager to establish a session to an EC2 instance to execute commands on the instance. This can be used to gain access to the instance and perform actions such as privilege escalation.
1411
"""
15-
false_positives = ["Legitimate use of AWS Systems Manager to establish a session to an EC2 instance."]
16-
from = "now-60m"
12+
false_positives = ["Legitimate use of AWS Session Manager to establish a session to an EC2 instance."]
13+
from = "now-6m"
1714
index = ["filebeat-*", "logs-aws.cloudtrail-*"]
18-
interval = "10m"
1915
language = "kuery"
2016
license = "Elastic License v2"
21-
name = "SSM Session Started to EC2 Instance"
17+
name = "AWS SSM Session Started to EC2 Instance"
2218
note = """## Triage and analysis
2319
24-
### Investigating SSM Session Started to EC2 Instance
20+
### Investigating AWS SSM Session Started to EC2 Instance
2521
26-
This rule detects the first instance of an AWS resource initiating an SSM session to an EC2 instance, which could be indicative of legitimate administrative activities or potential malicious actions like command execution or lateral movement.
22+
This rule detects the first instance of an AWS user or role initiating an SSM session to an EC2 instance, which could be indicative of legitimate administrative activities or potential malicious actions like command execution or lateral movement.
2723
2824
#### Possible Investigation Steps
2925
3026
- **Examine the Session Start Event**: Review the AWS CloudTrail log for the event.
31-
- Look for the `StartSession` action and verify details such as the `user_identity.arn`, `event.action`, and the target EC2 instance (`aws.cloudtrail.flattened.request_parameters`).
27+
- Determine the target EC2 instance using `aws.cloudtrail.request_parameters`.
3228
- **Verify User Identity and Role**: Check the user’s ARN and access key ID (`aws.cloudtrail.user_identity.access_key_id`).
33-
- Cross-reference this with IAM to verify if the user had the necessary permissions and if their role typically requires initiating SSM sessions.
29+
- Determine if their role typically requires initiating SSM sessions.
3430
- **Assess Geographic and IP Context**: Analyze the source IP (`source.ip`) and geographic location (`source.geo`) from which the session was initiated.
3531
- Determine if these are consistent with typical user locations or if they raise suspicions of compromise or misuse.
36-
- **Review Session Details**: Examine details like the session ID and stream URL (`aws.cloudtrail.flattened.response_elements`) to understand the scope and nature of the session.
32+
- **Review Session Details**: Examine details like the session ID and stream URL (`aws.cloudtrail.response_elements`) to understand the scope and nature of the session.
3733
- Check if any commands executed during the session were unauthorized or out of ordinary practices.
3834
- **Correlate with Other Security Events**: Look for other related security events around the time of the session start to identify any pattern or broader attack vector that may involve this user or EC2 instance.
3935
@@ -43,12 +39,10 @@ This rule detects the first instance of an AWS resource initiating an SSM sessio
4339
4440
### Response and Remediation
4541
46-
- **Immediate Session Review**: If the session initiation seems suspicious, review all actions taken during the session.
47-
- If possible, terminate the session to prevent any potential harm.
48-
- **Validate and Reinforce Security Policies**: Ensure that policies around SSM session initiation are strict and adhere to the principle of least privilege.
49-
- Update IAM policies if necessary to tighten controls.
5042
- **Incident Response Activation**: If malicious intent or actions are confirmed, activate the incident response protocol.
5143
- This includes containment of the threat, eradication of the adversary’s presence, recovery of affected systems, and a thorough investigation.
44+
- **Validate and Reinforce Security Policies**: Ensure that policies around SSM session initiation are strict and adhere to the principle of least privilege.
45+
- Update IAM policies if necessary to tighten controls.
5246
- **Enhance Monitoring and Alerts**: Improve monitoring of SSM sessions, particularly focusing on sessions that involve sensitive or critical EC2 instances.
5347
- Adjust alerting mechanisms to flag unusual session initiations promptly.
5448
@@ -60,6 +54,8 @@ For more in-depth understanding of managing SSM sessions and security best pract
6054
references = [
6155
"https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_StartSession.html",
6256
"https://hackingthe.cloud/aws/post_exploitation/intercept_ssm_communications/",
57+
"https://cloud.hacktricks.xyz/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ssm-privesc",
58+
"https://unit42.paloaltonetworks.com/cloud-lateral-movement-techniques",
6359
]
6460
risk_score = 47
6561
rule_id = "804a7ac8-fc00-11ee-924b-f661ea17fbce"
@@ -69,6 +65,7 @@ tags = [
6965
"Data Source: AWS",
7066
"Data Source: Amazon Web Services",
7167
"Data Source: AWS SSM",
68+
"Data Source: AWS EC2",
7269
"Use Case: Threat Detection",
7370
"Tactic: Lateral Movement",
7471
"Resources: Investigation Guide",
@@ -81,6 +78,22 @@ event.dataset:"aws.cloudtrail" and event.provider:"ssm.amazonaws.com"
8178
and event.action:"StartSession" and event.outcome:"success"
8279
'''
8380

81+
[rule.investigation_fields]
82+
field_names = [
83+
"@timestamp",
84+
"user.name",
85+
"user_agent.original",
86+
"source.ip",
87+
"aws.cloudtrail.user_identity.arn",
88+
"aws.cloudtrail.user_identity.type",
89+
"aws.cloudtrail.user_identity.access_key_id",
90+
"event.action",
91+
"event.outcome",
92+
"cloud.account.id",
93+
"cloud.region",
94+
"aws.cloudtrail.request_parameters",
95+
"aws.cloudtrail.response_elements"
96+
]
8497

8598
[[rule.threat]]
8699
framework = "MITRE ATT&CK"
@@ -102,7 +115,7 @@ reference = "https://attack.mitre.org/tactics/TA0008/"
102115

103116
[rule.new_terms]
104117
field = "new_terms_fields"
105-
value = ["aws.cloudtrail.user_identity.arn"]
118+
value = ["cloud.account.id", "user.name"]
106119
[[rule.new_terms.history_window_start]]
107120
field = "history_window_start"
108121
value = "now-10d"

0 commit comments

Comments
 (0)