Detection rules › Elastic
Suspicious File Overwrite and Modification via Echo
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
| Tactic | Techniques |
|---|---|
| Execution | |
| Stealth |
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.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
process.parent.executable | starts_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.path | wildcard | /private/tmp/docker-desktop-privileged*/exitcode.txt, /Users/*/Library/Logs/zoom.us/crashlog/usage.txt | excludes: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.
| Field | Kind | Values | Search |
|---|---|---|---|
event.action | eq |
| field:"EventType" kind:eq |
event.type | eq |
| field:"event.type" kind:eq value:"start" |
process.Ext.effective_parent.name | is_null | field:"process.Ext.effective_parent.name" kind:is_null | |
process.args | eq |
| field:"process.args" kind:eq value:"-c" |
process.args | wildcard |
| field:"process.args" kind:wildcard |
process.args_count | le |
| field:"process.args_count" kind:le value:"3" |
process.name | in |
| field:"process_name" kind:in |