Detection rules › Elastic
Payload Piped to Script Interpreter
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
| Tactic | Techniques |
|---|---|
| Execution |
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.
| Field | Kind | Values | Search |
|---|---|---|---|
event.action | eq |
| field:"EventType" kind:eq value:"exec" |
event.type | eq |
| field:"event.type" kind:eq value:"start" |
process.args | eq |
| field:"process.args" kind:eq value:"-c" |
process.args | wildcard |
| field:"process.args" kind:wildcard |
process.args_count | eq |
| field:"process.args_count" kind:eq value:"1" |
process.command_line | wildcard |
| field:"CommandLine" kind:wildcard |
process.name | wildcard |
| field:"process_name" kind:wildcard |
process.parent.name | in |
| field:"parent_process_name" kind:in |