AWS SSM Data Channel Created for Session Targeted to Another Node

edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.

AWS SSM Data Channel Created for Session Targeted to Another Node

edit

Detects an AWS Systems Manager (SSM) Session Manager session targeting one EC2 or hybrid managed node followed by a successful "CreateDataChannel" request for the same session from a different managed node. This mismatch can indicate that credentials from a compromised node were used to join another node’s session.

Rule type: esql

Rule indices: None

Severity: medium

Risk score: 47

Runs every: 5m

Searches indices from: now-35m (Date Math format, see also Additional look-back time)

Maximum alerts per execution: 100

References:

Tags:

  • Domain: Cloud
  • Data Source: AWS
  • Data Source: Amazon Web Services
  • Data Source: AWS SSM
  • Data Source: AWS EC2
  • Use Case: Threat Detection
  • Tactic: Lateral Movement
  • Rule Type: ES|QL
  • Resources: Investigation Guide

Version: 1

Rule authors:

  • Elastic

Rule license: Elastic License v2

Investigation guide

edit

Triage and analysis

Investigating AWS SSM Data Channel Created for Session Targeted to Another Node

This rule correlates a successful StartSession event with a successful CreateDataChannel event for the returned session ID. During normal Session Manager operation, the agent on the targeted managed node uses that node’s credentials to create the data channel. The rule alerts when the instance or hybrid-node identity at the end of the channel caller’s user.id differs from the StartSession target.

Managed-node roles commonly receive ssmmessages:CreateDataChannel on all resources. A caller with credentials from one node may therefore be able to request a data-channel token for a different node’s active session without receiving StartSession or ResumeSession permission. A mismatch is a strong lateral-movement signal, but the alert does not by itself prove that the returned token was used to open the channel.

Possible investigation steps

  • Compare Esql.start_target_values with Esql.create_data_channel_caller_node_values and confirm that they identify different managed nodes. Use Esql.session_id to retrieve the original CloudTrail events.
  • Identify the StartSession initiator, document name, session parameters, and source address. Determine whether the session was interactive and whether the initiator expected it to reach the recorded target.
  • Review preceding failed StartSession, ResumeSession, and DescribeSessions requests from the channel caller’s identity and source address. Search for discovery of active session identifiers.
  • Identify subsequent OpenDataChannel events for the session and review the associated source address and user agent.
  • Investigate the source managed node for instance metadata credential access and direct SSM messaging API calls.
  • Review Session Manager audit logs, shell history, and commands executed during the affected session.

False positive analysis

  • Determine whether an approved session broker intentionally creates channels on behalf of other managed nodes.
  • Do not exclude all instance-profile activity or all CreateDataChannel events. Normal agents generate these events; the cross-node correlation provides the signal.
  • If long-running sessions are expected, increase the lookback to the configured maximum session duration.

Response and remediation

  • Isolate both the source managed node and the target session’s node if cross-instance access is confirmed.
  • Terminate the affected Session Manager session and revoke or replace the source node’s instance profile credentials.
  • Review all sessions and channel events involving the source role for additional affected nodes.
  • Restrict discovery of active session identifiers and monitor the four ssmmessages channel operations granted to managed-node roles.

Rule query

edit
FROM logs-aws.cloudtrail-*
| WHERE event.dataset == "aws.cloudtrail"
  AND event.provider == "ssm.amazonaws.com"
  AND event.action IN ("StartSession", "CreateDataChannel")
  AND event.outcome == "success"
| GROK aws.cloudtrail.response_elements
    """%{GREEDYDATA}sessionId=(?<Esql.start_session_id>[^,}]+)%{GREEDYDATA}"""
| GROK aws.cloudtrail.request_parameters
    """%{GREEDYDATA}sessionId=(?<Esql.create_data_channel_session_id>[^,}]+)%{GREEDYDATA}"""
| GROK aws.cloudtrail.request_parameters
    """%{GREEDYDATA}target=(?<Esql.start_target>[^,}]+)%{GREEDYDATA}"""
| GROK user.id
    """%{GREEDYDATA}:(?<Esql.create_data_channel_caller_node>(?:i|mi)-.+)"""
| EVAL Esql.is_start_session = event.action == "StartSession"
| EVAL Esql.is_create_data_channel = event.action == "CreateDataChannel"
| EVAL Esql.session_id = COALESCE(
    Esql.start_session_id,
    Esql.create_data_channel_session_id
  )
| EVAL Esql.managed_node = CASE(
    Esql.is_start_session,
    Esql.start_target,
    Esql.create_data_channel_caller_node
  )
| WHERE Esql.session_id IS NOT NULL
  AND Esql.managed_node LIKE ("i-*", "mi-*")
| STATS
    Esql.start_session_event_count = SUM(CASE(Esql.is_start_session, 1, 0)),
    Esql.create_data_channel_event_count = SUM(CASE(Esql.is_create_data_channel, 1, 0)),
    Esql.managed_node_count = COUNT_DISTINCT(Esql.managed_node),
    Esql.first_start_session_event = MIN(CASE(Esql.is_start_session, @timestamp, null)),
    Esql.first_create_data_channel_event = MIN(CASE(Esql.is_create_data_channel, @timestamp, null)),
    Esql.start_target_values = VALUES(CASE(Esql.is_start_session, Esql.start_target, null)),
    Esql.create_data_channel_caller_node_values = VALUES(
      CASE(Esql.is_create_data_channel, Esql.create_data_channel_caller_node, null)
    ),
    Esql.source_ip_values = VALUES(CASE(Esql.is_create_data_channel, source.ip, null)),
    Esql.user_agent_original_values = VALUES(CASE(Esql.is_create_data_channel, user_agent.original, null)),
    Esql_priv.start_session_principal_arn_values = VALUES(
      CASE(Esql.is_start_session, aws.cloudtrail.user_identity.arn, null)
    ),
    Esql_priv.create_data_channel_principal_arn_values = VALUES(
      CASE(Esql.is_create_data_channel, aws.cloudtrail.user_identity.arn, null)
    )
  BY cloud.account.id, cloud.region, Esql.session_id
| WHERE Esql.start_session_event_count >= 1
  AND Esql.create_data_channel_event_count >= 1
  AND Esql.managed_node_count >= 2
  AND Esql.first_create_data_channel_event >= Esql.first_start_session_event
  AND DATE_DIFF(
    "minutes",
    Esql.first_start_session_event,
    Esql.first_create_data_channel_event
  ) <= 30
| KEEP cloud.account.id, cloud.region, Esql.*, Esql_priv.*

Framework: MITRE ATT&CKTM