AWS SSM Session Started to EC2 Instance

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.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2024/04/16"
  3integration = ["aws"]
  4maturity = "production"
  5updated_date = "2025/09/05"
  6
  7[rule]
  8author = ["Elastic"]
  9description = """
 10Identifies 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. 
 11"""
 12false_positives = ["Legitimate use of AWS Session Manager to establish a session to an EC2 instance."]
 13from = "now-6m"
 14index = ["filebeat-*", "logs-aws.cloudtrail-*"]
 15language = "kuery"
 16license = "Elastic License v2"
 17name = "AWS SSM Session Started to EC2 Instance"
 18note = """## Triage and analysis
 19
 20### Investigating AWS SSM Session Started to EC2 Instance
 21
 22This 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.
 23
 24#### Possible Investigation Steps
 25
 26- **Examine the Session Start Event**: Review the AWS CloudTrail log for the event.
 27    - Determine the target EC2 instance using `aws.cloudtrail.request_parameters`.
 28- **Verify User Identity and Role**: Check the user’s ARN and access key ID (`aws.cloudtrail.user_identity.access_key_id`).
 29    - Determine if their role typically requires initiating SSM sessions.
 30- **Assess Geographic and IP Context**: Analyze the source IP (`source.ip`) and geographic location (`source.geo`) from which the session was initiated.
 31    - Determine if these are consistent with typical user locations or if they raise suspicions of compromise or misuse.
 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.
 33    - Check if any commands executed during the session were unauthorized or out of ordinary practices.
 34- **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.
 35
 36### False Positive Analysis
 37
 38- **Legitimate Administrative Activities**: Confirm whether the SSM session was initiated for valid administrative purposes such as system maintenance, patching, or configuration updates. Verify with the respective teams or personnel.
 39
 40### Response and Remediation
 41
 42- **Incident Response Activation**: If malicious intent or actions are confirmed, activate the incident response protocol.
 43    - 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.
 46- **Enhance Monitoring and Alerts**: Improve monitoring of SSM sessions, particularly focusing on sessions that involve sensitive or critical EC2 instances.
 47    - Adjust alerting mechanisms to flag unusual session initiations promptly.
 48
 49### Additional Information
 50
 51For more in-depth understanding of managing SSM sessions and security best practices, refer to the [AWS Systems Manager documentation](https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_StartSession.html). Additionally, consider the security implications and best practices outlined in [AWS SSM privilege escalation techniques](https://cloud.hacktricks.xyz/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ssm-privesc).
 52
 53"""
 54references = [
 55    "https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_StartSession.html",
 56    "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",
 59]
 60risk_score = 47
 61rule_id = "804a7ac8-fc00-11ee-924b-f661ea17fbce"
 62severity = "medium"
 63tags = [
 64    "Domain: Cloud",
 65    "Data Source: AWS",
 66    "Data Source: Amazon Web Services",
 67    "Data Source: AWS SSM",
 68    "Data Source: AWS EC2",
 69    "Use Case: Threat Detection",
 70    "Tactic: Lateral Movement",
 71    "Resources: Investigation Guide",
 72]
 73timestamp_override = "event.ingested"
 74type = "new_terms"
 75
 76query = '''
 77event.dataset:"aws.cloudtrail" and event.provider:"ssm.amazonaws.com"
 78    and event.action:"StartSession" and event.outcome:"success"
 79'''
 80
 81[rule.investigation_fields]
 82field_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]
 97
 98[[rule.threat]]
 99framework = "MITRE ATT&CK"
100[[rule.threat.technique]]
101id = "T1021"
102name = "Remote Services"
103reference = "https://attack.mitre.org/techniques/T1021/"
104[[rule.threat.technique.subtechnique]]
105id = "T1021.007"
106name = "Cloud Services"
107reference = "https://attack.mitre.org/techniques/T1021/007/"
108
109
110
111[rule.threat.tactic]
112id = "TA0008"
113name = "Lateral Movement"
114reference = "https://attack.mitre.org/tactics/TA0008/"
115
116[rule.new_terms]
117field = "new_terms_fields"
118value = ["cloud.account.id", "user.name"]
119[[rule.new_terms.history_window_start]]
120field = "history_window_start"
121value = "now-10d"

Triage and analysis

Investigating AWS SSM Session Started to EC2 Instance

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.

Possible Investigation Steps

  • Examine the Session Start Event: Review the AWS CloudTrail log for the event.
    • Determine the target EC2 instance using aws.cloudtrail.request_parameters.
  • Verify User Identity and Role: Check the user’s ARN and access key ID (aws.cloudtrail.user_identity.access_key_id).
    • Determine if their role typically requires initiating SSM sessions.
  • Assess Geographic and IP Context: Analyze the source IP (source.ip) and geographic location (source.geo) from which the session was initiated.
    • Determine if these are consistent with typical user locations or if they raise suspicions of compromise or misuse.
  • 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.
    • Check if any commands executed during the session were unauthorized or out of ordinary practices.
  • 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.

False Positive Analysis

  • Legitimate Administrative Activities: Confirm whether the SSM session was initiated for valid administrative purposes such as system maintenance, patching, or configuration updates. Verify with the respective teams or personnel.

Response and Remediation

  • Incident Response Activation: If malicious intent or actions are confirmed, activate the incident response protocol.
    • This includes containment of the threat, eradication of the adversary’s presence, recovery of affected systems, and a thorough investigation.
  • Validate and Reinforce Security Policies: Ensure that policies around SSM session initiation are strict and adhere to the principle of least privilege.
    • Update IAM policies if necessary to tighten controls.
  • Enhance Monitoring and Alerts: Improve monitoring of SSM sessions, particularly focusing on sessions that involve sensitive or critical EC2 instances.
    • Adjust alerting mechanisms to flag unusual session initiations promptly.

Additional Information

For more in-depth understanding of managing SSM sessions and security best practices, refer to the AWS Systems Manager documentation. Additionally, consider the security implications and best practices outlined in AWS SSM privilege escalation techniques.

References

Related rules

to-top