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 = "2024/09/23"
  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]
 72timestamp_override = "event.ingested"
 73type = "new_terms"
 74
 75query = '''
 76event.category: "process" and event.type: "start" and process.name: "aws"
 77and (
 78    host.os.type: ("windows" or "macos")
 79    or (
 80        host.os.type: "linux"
 81        and event.action: ("exec" or "exec_event" or "executed" or "process_started")
 82    )
 83)
 84and process.args: (
 85    "send-command" and "--parameters" and commands=*
 86    and ("AWS-RunShellScript" or "AWS-RunPowerShellScript")
 87)
 88'''
 89
 90
 91[[rule.threat]]
 92framework = "MITRE ATT&CK"
 93[[rule.threat.technique]]
 94id = "T1651"
 95name = "Cloud Administration Command"
 96reference = "https://attack.mitre.org/techniques/T1651/"
 97
 98
 99[rule.threat.tactic]
100id = "TA0002"
101name = "Execution"
102reference = "https://attack.mitre.org/tactics/TA0002/"
103
104[rule.new_terms]
105field = "new_terms_fields"
106value = ["host.id"]
107[[rule.new_terms.history_window_start]]
108field = "history_window_start"
109value = "now-7d"

References

Related rules

to-top