Detection rules › Elastic

Execution of Memory File Descriptor via Interactive Session

Source
github.com/elastic/protections-artifacts

Detects when a file descriptor in the proc (temporary) file system is executed via an interactive session. This activity indicates an active attempt to execute an in-memory file and should be considered highly abnormal or suspicious. This activity can occur when the memfd syscall is utilized to create a memory resident file, like a payload, and then execute it via command and control.

MITRE ATT&CK coverage

TacticTechniques
Execution
Stealth

Rule body

[rule]
description = """
Detects when a file descriptor in the proc (temporary) file system is executed via an interactive session. This activity
indicates an active attempt to execute an in-memory file and should be considered highly abnormal or suspicious. This
activity can occur when the memfd syscall is utilized to create a memory resident file, like a payload, and then execute
it via command and control.
"""
id = "fbc224a0-5469-4c0c-953d-fc57e0293197"
license = "Elastic License v2"
name = "Execution of Memory File Descriptor via Interactive Session"
os_list = ["linux"]
reference = [
    "https://github.com/MythicAgents/merlin/blob/main/Payload_Type/merlin/container/commands/memfd.go",
    "https://x-c3ll.github.io/posts/fileless-memfd_create/",
]
version = "1.0.22"

query = '''
process where event.type == "start" and event.action == "exec" and process.parent.executable != null and
process.executable regex """/proc/(self|[0-9]{1,7})/fd/[0-9]{1,7}""" and process.interactive == true and
not (
  process.command_line in ("runc init", "/var/gdn/assets/linux/bin/runc init", "/usr/sbin/pfman", "lxc-attach -n rdsd.lv") or
  process.args == "datadog-ipc-helper" or
  process.parent.command_line == "/sbin/init" or
  process.parent.executable in (
    "/usr/sbin/runc", "/usr/libexec/snapd/snap-confine", "/var/lib/snapd/snap/bin/direnv", "/usr/lib/systemd/systemd",
    "/usr/bin/runc", "/usr/bin/login", "/usr/bin/nvidia-cdi-hook", "/usr/bin/buildkit-runc", "/usr/bin/nordlayer",
    "/usr/sbin/nordlayer", "/usr/libexec/nordlayer/nordlayer-setcap", "/sbin/apk", "/opt/sophos-spl/plugins/runtimedetections/bin/runtimedetections"
  ) or
  process.parent.executable like (
    "/proc/self/fd/*/*", "/home/*/.local/share/JetBrains/Toolbox/apps/rider/bin/rider", "/usr/bin/tini",
    "/home/*/.codex/*/codex-linux-sandbox"
  ) or
  (process.parent.name == "init" and process.args == "/usr/lib/systemd/systemd-executor") or
  (process.parent.name like "python*" and process.args == "-m" and process.args == "test.regrtest" and process.args == "--pgo")
)
'''

min_endpoint_version = "8.3.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 = "T1106"
name = "Native API"
reference = "https://attack.mitre.org/techniques/T1106/"


[threat.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1620"
name = "Reflective Code Loading"
reference = "https://attack.mitre.org/techniques/T1620/"


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

[internal]
min_endpoint_version = "8.3.0"

Stages and Predicates

Stage 1: process

process where event.type == "start" and event.action == "exec" and process.parent.executable != null and
process.executable regex """/proc/(self|[0-9]{1,7})/fd/[0-9]{1,7}""" and process.interactive == true and
not (
  process.command_line in ("runc init", "/var/gdn/assets/linux/bin/runc init", "/usr/sbin/pfman", "lxc-attach -n rdsd.lv") or
  process.args == "datadog-ipc-helper" or
  process.parent.command_line == "/sbin/init" or
  process.parent.executable in (
    "/usr/sbin/runc", "/usr/libexec/snapd/snap-confine", "/var/lib/snapd/snap/bin/direnv", "/usr/lib/systemd/systemd",
    "/usr/bin/runc", "/usr/bin/login", "/usr/bin/nvidia-cdi-hook", "/usr/bin/buildkit-runc", "/usr/bin/nordlayer",
    "/usr/sbin/nordlayer", "/usr/libexec/nordlayer/nordlayer-setcap", "/sbin/apk", "/opt/sophos-spl/plugins/runtimedetections/bin/runtimedetections"
  ) or
  process.parent.executable like (
    "/proc/self/fd/*/*", "/home/*/.local/share/JetBrains/Toolbox/apps/rider/bin/rider", "/usr/bin/tini",
    "/home/*/.codex/*/codex-linux-sandbox"
  ) or
  (process.parent.name == "init" and process.args == "/usr/lib/systemd/systemd-executor") or
  (process.parent.name like "python*" and process.args == "-m" and process.args == "test.regrtest" and process.args == "--pgo")
)

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
process.argseq--pgoexcludes:process.args field:"process.args" value:"--pgo"
process.argseq-mexcludes:process.args field:"process.args" value:"-m"
process.argseqtest.regrtestexcludes:process.args field:"process.args" value:"test.regrtest"
process.parent.namestarts_withpythonexcludes:process.parent.name field:"process.parent.name" value:"python"
process.argseq/usr/lib/systemd/systemd-executorexcludes:process.args field:"process.args" value:"/usr/lib/systemd/systemd-executor"
process.parent.nameeqinitexcludes:process.parent.name field:"process.parent.name" value:"init"
process.argseqdatadog-ipc-helperexcludes:process.args field:"process.args" value:"datadog-ipc-helper"
process.command_linein/usr/sbin/pfman, /var/gdn/assets/linux/bin/runc init, lxc-attach -n rdsd.lv, runc initexcludes:process.command_line
process.parent.command_lineeq/sbin/initexcludes:process.parent.command_line field:"process.parent.command_line" value:"/sbin/init"
process.parent.executablein/opt/sophos-spl/plugins/runtimedetections/bin/runtimedetections, /sbin/apk, /usr/bin/buildkit-runc, /usr/bin/login, /usr/bin/nordlayer, /usr/bin/nvidia-cdi-hook, /usr/bin/runc, /usr/lib/systemd/systemd, /usr/libexec/nordlayer/nordlayer-setcap, /usr/libexec/snapd/snap-confine, /usr/sbin/nordlayer, /usr/sbin/runc, /var/lib/snapd/snap/bin/direnvexcludes:process.parent.executable
process.parent.executablewildcard/proc/self/fd/*/*, /home/*/.local/share/JetBrains/Toolbox/apps/rider/bin/rider, /usr/bin/tini, /home/*/.codex/*/codex-linux-sandboxexcludes:process.parent.executable

Indicators

These rows show field, operator, and value matches.