Detection rules › Elastic

Background Process Execution via Shell

Source
github.com/elastic/protections-artifacts

Detects when a binary located in a suspicious location gets executed by a shell interpreter and put in the background via the & operator. Malwares may execute their payloads in the background in an effort to remain hidden.

MITRE ATT&CK coverage

Telemetry coverage

Rule body

[rule]
description = """
Detects when a binary located in a suspicious location gets executed by a shell interpreter and put in the background
via the & operator. Malwares may execute their payloads in the background in an effort to remain hidden.
"""
id = "603ac59e-9cca-4c48-9750-e38399079043"
license = "Elastic License v2"
name = "Background Process Execution via Shell"
os_list = ["macos"]
version = "1.0.19"

query = '''
process where event.type == "start" and event.action == "exec" and 
    process.name like~ ("bash", "sh", "zsh", "tclsh*") and
    process.args == "-c" and process.args like~ ("/* &", "/*&") and
    process.args_count == 3 and 
    process.parent.executable like~ 
                                ("/private/tmp/*", 
                                 "/var/tmp/*", 
                                 "/tmp/*", 
                                 "/var/folders/*", 
                                 "/Library/Containers/*", 
                                 "/Library/Graphics/*",
                                 "/Users/Shared/*", 
                                 "/Users/*/Library/Preferences/*", 
                                 "/var/root/*", 
                                 "/Library/WebServer/*", 
                                 "/Library/Preferences/*", 
                                 "/Library/Services/*", 
                                 "/Library/Fonts/*", 
                                 "/usr/local/bin/*")
'''

min_endpoint_version = "8.10.2"
optional_actions = []
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 0

[[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.004"
name = "Unix Shell"
reference = "https://attack.mitre.org/techniques/T1059/004/"



[threat.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"

[internal]
min_endpoint_version = "8.10.2"

Stages and Predicates

Stage 1: process

process where event.type == "start" and event.action == "exec" and 
    process.name like~ ("bash", "sh", "zsh", "tclsh*") and
    process.args == "-c" and process.args like~ ("/* &", "/*&") and
    process.args_count == 3 and 
    process.parent.executable like~ 
                                ("/private/tmp/*", 
                                 "/var/tmp/*", 
                                 "/tmp/*", 
                                 "/var/folders/*", 
                                 "/Library/Containers/*", 
                                 "/Library/Graphics/*",
                                 "/Users/Shared/*", 
                                 "/Users/*/Library/Preferences/*", 
                                 "/var/root/*", 
                                 "/Library/WebServer/*", 
                                 "/Library/Preferences/*", 
                                 "/Library/Services/*", 
                                 "/Library/Fonts/*", 
                                 "/usr/local/bin/*")

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
  • /* &
  • /*&
field:"process.args" kind:wildcard
process.args_counteq
  • 3 transforms: number
field:"process.args_count" kind:eq value:"3"
process.namewildcard
  • bash
  • sh
  • tclsh*
  • zsh
field:"process_name" kind:wildcard
process.parent.executablewildcard
  • /Library/Containers/*
  • /Library/Fonts/*
  • /Library/Graphics/*
  • /Library/Preferences/*
  • /Library/Services/*
  • /Library/WebServer/*
  • /Users/*/Library/Preferences/*
  • /Users/Shared/*
  • /private/tmp/*
  • /tmp/*
  • /usr/local/bin/*
  • /var/folders/*
  • /var/root/*
  • /var/tmp/*
field:"ParentImage" kind:wildcard