Skip to content

Commit 1f04411

Browse files
authored
[Rule Tuning] AWS EC2 Instance Connect SSH Public Key Uploaded (#5069)
This rule is performing as expected and low noise in telemetry so no changes to query - added investigation fields - small edits to description and IG - added a reference from Unit42 showing real world threat case - reduced execution window
1 parent 02fcd43 commit 1f04411

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

rules/integrations/aws/lateral_movement_ec2_instance_connect_ssh_public_key_uploaded.toml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
creation_date = "2024/04/30"
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 = """
1010
Identifies when a new SSH public key is uploaded to an AWS EC2 instance using the EC2 Instance Connect service. This
11-
action could indicate an adversary attempting to maintain access to the instance. The rule also detects the
12-
`SendSerialConsoleSSHPublicKey` or `SendSSHPublicKey` API actions, which are logged when manually uploading an SSH key
11+
action could indicate an adversary attempting to maintain access to the instance. The rule detects the
12+
SendSerialConsoleSSHPublicKey or SendSSHPublicKey API actions, which are logged when manually uploading an SSH key
1313
to an EC2 instance or serial connection. It is important to know that this API call happens automatically by the EC2
1414
Instance Connect service when a user connects to an EC2 instance using the EC2 Instance Connect service via the CLI or
1515
AWS Management Console.
1616
"""
1717
false_positives = ["Administrators may upload SSH public keys to EC2 instances for legitimate purposes."]
18-
from = "now-9m"
18+
from = "now-6m"
1919
index = ["filebeat-*", "logs-aws.cloudtrail-*"]
2020
language = "kuery"
2121
license = "Elastic License v2"
@@ -24,12 +24,12 @@ note = """## Triage and Analysis
2424
2525
### Investigating AWS EC2 Instance Connect SSH Public Key Uploaded
2626
27-
This rule detects when a new SSH public key is uploaded to an AWS EC2 instance using the EC2 Instance Connect service. Adversaries may upload SSH public keys to EC2 instances to maintain access to the instance or for initial access. This action also occurs automatically in the background when establishing a connection to an instance via the same service. The rule also covers cases where the `SendSerialConsoleSSHPublicKey` API action is used to upload an SSH public key to a serial connection, which can be exploited for privilege escalation.
27+
This rule detects when a new SSH public key is uploaded to an AWS EC2 instance using the EC2 Instance Connect service. Adversaries may upload SSH public keys to EC2 instances to maintain access to the instance or for initial access. This action also occurs automatically in the background when establishing a connection to an instance via the same service. The rule covers cases where the `SendSerialConsoleSSHPublicKey` API action is used to upload an SSH public key to a serial connection, which can be exploited for privilege escalation.
2828
2929
#### Possible Investigation Steps:
3030
3131
- **Identify the Actor**: Review the `aws.cloudtrail.user_identity.arn` and `aws.cloudtrail.user_identity.access_key_id` fields to identify who performed the action. Verify if this actor typically performs such actions and if they have the necessary permissions.
32-
- **Review the Request Details**: Examine the `aws.cloudtrail.request_parameters` to understand the specific details of the SSH public key upload. Look for any unusual parameters that could suggest unauthorized or malicious modifications.
32+
- **Review the Request Details**: Examine the `aws.cloudtrail.request_parameters` to understand the specific details of the SSH public key upload. Look for any unusual parameters that could suggest unauthorized or malicious modifications. Use the `target.entity.id` field to determine the targeted EC2 instance.
3333
- **Analyze the Source of the Request**: Investigate the `source.ip` and `source.geo` fields to determine the geographical origin of the request. An external or unexpected location might indicate compromised credentials or unauthorized access.
3434
- **Contextualize with Timestamp**: Use the `@timestamp` field to check when the SSH public key was uploaded. Changes during non-business hours or outside regular maintenance windows might require further scrutiny.
3535
- **Correlate with Other Activities**: Search for related CloudTrail events before and after this action to see if the same actor or IP address engaged in other potentially suspicious activities.
@@ -39,7 +39,7 @@ This rule detects when a new SSH public key is uploaded to an AWS EC2 instance u
3939
4040
- **Legitimate Administrative Actions**: Confirm if the SSH public key upload aligns with scheduled updates, development activities, or legitimate administrative tasks documented in change management systems.
4141
- **Consistency Check**: Compare the action against historical data of similar actions performed by the user or within the organization. If the action is consistent with past legitimate activities, it might indicate a false alarm.
42-
- **Verify through Outcomes**: Check the `aws.cloudtrail.response_elements` and the `event.outcome` to confirm if the upload was successful and intended according to policy.
42+
4343
4444
### Response and Remediation:
4545
@@ -57,9 +57,10 @@ For further guidance on managing EC2 instances and securing AWS environments, re
5757
- [AWS EC2 Instance Connect API Reference](https://docs.aws.amazon.com/ec2-instance-connect/latest/APIReference/API_SendSSHPublicKey.html)
5858
"""
5959
references = [
60+
"https://unit42.paloaltonetworks.com/cloud-lateral-movement-techniques",
61+
"https://medium.parttimepolymath.net/aws-ec2-instance-connect-a-very-neat-trick-4d2fc0c28010",
6062
"https://stratus-red-team.cloud/attack-techniques/AWS/aws.lateral-movement.ec2-instance-connect/",
6163
"https://cloud.hacktricks.xyz/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ec2-privesc",
62-
"https://medium.parttimepolymath.net/aws-ec2-instance-connect-a-very-neat-trick-4d2fc0c28010",
6364
"https://docs.aws.amazon.com/ec2-instance-connect/latest/APIReference/API_SendSSHPublicKey.html",
6465
"https://docs.aws.amazon.com/ec2-instance-connect/latest/APIReference/API_SendSerialConsoleSSHPublicKey.html",
6566
]
@@ -86,6 +87,22 @@ event.dataset: aws.cloudtrail
8687
and event.outcome: success
8788
'''
8889

90+
[rule.investigation_fields]
91+
field_names = [
92+
"@timestamp",
93+
"user.name",
94+
"user_agent.original",
95+
"source.ip",
96+
"aws.cloudtrail.user_identity.arn",
97+
"aws.cloudtrail.user_identity.type",
98+
"aws.cloudtrail.user_identity.access_key_id",
99+
"event.action",
100+
"event.outcome",
101+
"cloud.account.id",
102+
"cloud.region",
103+
"aws.cloudtrail.request_parameters",
104+
"aws.cloudtrail.response_elements"
105+
]
89106

90107
[[rule.threat]]
91108
framework = "MITRE ATT&CK"

0 commit comments

Comments
 (0)