iac.htora.dev · security templates

Home/Templates/Catch attackers at work on a server

Catch attackers at work on a server

Falco on plain Linux hosts, alerting on web shells, credential theft, and new programs in system folders.

Ansible

Why bother

A server outside a Kubernetes cluster is attacked the same way as a pod inside one. A web server starts a shell. A stolen tool reads cloud credentials, or a download tool asks the metadata service for the instance's keys. A program lands in /usr/bin. Falco watches system calls and alerts on each as it happens.

How you know it worked

On a test cloud host, curl the metadata service address. The instance credentials alert reaches syslog within seconds.

How it works

1A program does somethingstarts a shell, opens a file, connects out2Falco sees the system callthrough its eBPF driver3A rule matchesthe host rules here plus Falco's defaults4The alert goes to syslog as JSONand on through the host log template
Step by step, from the thing that happens to the result you want.

Set it up

Pick your platform, then open the level you want. Each level is complete on its own. Read the comments in the files as you go. Anything with a real consequence is explained on the line where it happens.

Ansible. Falco with the modern eBPF driver, rules in /etc/falco/rules.d

What you need first

  • An inventory, and an account you can become root with.
  • A kernel with BTF for the modern eBPF driver, which current distribution kernels have. Standard can use the kernel module driver instead.
  • The Falco .deb or .rpm URL from download.falco.org/packages, and its SHA-256.

What it creates

  • Falco, installed without prompts, with the modern eBPF driver and automatic rules updates off
  • Rules for a shell started by a network service, cloud credentials read by an unexpected program, and instance credentials fetched by a download tool
  • JSON alerts to syslog
  • A rule for new files in system binary folders, tunable lists, your own rules, a minimum priority, and a dry run of every rule before restart (Standard)

See the four alerts this creates

The code

Quick startReadyone file, 146 lines
One playbook. A checksummed install and three host rules, alerting to syslog as JSON.
Change these first
  • falco_package_url: "" playbook.yml, line 28
  • falco_package_sha256: "" playbook.yml, line 29
Run it
  1. ansible all -i inventory.ini -m ping
    Proves Ansible can reach every machine before anything changes.
  2. ansible-playbook -i inventory.ini playbook.yml --check --diff
    Shows each change it would make, line by line. Changes nothing.
  3. ansible-playbook -i inventory.ini playbook.yml
    Makes the change.
  4. ansible-playbook -i inventory.ini playbook.yml
    Run it once more. The recap should end with changed=0.

No inventory yet? A one-machine inventory.ini:

[all]
web-01 ansible_host=10.0.0.11 ansible_user=ubuntu
Download playbook.yml
Checks

Syntax passedAnsible lint passed

Last run 2026-10-02.

outcomes/host-runtime-detection/linux/t0
playbook.yml
Open playbook.yml as plain text
StandardReadysix files, 204 lines
A role. Adds a system binary folder rule, tunable lists, your own rules, a minimum priority, a driver choice, and a dry run before restart.
Run it
  1. ansible all -i inventory.ini -m ping
    Proves Ansible can reach every machine before anything changes.
  2. ansible-playbook -i inventory.ini site.yml --check --diff
    Shows each change it would make, line by line. Changes nothing.
  3. ansible-playbook -i inventory.ini site.yml
    Makes the change.
  4. ansible-playbook -i inventory.ini site.yml
    Run it once more. The recap should end with changed=0.

No inventory yet? A one-machine inventory.ini:

[all]
web-01 ansible_host=10.0.0.11 ansible_user=ubuntu
Download all six files as a zip
Checks

Syntax passedAnsible lint passed

Last run 2026-10-02.

outcomes/host-runtime-detection/linux/t1
roles/falco/defaults/main.yml
Open main.yml as plain text
roles/falco/handlers/main.yml
Open main.yml as plain text
roles/falco/meta/main.yml
Open main.yml as plain text
roles/falco/tasks/main.yml
Open main.yml as plain text
roles/falco/templates/50-iac-host.yaml.j2
Open 50-iac-host.yaml.j2 as plain text
site.yml
Open site.yml as plain text
HardenedReadythree files, 145 lines
Standard's roles, unchanged, with your settings in settings.yml. Rules refuse settings that turn on automatic rule updates, raise the minimum priority, empty the service list, trust a shell or download tool with credentials, or disable or redefine a host rule. A daily check-mode run reports drift, and ansible-lint runs on the production profile.
Run it
  1. ansible all -i inventory.ini -m ping
    Proves Ansible can reach every machine before anything changes.
  2. ansible-playbook -i inventory.ini site.yml --check --diff
    Shows each change it would make, line by line. Changes nothing.
  3. ansible-playbook -i inventory.ini site.yml
    Makes the change.
  4. ansible-playbook -i inventory.ini site.yml
    Run it once more. The recap should end with changed=0.

No inventory yet? A one-machine inventory.ini:

[all]
web-01 ansible_host=10.0.0.11 ansible_user=ubuntu
Download all three files as a zip
Checks

Syntax passedAnsible lint passed

Last run 2026-10-02.

outcomes/host-runtime-detection/linux/t2
guard.yml
Open guard.yml as plain text
settings.yml
Open settings.yml as plain text
site.yml
Open site.yml as plain text

How to check it worked

curl -s http://169.254.169.254/ on a test cloud host, then journalctl -t falco shows the instance credentials alert.

What catches people

A rule that does not compile stops Falco from starting, which ends detection on that host. Standard checks the new rules file with Falco before it replaces the old one, and loads everything with falco --dry-run before a restart. A bad rule fails the run, and the old file stays in place.

The allow lists are where rules go quiet. Keep them short, and review every addition like a firewall change.

How to undo it

Remove the falco package. Alerts already forwarded stay in the SIEM.

What it costs

Nothing to license. A few percent of CPU on busy hosts, depending on the rules loaded.

Good to know

  • These are the Kubernetes template's ideas for servers outside a cluster. The same Falco default rules load underneath.
  • Automatic rules updates are off, so the rules running are the ones reviewed. Update Falco's package on purpose to get new defaults.

Registry 0.23.0. Built 2026-11-17.

Made by Habibullah Tora. Source on GitHub. Code under the MIT licence, writing under CC BY 4.0.