Detection rules › Elastic

Payload Piped to Script Interpreter

Time window
10s
Sequence by
process.parent.entity_id
Source
github.com/elastic/protections-artifacts

Detects when a script interpreter executes via a shell (sh, bash, zsh) or osascript with only a single argument, being the process name and followed immediately by a network connection. This activity occurs when script code gets piped to the interpreter via a shell and that code is intended to reach out to an external destination like a C2 server.

MITRE ATT&CK coverage

Telemetry coverage

Rule body

[rule]
description = """
Detects when a script interpreter executes via a shell (sh, bash, zsh) or osascript with only a single argument, being
the process name and followed immediately by a network connection. This activity occurs when script code gets piped to
the interpreter via a shell and that code is intended to reach out to an external destination like a C2 server.
"""
id = "e413073c-4d6b-40d4-9ef1-b4de22d137d3"
license = "Elastic License v2"
name = "Payload Piped to Script Interpreter"
os_list = ["macos"]
reference = ["https://github.com/nnsee/fileless-elf-exec"]
version = "1.0.14"

query = '''
sequence by process.parent.entity_id with maxspan=10s
[process where event.type == "start" and event.action == "exec" and
  process.name like~ ("zsh", "sh", "bash", "python*", "terminal") and
  process.args == "-c" and
  (
    process.command_line : ("*curl*|*", "*nscurl*|*", "*wget*|*", "*osascript*|*",
                            "*/dev/tcp/*", "*base64*|*", "*openssl*|*", "*nc *|*") or
    process.command_line : ("*curl*>*", "*wget*>*") or
    process.command_line : "*http*|*"
  )]
[process where event.type == "start" and event.action == "exec" and 
  process.name like~ ("python*", "perl*", "ruby*", "osascript") and
  process.parent.name in ("sh", "bash", "zsh", "osascript") and 
  process.args like~ ("python*", "perl*", "ruby*", "osascript") and 
  process.args_count == 1]
'''

min_endpoint_version = "8.3.0"
optional_actions = []
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 1

[[actions]]
action = "kill_process"
field = "process.parent.entity_id"
state = 0

[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1059"
name = "Command and Scripting Interpreter"
reference = "https://attack.mitre.org/techniques/T1059/"
[[threat.technique.subtechnique]]
id = "T1059.006"
name = "Python"
reference = "https://attack.mitre.org/techniques/T1059/006/"



[threat.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"
[[threat]]
framework = "MITRE ATT&CK"

[threat.tactic]
id = "TA0011"
name = "Command and Control"
reference = "https://attack.mitre.org/tactics/TA0011/"

[internal]
min_endpoint_version = "8.3.0"

Stages and Predicates

Ordered sequence: each step below must occur in order within 10s, correlated by process.parent.entity_id.

Stage 1: process

[process where event.type == "start" and event.action == "exec" and
  process.name like~ ("zsh", "sh", "bash", "python*", "terminal") and
  process.args == "-c" and
  (
    process.command_line : ("*curl*|*", "*nscurl*|*", "*wget*|*", "*osascript*|*",
                            "*/dev/tcp/*", "*base64*|*", "*openssl*|*", "*nc *|*") or
    process.command_line : ("*curl*>*", "*wget*>*") or
    process.command_line : "*http*|*"
  )]

Stage 2: process

[process where event.type == "start" and event.action == "exec" and 
  process.name like~ ("python*", "perl*", "ruby*", "osascript") and
  process.parent.name in ("sh", "bash", "zsh", "osascript") and 
  process.args like~ ("python*", "perl*", "ruby*", "osascript") and 
  process.args_count == 1]

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
event.actioneq
  • exec
field:"EventType" kind:eq value:"exec"
event.typeeq
  • start
field:"event.type" kind:eq value:"start"
process.argseq
  • -c
field:"process.args" kind:eq value:"-c"
process.argswildcard
  • osascript
  • perl*
  • python*
  • ruby*
field:"process.args" kind:wildcard
process.args_counteq
  • 1 transforms: number
field:"process.args_count" kind:eq value:"1"
process.command_linewildcard
  • */dev/tcp/*
  • *base64*|*
  • *curl*>*
  • *curl*|*
  • *http*|*
  • *nc *|*
  • *nscurl*|*
  • *openssl*|*
  • *osascript*|*
  • *wget*>*
  • *wget*|*
field:"CommandLine" kind:wildcard
process.namewildcard
  • bash
  • osascript
  • perl*
  • python*
  • ruby*
  • sh
  • terminal
  • zsh
field:"process_name" kind:wildcard
process.parent.namein
  • bash
  • osascript
  • sh
  • zsh
field:"parent_process_name" kind:in