AWS SSM SendCommand
with Run Shell Command Parameters
Identifies the use of the AWS Systems Manager (SSM) SendCommand
API with the either AWS-RunShellScript
or
AWS-RunPowerShellScript
parameters. The SendCommand
API call allows users to execute commands on EC2 instances using
the SSM service. Adversaries may use this technique to execute commands on EC2 instances without the need for SSH or RDP
access. This behavior may indicate an adversary attempting to execute commands on an EC2 instance for malicious
purposes. This is a New Terms rule that only flags
when this behavior is observed for the first time on a host in the last 7 days.
Elastic rule (View on GitHub)
1[metadata]
2creation_date = "2022/09/03"
3integration = ["endpoint", "auditd_manager"]
4maturity = "production"
5updated_date = "2025/01/15"
6
7[rule]
8author = ["Elastic"]
9description = """
10Identifies the use of the AWS Systems Manager (SSM) `SendCommand` API with the either `AWS-RunShellScript` or
11`AWS-RunPowerShellScript` parameters. The `SendCommand` API call allows users to execute commands on EC2 instances using
12the SSM service. Adversaries may use this technique to execute commands on EC2 instances without the need for SSH or RDP
13access. This behavior may indicate an adversary attempting to execute commands on an EC2 instance for malicious
14purposes. This is a [New Terms](https://www.elastic.co/guide/en/security/current/rules-ui-create.html#create-new-terms-rule) rule that only flags
15when this behavior is observed for the first time on a host in the last 7 days.
16"""
17false_positives = [
18 """
19 Legitimate use of the `SendCommand` API call to execute commands on EC2 instances using the SSM service may be done
20 by system administrators or DevOps engineers for legitimate purposes.
21 """,
22]
23from = "now-9m"
24index = ["logs-endpoint.events.*", "endgame-*", "auditbeat-*", "logs-auditd_manager.auditd-*"]
25language = "kuery"
26license = "Elastic License v2"
27name = "AWS SSM `SendCommand` with Run Shell Command Parameters"
28references = [
29 "https://cloud.hacktricks.xyz/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ssm-privesc",
30 "https://securitycafe.ro/2023/01/17/aws-post-explitation-with-ssm-sendcommand/",
31]
32risk_score = 47
33rule_id = "c371e9fc-6a10-11ef-a0ac-f661ea17fbcc"
34setup = """## Setup
35
36This rule requires data coming in from Elastic Defend.
37
38### Elastic Defend Integration Setup
39Elastic Defend is integrated into the Elastic Agent using Fleet. Upon configuration, the integration allows the Elastic Agent to monitor events on your host and send data to the Elastic Security app.
40
41#### Prerequisite Requirements:
42- Fleet is required for Elastic Defend.
43- To configure Fleet Server refer to the [documentation](https://www.elastic.co/guide/en/fleet/current/fleet-server.html).
44
45#### The following steps should be executed in order to add the Elastic Defend integration on a Linux System:
46- Go to the Kibana home page and click "Add integrations".
47- In the query bar, search for "Elastic Defend" and select the integration to see more details about it.
48- Click "Add Elastic Defend".
49- Configure the integration name and optionally add a description.
50- Select the type of environment you want to protect, either "Traditional Endpoints" or "Cloud Workloads".
51- Select a configuration preset. Each preset comes with different default settings for Elastic Agent, you can further customize these later by configuring the Elastic Defend integration policy. [Helper guide](https://www.elastic.co/guide/en/security/current/configure-endpoint-integration-policy.html).
52- We suggest selecting "Complete EDR (Endpoint Detection and Response)" as a configuration setting, that provides "All events; all preventions"
53- Enter a name for the agent policy in "New agent policy name". If other agent policies already exist, you can click the "Existing hosts" tab and select an existing policy instead.
54For more details on Elastic Agent configuration settings, refer to the [helper guide](https://www.elastic.co/guide/en/fleet/8.10/agent-policy.html).
55- Click "Save and Continue".
56- To complete the integration, select "Add Elastic Agent to your hosts" and continue to the next section to install the Elastic Agent on your hosts.
57For more details on Elastic Defend refer to the [helper guide](https://www.elastic.co/guide/en/security/current/install-endpoint.html).
58"""
59severity = "medium"
60tags = [
61 "Domain: Endpoint",
62 "Domain: Cloud",
63 "OS: Linux",
64 "OS: macOS",
65 "OS: Windows",
66 "Use Case: Threat Detection",
67 "Tactic: Execution",
68 "Data Source: Elastic Defend",
69 "Data Source: Elastic Endgame",
70 "Data Source: Auditd Manager",
71 "Resources: Investigation Guide"
72]
73timestamp_override = "event.ingested"
74type = "new_terms"
75
76query = '''
77event.category: "process" and event.type: "start" and process.name: "aws"
78and (
79 host.os.type: ("windows" or "macos")
80 or (
81 host.os.type: "linux"
82 and event.action: ("exec" or "exec_event" or "executed" or "process_started")
83 )
84)
85and process.args: (
86 "send-command" and "--parameters" and commands=*
87 and ("AWS-RunShellScript" or "AWS-RunPowerShellScript")
88)
89'''
90note = """## Triage and analysis
91
92> **Disclaimer**:
93> This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
94
95### Investigating AWS SSM `SendCommand` with Run Shell Command Parameters
96
97AWS Systems Manager (SSM) allows remote command execution on EC2 instances via the `SendCommand` API, using scripts like `AWS-RunShellScript` or `AWS-RunPowerShellScript`. Adversaries may exploit this to execute unauthorized commands without direct access. The detection rule identifies unusual command executions by monitoring process activities, flagging first-time occurrences within a week to spot potential threats.
98
99### Possible investigation steps
100
101- Review the alert details to identify the specific EC2 instance and the user account associated with the `SendCommand` API call.
102- Check the AWS CloudTrail logs for the `SendCommand` event to gather additional context, such as the source IP address, user agent, and any associated IAM roles or policies.
103- Investigate the command parameters used in the `SendCommand` API call, focusing on the `commands` field to determine the nature and intent of the executed script.
104- Examine the process execution history on the affected host to identify any unusual or unauthorized processes that may have been initiated as a result of the command.
105- Assess the recent activity of the user account involved in the alert to identify any other suspicious actions or deviations from normal behavior.
106- Verify the integrity and security posture of the affected EC2 instance, checking for any signs of compromise or unauthorized changes.
107
108### False positive analysis
109
110- Routine administrative tasks using AWS SSM SendCommand may trigger alerts. Identify and document regular maintenance scripts and exclude them from detection to reduce noise.
111- Automated deployment processes often use AWS-RunShellScript or AWS-RunPowerShellScript. Review deployment logs and whitelist these processes if they are verified as non-threatening.
112- Monitoring or compliance checks that utilize SSM for gathering system information can be mistaken for malicious activity. Confirm these activities with the relevant teams and create exceptions for known benign operations.
113- Scheduled tasks or cron jobs that execute commands via SSM should be reviewed. If they are part of standard operations, consider excluding them from the rule to prevent false positives.
114- Development and testing environments frequently use SSM for testing scripts. Ensure these environments are well-documented and apply exceptions to avoid unnecessary alerts.
115
116### Response and remediation
117
118- Immediately isolate the affected EC2 instance from the network to prevent further unauthorized command execution and potential lateral movement.
119- Review the AWS CloudTrail logs to identify the source of the `SendCommand` API call, including the IAM user or role that initiated the command, and assess whether the access was legitimate or compromised.
120- Revoke or rotate the credentials of the IAM user or role involved in the suspicious activity to prevent further unauthorized access.
121- Conduct a thorough examination of the affected EC2 instance to identify any unauthorized changes or installed malware, and restore the instance from a known good backup if necessary.
122- Implement stricter IAM policies and permissions to limit the use of the `SendCommand` API to only trusted users and roles, ensuring the principle of least privilege is enforced.
123- Enable multi-factor authentication (MFA) for all IAM users with permissions to execute commands on EC2 instances to add an additional layer of security.
124- Escalate the incident to the security operations team for further investigation and to determine if additional instances or resources have been compromised."""
125
126[rule.investigation_fields]
127field_names = [
128 "@timestamp",
129 "process.user.name",
130 "process.entry_leader.group.name",
131 "process.entry_leader.real_user.name",
132 "event.action",
133 "event.type",
134 "host.os.type",
135 "host.os.kernel",
136 "process.entry_leader.executable",
137 "process.entry_leader.working_directory",
138 "process.parent.executable",
139 "process.executable",
140 "process.hash.sha256",
141 "process.parent.command_line",
142 "process.command_line",
143 "process.args"
144]
145
146[[rule.threat]]
147framework = "MITRE ATT&CK"
148[[rule.threat.technique]]
149id = "T1651"
150name = "Cloud Administration Command"
151reference = "https://attack.mitre.org/techniques/T1651/"
152
153
154[rule.threat.tactic]
155id = "TA0002"
156name = "Execution"
157reference = "https://attack.mitre.org/tactics/TA0002/"
158
159[rule.new_terms]
160field = "new_terms_fields"
161value = ["host.id"]
162[[rule.new_terms.history_window_start]]
163field = "history_window_start"
164value = "now-7d"
Triage and analysis
Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
Investigating AWS SSM SendCommand
with Run Shell Command Parameters
AWS Systems Manager (SSM) allows remote command execution on EC2 instances via the SendCommand
API, using scripts like AWS-RunShellScript
or AWS-RunPowerShellScript
. Adversaries may exploit this to execute unauthorized commands without direct access. The detection rule identifies unusual command executions by monitoring process activities, flagging first-time occurrences within a week to spot potential threats.
Possible investigation steps
- Review the alert details to identify the specific EC2 instance and the user account associated with the
SendCommand
API call. - Check the AWS CloudTrail logs for the
SendCommand
event to gather additional context, such as the source IP address, user agent, and any associated IAM roles or policies. - Investigate the command parameters used in the
SendCommand
API call, focusing on thecommands
field to determine the nature and intent of the executed script. - Examine the process execution history on the affected host to identify any unusual or unauthorized processes that may have been initiated as a result of the command.
- Assess the recent activity of the user account involved in the alert to identify any other suspicious actions or deviations from normal behavior.
- Verify the integrity and security posture of the affected EC2 instance, checking for any signs of compromise or unauthorized changes.
False positive analysis
- Routine administrative tasks using AWS SSM SendCommand may trigger alerts. Identify and document regular maintenance scripts and exclude them from detection to reduce noise.
- Automated deployment processes often use AWS-RunShellScript or AWS-RunPowerShellScript. Review deployment logs and whitelist these processes if they are verified as non-threatening.
- Monitoring or compliance checks that utilize SSM for gathering system information can be mistaken for malicious activity. Confirm these activities with the relevant teams and create exceptions for known benign operations.
- Scheduled tasks or cron jobs that execute commands via SSM should be reviewed. If they are part of standard operations, consider excluding them from the rule to prevent false positives.
- Development and testing environments frequently use SSM for testing scripts. Ensure these environments are well-documented and apply exceptions to avoid unnecessary alerts.
Response and remediation
- Immediately isolate the affected EC2 instance from the network to prevent further unauthorized command execution and potential lateral movement.
- Review the AWS CloudTrail logs to identify the source of the
SendCommand
API call, including the IAM user or role that initiated the command, and assess whether the access was legitimate or compromised. - Revoke or rotate the credentials of the IAM user or role involved in the suspicious activity to prevent further unauthorized access.
- Conduct a thorough examination of the affected EC2 instance to identify any unauthorized changes or installed malware, and restore the instance from a known good backup if necessary.
- Implement stricter IAM policies and permissions to limit the use of the
SendCommand
API to only trusted users and roles, ensuring the principle of least privilege is enforced. - Enable multi-factor authentication (MFA) for all IAM users with permissions to execute commands on EC2 instances to add an additional layer of security.
- Escalate the incident to the security operations team for further investigation and to determine if additional instances or resources have been compromised.
References
Related rules
- Hidden Files and Directories via Hidden Flag
- Potential Linux Hack Tool Launched
- Process Started from Process ID (PID) File
- Tampering of Shell Command-Line History
- Unix Socket Connection