Payload Piped to Script Interpreter


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.

Query · eql

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]
Raw source Payload Piped to Script Interpreter · Elastic TOML
Esc
Published by elastic/protections-artifacts ↗, licensed under Elastic License 2.0 ↗. Reproduced here unmodified.
[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"

Detection rules belong to the projects that publish them and remain under their own licenses. This site indexes and links to them; it claims no rights in them.