DR Linux Rule Tuning 8.9 (#2859)

Co-authored-by: Ruben Groenewoud <78494512+Aegrah@users.noreply.github.com>
This commit is contained in:
shashank-elastic
2023-07-10 20:02:42 +05:30
committed by GitHub
parent 1283a21fb7
commit 3ed8c56942
17 changed files with 177 additions and 190 deletions
@@ -9,12 +9,12 @@ updated_date = "2023/06/22"
[rule]
author = ["Elastic"]
description = """
Identifies Linux binary(s) abuse to breakout of restricted shells or environments by spawning an interactive system
shell. The linux utility(s) activity of spawning shell is not a standard use of the binary for a user or system
administrator. It may indicates an attempt to improve the capabilities or stability of an adversary access.
Identifies the abuse of a Linux binary to break out of a restricted shell or environment by spawning an interactive
system shell. The activity of spawning a shell from a binary is not common behavior for a user or system administrator,
and may indicate an attempt to evade detection, increase capabilities or enhance the stability of an adversary.
"""
from = "now-9m"
index = ["logs-endpoint.events.*", "endgame-*"]
index = ["logs-endpoint.events.*"]
language = "eql"
license = "Elastic License v2"
name = "Linux Restricted Shell Breakout via Linux Binary(s)"
@@ -100,61 +100,68 @@ severity = "medium"
tags = ["Domain: Endpoint", "OS: Linux", "Use Case: Threat Detection", "Tactic: Execution", "Data Source: Elastic Endgame"]
timestamp_override = "event.ingested"
type = "eql"
query = '''
process where host.os.type == "linux" and event.type == "start" and
(
/* launch shells from unusual process */
(process.name == "capsh" and process.args == "--") or
/* launching shells from unusual parents or parent+arg combos */
(process.name in ("bash", "sh", "dash","ash") and
(process.parent.name in ("byebug","git","ftp","strace","nawk", "mawk", "awk", "gawk", "tar", "zip")) or
/* shells specified in parent args */
/* nice rule is broken in 8.2 */
(process.parent.args in ("/bin/sh", "/bin/bash", "/bin/dash", "/bin/ash", "sh", "bash", "dash", "ash") and
(
(process.parent.name == "nice") or
(process.parent.name == "cpulimit" and process.parent.args == "-f") or
(process.parent.name == "find" and process.parent.args == "-exec" and process.parent.args == ";") or
(process.parent.name == "flock" and process.parent.args == "-u" and process.parent.args == "/")
)
) or
/* shells specified in args */
(process.args in ("/bin/sh", "/bin/bash", "/bin/dash", "/bin/ash", "sh", "bash", "dash", "ash") and
(process.parent.name == "crash" and process.parent.args == "-h") or
(process.name == "sensible-pager" and process.parent.name in ("apt", "apt-get") and process.parent.args == "changelog")
/* scope to include more sensible-pager invoked shells with different parent process to reduce noise and remove false positives */
)
(
/* launching shell from capsh */
(process.name == "capsh" and process.args == "--") or
/* launching shells from unusual parents or parent+arg combos */
(process.name : "*sh" and (
(process.parent.name : ("byebug", "ftp", "strace", "zip", "*awk", "git", "tar") and
(
process.parent.args : "BEGIN {system(*)}" or
(process.parent.args : ("*PAGER*", "!*sh", "exec *sh") or process.args : ("*PAGER*", "!*sh", "exec *sh")) or
(
(process.parent.args : "exec=*sh" or (process.parent.args : "-I" and process.parent.args : "*sh")) or
(process.args : "exec=*sh" or (process.args : "-I" and process.args : "*sh"))
)
)
) or
(process.name == "busybox" and process.args_count == 2 and process.args in ("/bin/sh", "/bin/bash", "/bin/dash", "/bin/ash", "sh", "bash", "dash", "ash") )or
(process.name == "env" and process.args_count == 2 and process.args in ("/bin/sh", "/bin/bash", "/bin/dash", "/bin/ash", "sh", "bash", "dash", "ash")) or
(process.parent.name in ("vi", "vim") and process.parent.args == "-c" and process.parent.args in (":!/bin/bash", ":!/bin/sh", ":!bash", ":!sh")) or
(process.parent.name in ("c89","c99", "gcc") and process.parent.args in ("sh,-s", "bash,-s", "dash,-s", "ash,-s", "/bin/sh,-s", "/bin/bash,-s", "/bin/dash,-s", "/bin/ash,-s") and process.parent.args == "-wrapper") or
(process.parent.name == "expect" and process.parent.args == "-c" and process.parent.args in ("spawn /bin/sh;interact", "spawn /bin/bash;interact", "spawn /bin/dash;interact", "spawn sh;interact", "spawn bash;interact", "spawn dash;interact")) or
(process.parent.name == "mysql" and process.parent.args == "-e" and process.parent.args in ("\\!*sh", "\\!*bash", "\\!*dash", "\\!*/bin/sh", "\\!*/bin/bash", "\\!*/bin/dash")) or
(process.parent.name == "ssh" and process.parent.args == "-o" and process.parent.args in ("ProxyCommand=;sh 0<&2 1>&2", "ProxyCommand=;bash 0<&2 1>&2", "ProxyCommand=;dash 0<&2 1>&2", "ProxyCommand=;/bin/sh 0<&2 1>&2", "ProxyCommand=;/bin/bash 0<&2 1>&2", "ProxyCommand=;/bin/dash 0<&2 1>&2"))
)
'''
/* shells specified in parent args */
/* nice rule is broken in 8.2 */
(process.parent.args : "*sh" and
(
(process.parent.name == "nice") or
(process.parent.name == "cpulimit" and process.parent.args == "-f") or
(process.parent.name == "find" and process.parent.args == "-exec" and process.parent.args == ";" and process.parent.args == "-p") or
(process.parent.name == "flock" and process.parent.args == "-u" and process.parent.args == "/")
)
)
)) or
/* shells specified in args */
(process.args : "*sh" and (
(process.parent.name == "crash" and process.parent.args == "-h") or
(process.name == "sensible-pager" and process.parent.name in ("apt", "apt-get") and process.parent.args == "changelog")
/* scope to include more sensible-pager invoked shells with different parent process to reduce noise and remove false positives */
)) or
(process.name == "busybox" and event.action == "exec" and process.args_count == 2 and process.args : "*sh" and not process.executable : "/var/lib/docker/overlay2/*/merged/bin/busybox") or
(process.name == "env" and process.args_count == 2 and process.args : "*sh") or
(process.parent.name in ("vi", "vim") and process.parent.args == "-c" and process.parent.args : ":!*sh") or
(process.parent.name in ("c89", "c99", "gcc") and process.parent.args : "*sh,-s" and process.parent.args == "-wrapper") or
(process.parent.name == "expect" and process.parent.args == "-c" and process.parent.args : "spawn *sh;interact") or
(process.parent.name == "mysql" and process.parent.args == "-e" and process.parent.args : "\\!*sh") or
(process.parent.name == "ssh" and process.parent.args == "-o" and process.parent.args : "ProxyCommand=;*sh 0<&2 1>&2")
)
'''
[[rule.threat]]
framework = "MITRE ATT&CK"
[[rule.threat.technique]]
id = "T1059"
name = "Command and Scripting Interpreter"
reference = "https://attack.mitre.org/techniques/T1059/"
[[rule.threat.technique.subtechnique]]
id = "T1059.004"
name = "Unix Shell"
reference = "https://attack.mitre.org/techniques/T1059/004/"
[rule.threat.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"