Challenge
DifficultyMedium
Learner activity No attempts yet

Detect Shells in Pods With Falco

Install Falco with the modern eBPF driver on a Kubernetes worker node, add a custom rule for shells started in Pods, and find its alert in the Falco service logs. Practice loading custom Falco rules and reading their alerts.

Scenario

Attackers often run single commands in a container through a shell, for example bash -c. Nobody on your team notices this today. The security team wants an alert for it and asked you to set up Falco. The built-in rules of Falco already report interactive shells, so the team wrote a rule for the other ones.

The cluster has two nodes:

  • cplane-01 runs the control plane and has a NoSchedule taint.
  • node-01 is the only worker node. Your Pods run here, so Falco must run here too.

kubectl works on both nodes.

This is the rule of the security team:

- rule: Shell Spawned in Pod
  desc: Detect a shell started inside a Kubernetes pod
  condition: spawned_process and container and proc.name in (bash, sh)
  output: Shell in pod (ns=%k8s.ns.name pod=%k8s.pod.name container=%container.name user=%user.name cmd=%proc.cmdline)
  priority: WARNING

Task

  1. Install Falco on node-01 with the modern eBPF driver, as described in Install on a host (DEB, RPM). The service must run and start again after a reboot.
  2. Add the rule, unchanged, on node-01 in a file that a Falco upgrade does not overwrite. Leave the default rules file as it is.
  3. Validate both rules files, and make sure that the running Falco raises the alert of the custom rule.
  4. Create a Pod named falco-test in the default namespace with the image nginx:stable. Run a single command in it through bash or sh, without a terminal.
  5. Save the Falco service logs from the systemd journal to /home/laborant/falco.log on node-01. The file must contain the alert of the custom rule for your shell.

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:

Hint 2: Custom rules

The rules_files setting in /etc/falco/falco.yaml lists the files that Falco loads, in order. One of them is meant for your own rules.

Validate it with falco together with the default rules file, because the rule uses macros from there.

Docs:

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.

A shell opened with kubectl exec -it matches a built-in rule first, so by default you see only the built-in alert for it. The -c flag of a shell runs a single command.

Docs:


⚒ Test Cases

Problem
Solution
Start