1. Resources
  2. Detection rules
  3. SSH Key Pushed to an EC2 Instance Through EC2 Instance Connect or the Serial Console

SSH Key Pushed to an EC2 Instance Through EC2 Instance Connect or the Serial Console detection rules

An attacker who controls an identity with EC2 Instance Connect permissions pushes a temporary SSH public key to an instance and logs in, with no long-term key on the host and no change to the instance.

Platform
AWS
Severity
Medium
Log source
AWS CloudTrail
Last updated
Rule formats
Sigmaand queries for: SplunkMicrosoft SentinelIBM QRadar
What an attacker needs
Credentials for a principal that may push SSH keys with EC2 Instance Connect, and network or serial console reach to the instance.
Impact
An interactive session on the instance, which exposes its data and the temporary credentials of its instance role.
Response
Contain the principal that pushed the key, treat the instance as accessed, and revoke the active sessions of its instance role.
Mitigation
Grant SendSSHPublicKey only to operators and only for specific instances and users, and keep serial console access disabled.
CloudTrail events
EnableSerialConsoleAccessSendSerialConsoleSSHPublicKeySendSSHPublicKey
Threat groups
None listed in MITRE ATT&CK for this technique

How the attack works

EC2 Instance Connect replaces stored SSH keys with an IAM permission. SendSSHPublicKey pushes a public key for one operating system user to an instance, and the holder of the matching private key can then open an SSH session. SendSerialConsoleSSHPublicKey does the same for the EC2 serial console, where AWS states that the key remains for 60 seconds, and the serial console reaches an instance even when its network is not reachable. Access to the serial console is disabled for an account by default and is switched on with EnableSerialConsoleAccess. Where the instance has no public address, an EC2 Instance Connect Endpoint carries the connection into the VPC, and AWS logs each such connection as an OpenTunnel event.

For an attacker who has taken over an AWS principal with these permissions, this is a way onto hosts that leaves nothing behind on them: no new entry in an authorized keys file, no key pair to find later. Once logged in, the attacker has what the operating system user has: the data on the host and, through the instance metadata, the temporary credentials of the instance role.

The calls are recorded as CloudTrail management events under ec2-instance-connect.amazonaws.com. AWS publishes an example record for SendSSHPublicKey, whose requestParameters hold the destination instance (instanceId), the operating system user (osUser) and the public key, and one for OpenTunnel. CloudTrail shows that a key was pushed, not that the SSH login succeeded or what was done in the session. No incident report was used for this page: it follows what AWS documents about these calls.

What an attacker needs

  • Credentials for a principal allowed ec2-instance-connect:SendSSHPublicKey on the instance, or ec2-instance-connect:SendSerialConsoleSSHPublicKey in an account where serial console access is enabled.
  • For SSH, network reach to the instance, directly or through an EC2 Instance Connect Endpoint, and an instance on which EC2 Instance Connect is installed.
  • For the serial console, an operating system user with a password on the instance.

Impact

An interactive session on the instance as the chosen operating system user. The attacker reads data and secrets on the host, can take the temporary credentials of the instance role and act with its permissions in the account, and can move on to what the host reaches on the network. Nothing on the instance records which AWS identity was behind the login.

Detection rules

EC2 Serial Console Access Enabled or SSH Key Pushed to the Serial Console

Detects EnableSerialConsoleAccess calls to Amazon EC2 and SendSerialConsoleSSHPublicKey calls to EC2 Instance Connect. AWS documents that access to the EC2 serial console is disabled for an account by default and that EnableSerialConsoleAccess enables it for all instances of the account. SendSerialConsoleSSHPublicKey pushes an SSH public key to the serial console of one instance, where it remains for 60 seconds. The serial console reaches an instance without a network path to it, so it is a recovery tool that few teams use daily. EC2 logs all of its API actions as management events, and AWS publishes no example record for these two calls, so the rule matches the event names only. It also matches attempts that failed (errorCode present): check errorCode, because an unauthorized attempt is worth seeing.

