File Creation or Modification via (Memory) File Descriptor
Description
This rule detects when a process creates a (memory) file descriptor and creates, or modifies, a file. This behavior may indicate the creation of a second stage payload, after the first fileless stage has executed.
Query · eql
file where event.type != "deletion" and (
process.executable regex """/proc/(self|[0-9]{1,7})/fd/[0-9]{1,7}""" or
process.executable like ("memfd:*", "?memfd:*")
) and
file.path like (
"/tmp/*", "/var/tmp/*", "/dev/shm/*", "/run/user/*", "/var/run/user/*", "/boot/*",
"/lost+found/*", "/var/mail/*", "/var/www/*", "/home/*/*", "/root/*"
) and
not (
process.executable like ("?memfd:/sophos-subprocess-*-exec*", "memfd:/sophos-subprocess-*-exec*") or
process.executable in (
"memfd:spawn_worker_trampoline", "memfd:buildah-chroot-runtime", "memfd:lxc-attach",
"memfd:teleport-sessionhelper", "memfd:buildah-chroot-exec"
) or
(process.executable == "/memfd: (deleted)" and file.path like "/var/tmp/etilqs_*") or
file.path like (
"/tmp/tmp.*", "/tmp/syft-cataloger-*/*", "/home/*/.local/state/wireplumber/*",
"/run/user/0/systemd/units/invocation:gpg-agent.socket", "/run/user/0/systemd/units/invocation:ssh-agent.socket"
)
)