Dropping an implant, making the file executable and executing the implant is amongst one of the oldest tricks. While memory based cyber attacks mostly circumvent touching disk, reliably detecting drifts, that is, a suspicious new executable is executed is often considered a crucial baseline detection.
Three Falco contributors have come to similar conclusions, that is, (1) it is at process startup where we need to fetch better kernel signals and (2) this old problem "drop+exec" has not yet been well addressed.
This document is for discussing the development of a more generic and robust solution to detect the classic drop an implant and execute it TTP called "drop+exec". In addition, perform threat modeling not limited to this use case, e.g. "fileless" attacks or malicious scripts run by interpreter …
Robust and stable Falco rules that work in new / unknown environments with acceptable FP (False Positives) rate, no FNs (False Negatives). Falco rules shall work especially in containers, hopefully also on the host. Threat actors reading this will need to work harder to circumvent new more robust detections.
@LucaGuerra, @loresuso, @incertum kicked off discussions in below PRs:
exe_writable
- https://github.com/falcosecurity/libs/pull/97 (merged) @LucaGuerraexe_upper_layer
- https://github.com/falcosecurity/libs/pull/287 @loresusoexe_ino
related kernel signals https://github.com/falcosecurity/libs/pull/595 @incertum
Reference libs issue that includes some engineering roadmap.
-> Come up with ways to correlated all those new signals and also leverage existing metadata fields around process collection.
Initial proposal @incertum (2022-11-10): A simple rule like the one proposed below should work well for most end users and environments. Working well means the new Falco rule does not generate too many logs and can be enabled by default. End users likely need some "anomaly detection" that at first can be performed off host. Time between ctime file change and proc clone was choosen to be very conservative for now. It's a paramter end users can tune. %evt.arg.flags
also contains the information from the exe_writable
signal, e.g. "EXE_WRITABLE|EXE_UPPER_LAYER"
- condition: proc.exe_ino.ctime_duration_proc_start <= 3600000000000
macro: executable_drop_exec
- condition: proc.is_exe_upper_layer=true and proc.exe_ino.ctime_duration_pidns_start >= 10000000000
macro: executable_new
- condition: spawned_process and container and executable_drop_exec and executable_new
desc: New executable spawned in container (drop+exec)
enabled: true
output: '%container.id %container.image.repository %container.image.tag %evt.type
%proc.aname[2] %proc.aname[3] %proc.cmdline %proc.cwd %proc.exepath
%proc.loginshellid %proc.name %proc.pid %proc.pname %proc.ppid %proc.sid %proc.sname
%proc.tty %proc.vpgid %user.loginuid %user.name %user.uid %proc.vpid
%evt.arg.flags %fd.name %fd.type %evt.res %k8s.ns.name %k8s.pod.name %proc.exe_ino
%proc.exe_ino.ctime %proc.exe_ino.mtime %proc.exe_ino.ctime_duration_proc_start
%proc.pidns_init_start_ts %proc.exe_ino.ctime_duration_pidns_start'
priority: NOTICE
rule: New executable spawned in container (drop+exec)
tags:
- filesystem
- mitre_execution
@loresuso proposal:
To detect fileless execution done via the attack pattern memfd_create + execve
, I think we have a few alternatives, each one with its pros and cons:
when creating a file descriptor via memfd_create
and then execute, we could try to detect the superblock magic upon execve
event, similar to what we are trying to do with exe_upper_layer
. I believe we might discover that:
resolve the name of the executable on execve and check if it begins with memfd:
. See https://elixir.bootlin.com/linux/v5.19.9/source/mm/memfd.c#L260. I really believe that this would work. However, we cannot blindly resolve the name upon each execve event (I am thinking about using d_path
https://elixir.bootlin.com/linux/v5.19.9/source/fs/d_path.c#L264) because it has a cost, and we don't want to pay it for every execve event, it might slow down too much.
Mix it up!! We could try to understand if the superblock magic can act as a good filter for trying resolving the name, so that we do it only when there is a bigger chance that fileless execution really took place!
// pseudocode
if(sb_magic == MEMFD_MAGIC){
name = d_path(...)
if (name begins with "memfd"){
set new exe_fileless flag
}
}
These are just ideas, they might be completely wrong or maybe they are a candidate to start experimenting, feedback appreciated!
Some relevant references in this line:
Experiments / attempt that did not yet pan out:
LD_PRELOAD
env variable isn't that rare since it was mentioned as possibly easy signalLikely won't get away without determining a pattern of past behavior of the applications that are running, and analyze behaviors outside the past behavior. There will be both data modeling challenges and software implementation challenges, the good news is similar problems have been solved in the industry before and we can build upon this. Needless to say let's start more basic and iterate.
Options and discussion TBA once we finish discussions around better kernel signals …