LevelMediumStatusExperimentalLog sourceAWS CloudTrail
title: EC2 Serial Console Access Enabled or SSH Key Pushed to the Serial Console
id: 5415b1f4-ff14-4707-b15a-7a98065f883f
status: experimental
description: >-
  Detects EnableSerialConsoleAccess calls to Amazon EC2 and
  SendSerialConsoleSSHPublicKey calls to EC2 Instance Connect. AWS documents
  that access to the EC2 serial console is disabled for an account by
  default and that EnableSerialConsoleAccess enables it for all instances of
  the account. SendSerialConsoleSSHPublicKey pushes an SSH public key to the
  serial console of one instance, where it remains for 60 seconds. The
  serial console reaches an instance without a network path to it, so it is
  a recovery tool that few teams use daily. EC2 logs all of its API actions
  as management events, and AWS publishes no example record for these two
  calls, so the rule matches the event names only.
  It also matches attempts that failed (errorCode present): check errorCode,
  because an unauthorized attempt is worth seeing.
references:
  - https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_EnableSerialConsoleAccess.html
  - https://docs.aws.amazon.com/ec2-instance-connect/latest/APIReference/API_SendSerialConsoleSSHPublicKey.html
  - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitor-with-cloudtrail.html
  - https://attack.mitre.org/techniques/T1021/008/
author: Forestall
date: 2026-11-18
tags:
  - attack.lateral-movement
  - attack.t1021.008
logsource:
  product: aws
  service: cloudtrail
detection:
  selection_enable:
    eventSource: ec2.amazonaws.com
    eventName: EnableSerialConsoleAccess
  selection_key:
    eventSource: ec2-instance-connect.amazonaws.com
    eventName: SendSerialConsoleSSHPublicKey
  condition: 1 of selection_*
falsepositives:
  - Recovery of instances that no longer boot or have lost their network configuration, done by administrators through the serial console. These are rare and planned, so confirm each one with the team that owns the instance.
level: medium

False positives

  • Recovery of instances that no longer boot or have lost their network configuration, done by administrators through the serial console. These are rare and planned, so confirm each one with the team that owns the instance.

SSH Keys Pushed to Many EC2 Instances by One Principal

Counts, per calling principal (userIdentity.arn), to how many different instances it pushed an SSH public key with EC2 Instance Connect. Keys pushed to five or more different instances within 30 minutes is the pattern of someone working through a fleet. The instance is read from requestParameters.instanceId, which AWS's example record for SendSSHPublicKey shows. An operator who checks many hosts during an incident produces the same pattern, so the count and the window are starting points to tune. Denied attempts are counted as well. For role sessions the principal is the session ARN, so one role used with different session names is counted per session.

Fires when one userIdentity.arn has at least 5 different requestParameters.instanceId values within 30 minutes.

Threshold ruleLevelMediumStatusExperimentalLog sourceAWS CloudTrail
title: SSH Public Key Pushed with EC2 Instance Connect (Many Instances Base Event)
id: be60927b-537c-43d5-80c0-6f6d242af2f2
name: aws_instance_connect_ssh_key_pushed
status: experimental
description: >-
  Base event of the threshold rule in this file. Any SendSSHPublicKey call
  to EC2 Instance Connect, including attempts that were denied.
logsource:
  product: aws
  service: cloudtrail
detection:
  selection:
    eventSource: ec2-instance-connect.amazonaws.com
    eventName: SendSSHPublicKey
  condition: selection
level: low
---
title: SSH Keys Pushed to Many EC2 Instances by One Principal
id: 2da680c8-2945-402c-a217-a7993053ad10
status: experimental
description: >-
  Counts, per calling principal (userIdentity.arn), to how many different
  instances it pushed an SSH public key with EC2 Instance Connect. Keys
  pushed to five or more different instances within 30 minutes is the
  pattern of someone working through a fleet. The instance is read from
  requestParameters.instanceId, which AWS's example record for
  SendSSHPublicKey shows. An operator who checks many hosts during an
  incident produces the same pattern, so the count and the window are
  starting points to tune. Denied attempts are counted as well. For role
  sessions the principal is the session ARN, so one role used with
  different session names is counted per session.
references:
  - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitor-with-cloudtrail.html
  - https://docs.aws.amazon.com/ec2-instance-connect/latest/APIReference/API_SendSSHPublicKey.html
  - https://attack.mitre.org/techniques/T1021/008/
author: Forestall
date: 2026-11-18
tags:
  - attack.lateral-movement
  - attack.t1021.008
