Detection rules › Elastic

Suspicious File Overwrite and Modification via Echo

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

Detects the abnormal use of the echo command via a shell to write text into a file located in a suspicious location. Threat actors have used this as a method for creating second stage payloads on systems after initial access has been achieved.

MITRE ATT&CK coverage

Telemetry coverage

Rule body

[rule]
description = """
Detects the abnormal use of the echo command via a shell to write text into a file located in a suspicious location.
Threat actors have used this as a method for creating second stage payloads on systems after initial access has been
achieved.
"""
id = "cd3a06dc-58c3-4d57-a03a-0d8991f237e7"
license = "Elastic License v2"
name = "Suspicious File Overwrite and Modification via Echo"
os_list = ["macos"]
version = "1.0.22"

query = '''
sequence by process.entity_id with maxspan=20s
[process where event.type == "start" and event.action == "exec" and 
    process.name in ("bash", "sh", "zsh") and
    process.args == "-c" and
    process.args like~ ("echo* > /.*", 
                        "echo* > /usr/local/bin/*", 
                        "echo* > ~/.*", 
                        "echo* > /tmp/*", 
                        "echo* > /var/root/*", 
                        "echo* > /private/tmp/*", 
                        "echo* > /var/tmp/*", 
                        "echo* > /var/folders/*", 
                        "echo* > /Library/*", 
                        "echo* > /Users/*", 
                        "echo* > ~/*") and 
    process.args_count <= 3 and 
    process.Ext.effective_parent.name == null and 
    not process.parent.executable like ("/Library/Developer/*", "/Applications/Xcode.app/Contents/*")]
[file where event.action == "modification" and process.name in ("sh", "zsh", "bash") and
    not file.path like~ ("/private/tmp/docker-desktop-privileged*/exitcode.txt", "/Users/*/Library/Logs/zoom.us/crashlog/usage.txt")]
'''

min_endpoint_version = "8.5.0"
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/"
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1027"
name = "Obfuscated Files or Information"
reference = "https://attack.mitre.org/techniques/T1027/"


[threat.tactic]
id = "TA0005"
name = "Defense Evasion"
reference = "https://attack.mitre.org/tactics/TA0005/"

[internal]
min_endpoint_version = "8.5.0"

Stages and Predicates

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

Stage 1: process

[process where event.type == "start" and event.action == "exec" and 
    process.name in ("bash", "sh", "zsh") and
    process.args == "-c" and
    process.args like~ ("echo* > /.*", 
                        "echo* > /usr/local/bin/*", 
                        "echo* > ~/.*", 
                        "echo* > /tmp/*", 
                        "echo* > /var/root/*", 
                        "echo* > /private/tmp/*", 
                        "echo* > /var/tmp/*", 
                        "echo* > /var/folders/*", 
                        "echo* > /Library/*", 
                        "echo* > /Users/*", 
                        "echo* > ~/*") and 
    process.args_count <= 3 and 
    process.Ext.effective_parent.name == null and 
    not process.parent.executable like ("/Library/Developer/*", "/Applications/Xcode.app/Contents/*")]

Stage 2: file

[file where event.action == "modification" and process.name in ("sh", "zsh", "bash") and
    not file.path like~ ("/private/tmp/docker-desktop-privileged*/exitcode.txt", "/Users/*/Library/Logs/zoom.us/crashlog/usage.txt")]

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
process.parent.executablestarts_with/Library/Developer/, /Applications/Xcode.app/Contents/excludes:process.parent.executable field:"process.parent.executable" value:"/Library/Developer/" field:"process.parent.executable" value:"/Applications/Xcode.app/Contents/"
file.pathwildcard/private/tmp/docker-desktop-privileged*/exitcode.txt, /Users/*/Library/Logs/zoom.us/crashlog/usage.txtexcludes:file.path field:"file.path" value:"/private/tmp/docker-desktop-privileged*/exitcode.txt" field:"file.path" value:"/Users/*/Library/Logs/zoom.us/crashlog/usage.txt"

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
event.actioneq
  • exec
  • modification
field:"EventType" kind:eq
event.typeeq
  • start
field:"event.type" kind:eq value:"start"
process.Ext.effective_parent.nameis_null
  • (no value, null check)
field:"process.Ext.effective_parent.name" kind:is_null
process.argseq
  • -c
field:"process.args" kind:eq value:"-c"
process.argswildcard
  • echo* > /.*
  • echo* > /Library/*
  • echo* > /Users/*
  • echo* > /private/tmp/*
  • echo* > /tmp/*
  • echo* > /usr/local/bin/*
  • echo* > /var/folders/*
  • echo* > /var/root/*
  • echo* > /var/tmp/*
  • echo* > ~/*
  • echo* > ~/.*
field:"process.args" kind:wildcard
process.args_countle
  • 3 transforms: number
field:"process.args_count" kind:le value:"3"
process.namein
  • bash
  • sh
  • zsh
field:"process_name" kind:in