متقدم
البحث فيأدلة «كيف»
طريقة البحث
  • اكتب المهمة بكلماتك (find port، open firewall، disk full) أو الصق رسالة الخطأ بين علامتي تنصيص.
  • اختر «الإجابة السريعة» لترى الأوامر فقط، أو مجالًا لتبقى في مجال واحد.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

كيف 126Security · Runtime

How to detect a shell in a container with Falco

Containers in production should only run their app. A shell started inside one — kubectl exec, or an attacker using a hole in the app — is a strong sign of trouble. Falco watches system calls with eBPF and raises an alert when such things happen: shells, writes to /etc, reading secrets, unexpected network connections. This how-to installs Falco, triggers a test alert, adds your own rule, and sends alerts where people see them.

  • 5 الدروس
  • 8 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

126.1

The quick answer

FALCO_FRONTEND=noninteractive FALCO_DRIVER_CHOICE=modern_ebpf dnf -y install falco
systemctl enable --now falco-modern-bpf.service
docker run --rm -it alpine:3.22 sh -c 'echo test'
journalctl -u falco-modern-bpf -n 20 --output cat | grep -i shell

(Add the Falco repository first — see the full guide.) In Kubernetes install it as a DaemonSet with the Helm chart.

126.2

Step by step

  1. Install (quick answer, or Helm for Kubernetes):
helm repo add falcosecurity https://falcosecurity.github.io/charts
helm upgrade --install falco falcosecurity/falco -n falco --create-namespace --set driver.kind=modern_ebpf
  1. Trigger a test — open a shell in a running container:
kubectl exec -it deploy/api -n shop -- sh -c 'id'

Falco logs a line like:

Notice A shell was spawned in a container with an attached terminal (user=root container=api pod=api-6d8f9c7b5d-x2kq9 ns=shop image=registry.example.com/shop/api)
  1. Your own rule — in your own file (never edit the shipped rules):
/etc/falco/rules.d/shop.yaml
- list: shell_binaries_shop
  items: [bash, sh, zsh, ash, dash]
 
- rule: Shell in shop container
  desc: A shell started inside a shop container
  condition: >
    spawned_process and container
    and proc.name in (shell_binaries_shop)
    and k8s.ns.name = "shop"
  output: >
    Shell in shop container (user=%user.name cmd=%proc.cmdline pod=%k8s.pod.name image=%container.image.repository)
  priority: WARNING
  tags: [container, shell]
falco --dry-run
systemctl restart falco-modern-bpf
  1. Tune the noise — allow known, expected processes (a backup job, a debug tool) with exceptions in your file, instead of turning rules off.
  2. Send alerts out — logs alone are not alerts. Use Falcosidekick (Slack, Teams, Alertmanager, Loki, SIEM) or json_output: true and ship the journal to your SIEM.
  3. React: who ran it (kubectl audit log for exec), which Pod, which image — then isolate (NetworkPolicy deny-all, scale to 0, keep the node for forensics).

126.3

Check that it worked

systemctl status falco-modern-bpf (or the Falco Pods) is running, the test exec produces an alert within seconds, your own rule fires for the shop namespace, and the alert reaches the channel where on-call people see it.

الأوامر في هذا الدرس

126.4

Common problems

ProblemCauseFix
Falco does not start (driver error)Kernel too old for modern_ebpf.Use a newer kernel (5.8+), or the ebpf/kmod driver.
No k8s.* fields in alertsNo container runtime metadata.Run as the Helm DaemonSet; check the container runtime socket settings.
Hundreds of alerts per hourDefault rules match normal tools.Add exceptions for known processes; review noisy rules.
Your rule never firesCondition too narrow, or file not loaded.falco --dry-run (checks config and all rule files); falco -L lists the loaded rules; test step by step.
Alerts only in the local logNo output configured.Falcosidekick or ship JSON logs to the SIEM.
Performance worrieseBPF overhead.Normally small; monitor CPU; limit custom rules to needed syscalls.

الأوامر في هذا الدرس

126.5

Go further

1Why is a shell inside a production container worth an alert?

Containers should only run their app; a shell means manual access or an attacker.

2Where do you put your own Falco rules?

In your own files (/etc/falco/rules.d/ or falco_rules.local.yaml), never in the shipped rules file.

كل الأوامر في هذا الفصل