correlation:
  type: value_count
  rules:
    - aws_instance_connect_ssh_key_pushed
  group-by:
    - userIdentity.arn
  timespan: 30m
  condition:
    field: requestParameters.instanceId
    gte: 5
falsepositives:
  - Operators who connect to many hosts during an incident or a rollout, and scripts that open SSH connections to instances in turn. Exclude those roles or give them a higher count.
  - The values of 5 instances and 30 minutes are starting points, not tested limits. Measure what your own operators produce and adjust both.
level: medium

False positives

  • Operators who connect to many hosts during an incident or a rollout, and scripts that open SSH connections to instances in turn. Exclude those roles or give them a higher count.
  • The values of 5 instances and 30 minutes are starting points, not tested limits. Measure what your own operators produce and adjust both.

SSH Public Key Pushed for the Root User with EC2 Instance Connect

Detects SendSSHPublicKey calls to EC2 Instance Connect whose operating system user is root. AWS's example record for this event shows the user in requestParameters.osUser (ec2-user in the example). Operators normally connect as the default user of the image and raise their rights on the host, so a key pushed directly for root is unusual and gives full control of the instance when the SSH configuration of the host permits root logins. The event shows that a key was pushed, not that the login succeeded. It also matches attempts that failed (errorCode present): check errorCode, because an unauthorized attempt is worth seeing.

LevelMediumStatusExperimentalLog sourceAWS CloudTrail
title: SSH Public Key Pushed for the Root User with EC2 Instance Connect
id: d2fdbea0-2ca2-4b54-abb2-6a01236dc15f
status: experimental
description: >-
  Detects SendSSHPublicKey calls to EC2 Instance Connect whose operating
  system user is root. AWS's example record for this event shows the user in
  requestParameters.osUser (ec2-user in the example). Operators normally
  connect as the default user of the image and raise their rights on the
  host, so a key pushed directly for root is unusual and gives full control
  of the instance when the SSH configuration of the host permits root
  logins. The event shows that a key was pushed, not that the login
  succeeded.
  It also matches attempts that failed (errorCode present): check errorCode,
  because an unauthorized attempt is worth seeing.
references:
  - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitor-with-cloudtrail.html
  - https://docs.aws.amazon.com/ec2-instance-connect/latest/APIReference/API_SendSSHPublicKey.html
  - https://attack.mitre.org/techniques/T1021/008/
author: Forestall
date: 2026-11-18
tags:
  - attack.lateral-movement
  - attack.t1021.008
logsource:
  product: aws
  service: cloudtrail
detection:
  selection:
    eventSource: ec2-instance-connect.amazonaws.com
    eventName: SendSSHPublicKey
    requestParameters.osUser: root
  condition: selection
falsepositives:
  - Images and recovery procedures that are built around direct root logins. Add the roles that follow such a procedure to a filter_* selection on userIdentity.arn.
level: medium

False positives

  • Images and recovery procedures that are built around direct root logins. Add the roles that follow such a procedure to a filter_* selection on userIdentity.arn.

SSH Public Key Pushed to an EC2 Instance with EC2 Instance Connect

Detects SendSSHPublicKey calls to EC2 Instance Connect. The call pushes a temporary SSH public key for one operating system user to an instance, and whoever holds the private key can then log in. AWS documents the event with an example record: the event source is ec2-instance-connect.amazonaws.com, and requestParameters holds the destination instance (instanceId), the operating system user (osUser) and the public key. The event shows that a key was pushed, not that the login succeeded. Every connection that operators make with EC2 Instance Connect matches, so scope the rule to callers outside the operations team. It also matches attempts that failed (errorCode present): check errorCode, because an unauthorized attempt is worth seeing.

LevelLowStatusExperimentalLog sourceAWS CloudTrail
title: SSH Public Key Pushed to an EC2 Instance with EC2 Instance Connect
id: b01e1cdd-c36f-4717-b953-2bd5fbb947e2
status: experimental
description: >-
  Detects SendSSHPublicKey calls to EC2 Instance Connect. The call pushes a
  temporary SSH public key for one operating system user to an instance, and
  whoever holds the private key can then log in. AWS documents the event
  with an example record: the event source is
  ec2-instance-connect.amazonaws.com, and requestParameters holds the
  destination instance (instanceId), the operating system user (osUser) and
  the public key. The event shows that a key was pushed, not that the login
  succeeded. Every connection that operators make with EC2 Instance Connect
  matches, so scope the rule to callers outside the operations team.
  It also matches attempts that failed (errorCode present): check errorCode,
  because an unauthorized attempt is worth seeing.
