-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new(driver, libsinsp, libscap): Add kernel signals exe_ino, exe_ino_ctime, exe_ino_mtime, pidns_init_start_ts + derived filter fields #595
Conversation
This is a huge PR @incertum!
Aside from this, it looks really cool, thank you! |
Hello @incertum! The container drift detection seems to be something really significant, thanks for spending time on it and trying to detect this kind of behavior! The main problem of this approach is that it relies on overlayfs and so it cannot work with old kernels and container runtimes that do not use it. It also needs to be tested across a wider variety of kernels to be sure that it's working, since it was like an experiment for me. I would be happy to know what you think about it! |
@FedeDP ty let me look into @loresuso was actually lurking around that @loresuso more signals are needed for detecting memory attacks or RCE in a more general and robust way (executables are just one aspect), one step at a time though. And I saw you also refactored the Re fetching the container start time or pid namespace creation time works too still monkeying around if this is best implemented kernel side. Something like somehow fetching the start time of pid=1 as seen from process namespace or the creation ts of the pid namespace the process belongs too ... would you have any thoughts on this? |
Hey folks, I'd like to add my thoughts to the discussion since I originally introduced the Regarding attack scenarios, the proposed fields would allow us to add another way to filter events to try and reduce the noise from this kind of rules. I would love for Falco to be able to have a set of rules to deal with the standard "drop + execute" case. This is what comes to mind:
@incertum 's idea I think is definitely clever, as it allows us to add the time dimension to the above. You can say "If a regular user is running an executable that they can modify AND it has been modified 'recently', then alert". This allows us to detect drops without drowning in noise caused by system-wide software updates and new deployments. Same goes for containers. In that case I like the stronger properties of In conclusion, I probably want all of these fields 😎 I actually wanted |
@LucaGuerra ❤️ 😎 as always a fantastic summary and technical assessment of what the actual problem here is. Fully agree that all these signals combined will be super valuable in addition to existing metadata fields. It's nice to see three folks having 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+execute" has not yet been well addressed. Of course the "host" is the more tricky one, doesn't change the fact that I have been asked to fix / solve this ... so thinking we 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. How about first merging @loresuso PR that features
Would you have ideas re what the best forum would be to expand on those Threat Modeling discussions?
Yeah you can never just have nice things in security, hence why I am a big fan of multi-signal correlations. |
Thanks @incertum @LucaGuerra, this conversation is getting more and more interesting! I also believe that we have to expand the conversation (maybe in Slack or a Github issue?) to other attack patterns. I think we may want to research a bit on fileless execution (especially the one implemented with |
Edited: We have moved all brainstorming to #615 in order to keep this PR focused. |
Kernel side solution for robustness reasons: Add pid namespace init task start ts to generically approx container or host start ts and compute time deltas useful for detections, such as container duration or duration between pidns start ts and ctime exe file if pidns ts predates ctime. A general detection use case can be that if suspicious events happen in multiple containers of a deployment near container start it's more likely to be "normal". The longer a container runs the longer it is "exposed". What questions do you have re the proposed approach to solve above? Would it be possible to check soundness of this approach? This would be much appreciated. Initial experimentation seemed correct ts values for various scenarios, but will continue testing. |
Another kernel side signal that would like to look into and possibly add to this PR would be:
Please note, not talking about the use case where you run the interpreter and pass the script, like Any thoughts on above? @LucaGuerra @loresuso @FedeDP @Andreagit97 After that this PR should be feature complete and can start finalizing it, followed by code optimization review. |
d3d1c9d
to
a5510e7
Compare
a5510e7
to
b4b54f4
Compare
Signed-off-by: Melissa Kilby <[email protected]>
Signed-off-by: Melissa Kilby <[email protected]>
Consistently have constant m_boot_ts_epoch for pidns_init_start_ts when vpid != pid. Signed-off-by: Melissa Kilby <[email protected]>
* Add pidns_init_start_time to sched_prog_fork_3. * Ensure consistent unsigned long long usage and init variable properly. Signed-off-by: Melissa Kilby <[email protected]>
…to sched bpfs * cleanup some debugging leftovers. Signed-off-by: Melissa Kilby <[email protected]>
* address minor reviewers comments * properly init some variables to 0 that were overlooked * use new macro CHECK_RES(res) * perform pidns start ts lookup only when in childtid (raw syscall tracepoints) * formalize consistent helper function epoch_ns_from_time also in modern_bpf * minor modern_bpf refactor based on reviewers comments * additional cleanup after a fresh look Co-authored-by: Andrea Terzolo <[email protected]> Signed-off-by: Melissa Kilby <[email protected]>
Signed-off-by: Melissa Kilby <[email protected]>
* remove redudant CHECK_RES(res) when possible * cleanup epoch_ns_from_time helper function * modern_bpf rename function variable for extract__task_pidns_start_time Co-authored-by: Hendrik Brueckner <[email protected]> Signed-off-by: Melissa Kilby <[email protected]>
Signed-off-by: Melissa Kilby <[email protected]>
Signed-off-by: Andrea Terzolo <[email protected]>
Signed-off-by: Andrea Terzolo <[email protected]>
18f1676
to
140f612
Compare
Co-authored-by: Luca Guerra <[email protected]> Signed-off-by: Melissa Kilby <[email protected]>
4693f3a
to
db9270e
Compare
Signed-off-by: Andrea Terzolo <[email protected]>
db9270e
to
074625a
Compare
The last commit should fix windows CI, just removed |
lol classic, thanks for keeping the new more reliable method to get a constant boot ts :) |
Signed-off-by: Andrea Terzolo <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
LGTM label has been added. Git tree hash: 7f7068dcd291f5ed76d4ec430bd06adb37f263bf
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: FedeDP, incertum, LucaGuerra The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind cleanup
/kind feature
Any specific area of the project related to this PR?
/area driver-kmod
/area driver-bpf
/area driver-modern-bpf
/area libscap
/area libsinsp
Does this PR require a change in the driver versions?
/version driver-SCHEMA-version-major
What this PR does / why we need it:
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.
Falco's upstream rules
"Container Drift Detected (chmod)"
and"Container Drift Detected (open+create)"
aim to detect the creation of a new executable in a container (drift). However, both rules are disabled by default, because those rules can be noisy in un-profiled environments and workloads. Finally, currently there are no easy or robust mechanisms to correlate above rules that are based on file operation events with the events where the executable is run (execve
).This PR attempts to address this gap via adding enhanced kernel signals to spawned processes. While the proposed signals won't replace the need to monitor file operation events, they can help reduce the search space for tracking spawned processes where for example
chmod +x
was run against the executable file on disk prior to execution (this causesctime
ofinode
to change, but we don't know if it was chmod related or a different status change operation). In addition, end users could use these fields for selected rules to augment information available for incident response.New derived filter fields based on new kernel signals
"proc.exe_ino"
, "Inode number of executable image file on disk", "The inode number of the executable image file on disk. Can be correlated with fd.ino.""proc.exe_ino.ctime"
, "Last status change time (ctime - epoch ns) of exe file on disk", "Last status change time (ctime - epoch nanoseconds) of executable image file on disk (inode->ctime). Time is changed by writing or by setting inode information e.g. owner, group, link count, mode etc.""proc.exe_ino.mtime"
, "Last modification time (mtime - epoch ns) of exe file on disk", "Last modification time (mtime - epoch nanoseconds) of executable image file on disk (inode->mtime). Time is changed by file modifications, e.g. by mknod, truncate, utime, write of more than zero bytes etc. For tracking changes in owner, group, link count or mode, use proc.exe_ino.ctime instead.""proc.exe_ino.ctime_duration_proc_start"
, "Number of nanoseconds between ctime exe file and proc clone ts", "Number of nanoseconds between modifying status of executable image and spawning a new process using the changed executable image.""proc.exe_ino.ctime_duration_pidns_start"
, "Number of nanoseconds between pidns start ts and ctime exe file", "Number of nanoseconds between pid namespace start ts and ctime exe file if pidns start predates ctime.""proc.pidns_init_start_ts"
, "Start ts of pid namespace (epoch ns)", "Start ts (epoch ns) of pid namespace; approximate start ts of container if pid in container or start ts of host if pid in host namespace.""container.start_ts"
, "Container start ts (epoch in ns)", "Container start ts (epoch in ns) based on proc.pidns_init_start_ts.""container.duration"
, "Number of nanoseconds since the container start ts", "Number of nanoseconds since the container start ts."Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Includes cleanup, mainly make
sched_prog_exec_4
andexecve_family_flags
filler alike in terms of style. Refactored (no logic changes)get_exe_writable
to avoid few redundant_READ()
s on same kernel structures within the same filler (@LucaGuerra).This PR is not yet ready. Hoping for some early feedback to make these new signals better :)
Checklist (this PR)
Checklist (future PR)
Does this PR introduce a user-facing change?: