Detect Download Tools in Pods With Falco
Scenario
Attackers who get into a container often fetch their tools with curl or wget.
The default rules of Falco have no rule for these commands, so the security team wrote one
and asked you to add it.
All Pods run on node-01, the only worker node of the cluster. kubectl works on both node-01 and cplane-01.
This is the rule of the security team:
- rule: Download Tool in Container
desc: Detect curl or wget started inside a container
condition: spawned_process and container and proc.name in (curl, wget)
output: "[CUSTOM] Download tool run (pod=%k8s.pod.name ns=%k8s.ns.name cmd=%proc.cmdline)"
priority: WARNING
tags: [custom]
Task
- Install Falco on
node-01with the modern eBPF driver (see Install on a host (DEB, RPM)). Its service must be running and start after a reboot. - Add the rule above to Falco on
node-01, without changing it. Use either of these two places:- the local rules file,
/etc/falco/falco_rules.local.yaml - a new rules file of your own in
/etc/falco/rules.d/, with any name that ends in.yaml
Do not edit the default rules file,/etc/falco/falco_rules.yaml. - the local rules file,
- Create a Pod named
falco-testin thedefaultnamespace with the imagenginx:stable, and runcurl https://labs.iximiuz.com/in it. - Save the logs of the Falco service to
/home/laborant/falco.logonnode-01. They must contain the alert for thiscurlcommand.
Hint 1: Installing Falco
The Falco docs show how to trust the key of the Falco repository, add the repository, and install the package.
During the installation, Falco asks which driver to use.
The modern eBPF driver needs a recent kernel, so check the kernel of node-01 with uname -r first.
The name of the systemd service that Falco runs depends on the driver you choose.
Docs:
- Install on a host (DEB, RPM) (Falco)
- Kernel Events (Falco)
Hint 2: Custom rules
The rules_files setting in /etc/falco/falco.yaml lists the files and directories from which Falco loads rules, in order.
The local rules file and rules.d are already in the list, so the configuration needs no change.
Adding the rule to one of them is enough.
The custom rule uses macros from the default rules file, so validate the two files together with the -V flag of falco.
The service logs show which rules files the running Falco has loaded.
Docs:
- Basic Elements of Falco Rules (Falco)
- Custom Ruleset (Falco)
Hint 3: Reading the alerts
journalctl shows the logs of a single systemd unit.
Look for the text that starts the output of the custom rule.
Docs:
- Falco Outputs (Falco)
- journalctl(1) (Linux manual page)