references:
  - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitor-with-cloudtrail.html
  - https://docs.aws.amazon.com/ec2-instance-connect/latest/APIReference/API_SendSSHPublicKey.html
  - https://attack.mitre.org/techniques/T1021/008/
author: Forestall
date: 2026-11-18
tags:
  - attack.lateral-movement
  - attack.t1021.008
logsource:
  product: aws
  service: cloudtrail
detection:
  selection:
    eventSource: ec2-instance-connect.amazonaws.com
    eventName: SendSSHPublicKey
  condition: selection
falsepositives:
  - Operators who connect to instances from the EC2 console or the command line with EC2 Instance Connect. Add the roles of the operations team to a filter_* selection on userIdentity.arn and keep alerting on keys pushed by workload roles, CI roles and unknown principals.
level: low

False positives

  • Operators who connect to instances from the EC2 console or the command line with EC2 Instance Connect. Add the roles of the operations team to a filter_* selection on userIdentity.arn and keep alerting on keys pushed by workload roles, CI roles and unknown principals.

Triage

  • Identify the caller (userIdentity.arn), the source IP address and the user agent. Is it an operator who normally connects to this instance?
  • Read requestParameters.instanceId and requestParameters.osUser. A key pushed for root, or to instances the caller's team does not own, deserves a closer look.
  • Count the different instances the caller pushed keys to in a short time.
  • Look for an OpenTunnel event by the same caller, which shows a connection through an EC2 Instance Connect Endpoint and the private address it went to.
  • Check what the instance role of the target did in CloudTrail after the event, and review the SSH and authentication logs of the host if they are collected.

Response

Once the attack is confirmed:

  1. Contain the principal that pushed the key, and take away its EC2 Instance Connect permissions until its use is explained.
  2. Treat the instance as accessed. End the open sessions on the host, isolate it, and review or rebuild it.
  3. Revoke the active sessions of the instance role of the instance, and rotate the secrets stored on or readable from the host.
  4. Disable serial console access for the account again if it was enabled without a recovery reason.
  5. Review CloudTrail for what the instance role did after the event, and remove what was created.

Mitigation

  • Grant ec2-instance-connect:SendSSHPublicKey only to the people who operate the instances, limited to specific instances or tags and to specific operating system users.
  • Keep serial console access disabled at the account level unless it is needed for recovery, and allow ec2-instance-connect:SendSerialConsoleSSHPublicKey only to a recovery role.
  • Restrict who may open tunnels through EC2 Instance Connect Endpoints, and limit the endpoints by security group to the instances that need them.
  • Keep instance roles least-privilege, because whoever logs in to the host can use the role.
  • Remove EC2 Instance Connect permissions from workload roles and CI roles that do not operate instances.

Frequently asked questions

Does a pushed key stay on the instance?

No. The key is temporary, which is the point of the service. For the serial console AWS states that the key remains for 60 seconds, the time in which the connection has to be opened. A session that was opened in that time continues after the key is gone. A review of the authorized keys files on the host therefore finds nothing.

Does CloudTrail show that the SSH login succeeded?

No. The `SendSSHPublicKey` event shows who pushed a key, for which instance and for which operating system user. The SSH connection itself goes to the instance and is not an AWS API call. A connection through an EC2 Instance Connect Endpoint is the exception, because AWS logs it as an `OpenTunnel` management event.

Why does the serial console matter if nobody uses it?

It connects to an instance without a working network connection to it, which is why it exists as a recovery tool. AWS disables serial console access for an account by default. An `EnableSerialConsoleAccess` call in an account that never used the serial console, followed by a key push, is therefore a strong signal.

Which legitimate activity produces these events?

Operators who connect from the EC2 console or the command line with EC2 Instance Connect produce a `SendSSHPublicKey` event for every connection. The events are suspicious when they come from a workload role, from a principal that has not connected to instances before, for the root user, or for many instances in a short time.

References

We respect your privacy

We use cookies to keep this site secure and working properly. With your permission, we also use optional cookies to understand usage and improve the experience. Cookie Policy

You can change your choice at any time.