mcpField
D
detecting-container-runtime-threats-with-falco

detecting-container-runtime-threats-with-falco

github.com/mukul975安全35.2k49 次安装8 周前更新
代码仓库

关于 detecting-container-runtime-threats-with-falco

面向容器与 Kubernetes 安全人员的 Falco 技能,指导编写、部署和验证运行时威胁检测规则。内容涵盖容器逃逸、命名空间操作、特权挂载和反向 Shell 等行为。

主要功能

  1. 01部署并确认 Falco 驱动
  2. 02编写规则、宏和列表
  3. 03检测容器逃逸与异常行为
  4. 04验证规则并触发告警
  5. 05通过 Falcosidekick 转发告警

适用场景

  1. 01为 Kubernetes 或 Docker 构建运行时检测
  2. 02通过紫队演练验证逃逸告警
  3. 03针对新披露的运行时 CVE 增加规则
  4. 04将 Falco 告警转发到 SIEM

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill detecting-container-runtime-threats-with-falco

安装后在 Claude Code 中输入/detecting-container-runtime-threats-with-falco确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

LICENSE
references/
api-reference.md
standards.md
scripts/
agent.py

详细介绍

使用 Falco 检测容器运行时威胁

概述

Falco 是 CNCF 毕业的运行时安全项目(最初由 Sysdig 开发),它通过驱动程序消费 Linux 内核系统调用和 Kubernetes 审计事件,依据 YAML 规则引擎对其进行评估,并发出实时告警。它是容器内运行时威胁事实上的开源检测工具,涵盖容器逃逸(MITRE ATT&CK T1611,Escape to Host)、命名空间操纵(setns)、特权挂载、反弹 shell 以及异常出站连接。

Falco 支持三种驱动:modern eBPF 探针(首选默认,要求内核 >= 5.8,直接内置在 Falco 二进制文件中,因此无需 init 容器)、旧版 eBPF 探针以及内核模块(kmod)。驱动选择通过 falcoctl driver config --type {kmod|ebpf|modern_ebpf} 或 Helm chart 中的 driver.kind=modern_ebpf 完成。在 Kubernetes 上,Falco 以 DaemonSet 方式运行,因此每个节点都受到监控,并且 falcoctl 会自动从 Falco 规则仓库安装和更新规则制品。

本技能涵盖编写和部署自定义 Falco 规则,以检测本合集所涉及的突破技术产生的容器逃逸原语和异常行为信号。每条 Falco 规则包含字段 rule、desc、condition、output、priority 以及可选的 tags;可复用逻辑被抽取到 macro 和 list 对象中。来源:falco.org 官方文档;falcosecurity/rules 仓库;Sysdig Falco 检测研究(例如 CVE-2025-22224)。

何时使用

  • 为 Kubernetes 或 Docker 环境构建运行时检测
  • 验证容器逃逸和横向移动尝试会产生告警(紫队)
  • 为新披露的运行时 CVE 增加覆盖
  • 加固 SOC 的容器遥测管道(Falco -> Falcosidekick -> SIEM)

前置条件

  • 你管理的 Linux 主机(modern eBPF 需要内核 >= 5.8)或 Kubernetes 集群
  • 安装 Falco:
    # Helm (Kubernetes, modern eBPF, JSON output for SIEM ingest)
    helm repo add falcosecurity https://falcosecurity.github.io/charts
    helm repo update
    helm install falco falcosecurity/falco \
      --namespace falco --create-namespace \
      --set driver.kind=modern_ebpf \
      --set collectors.containerd.enabled=true \
      --set falco.json_output=true \
      --set tty=true
    
    # Linux package install (Debian/Ubuntu)
    curl -fsSL https://falco.org/repo/falcosecurity-packages.asc | \
      sudo gpg --dearmor -o /usr/share/keyrings/falco-archive-keyring.gpg
    echo "deb [signed-by=/usr/share/keyrings/falco-archive-keyring.gpg] \
      https://download.falco.org/packages/deb stable main" | \
      sudo tee /etc/apt/sources.list.d/falcosecurity.list
    sudo apt-get update -y && sudo apt-get install -y falco
    
  • 基本熟悉 Falco 字段(evt.type、proc.name、container.id、fd.name)

目标

  • 使用 modern eBPF 驱动安装 Falco
  • 理解 rule/macro/list schema 以及关键的 Falco 过滤字段
  • 为容器逃逸、setns、特权挂载、敏感文件读取和反弹 shell 编写自定义规则
  • 加载自定义规则并验证语法
  • 触发并确认检测(紫队验证)
  • 通过 Falcosidekick 将告警转发到 SIEM

MITRE ATT&CK 映射

技术 ID名称战术
T1611Escape to HostPrivilege Escalation
T1059.004Command and Scripting Interpreter: Unix ShellExecution
T1610Deploy ContainerDefense Evasion / Execution
T1543Create or Modify System ProcessPersistence
T1071.001Application Layer Protocol: Web ProtocolsCommand and Control

工作流

步骤 1:安装 Falco 并确认驱动
# Kubernetes: confirm the DaemonSet is running on every node
kubectl get pods -n falco -o wide
kubectl logs -n falco -l app.kubernetes.io/name=falco | grep -i "driver"

# Linux host: configure driver and start
sudo falcoctl driver config --type modern_ebpf
sudo systemctl enable --now falco-modern-bpf.service
sudo systemctl status falco-modern-bpf.service
步骤 2:了解 Rule、Macro 和 List Schema

自定义规则位于 /etc/falco/falco_rules.local.yaml 或 /etc/falco/rules.d/,由 /etc/falco/falco.yaml 中的 rules_files 引用。

# /etc/falco/rules.d/custom-escape.yaml
- list: shell_binaries
  items: [bash, sh, zsh, dash, ash, ksh]

- macro: spawned_process
  condition: evt.type in (execve, execveat) and evt.dir = <

- macro: container
  condition: container.id != host
步骤 3:编写容器逃逸检测规则(release_agent / cgroup)
- rule: Container Escape via cgroup release_agent
  desc: >
    Detect a process inside a container writing to a cgroup release_agent or
    notify_on_release file, a classic privileged-container breakout primitive.
  condition: >
    container
    and spawned_process
    and (evt.type in (open, openat, openat2) or evt.type=write)
    and (fd.name endswith "release_agent"
         or fd.name endswith "notify_on_release")
    and evt.is_open_write=true
  output: >
    Container escape attempt via cgroup release_agent
    (user=%user.name command=%proc.cmdline file=%fd.name
     container=%container.name image=%container.image.repository)
  priority: CRITICAL
  tags: [container, mitre_privilege_escalation, T1611]
步骤 4:检测命名空间突破(setns / nsenter)
- rule: Namespace Change via setns to Host
  desc: >
    Detect setns/nsenter used to enter the host namespace (e.g. nsenter -t 1),
    a common container-to-host escape technique.
  condition: >
    evt.type = setns
    and container
    and proc.name in (nsenter, unshare)
  output: >
    Namespace breakout via setns/nsenter
    (user=%user.name proc=%proc.name cmd=%proc.cmdline
     container=%container.name image=%container.image.repository)
  priority: CRITICAL
  tags: [container, mitre_privilege_escalation, T1611]
步骤 5:检测特权挂载和 Docker Socket 滥用
- rule: Mount Launched in Privileged Container
  desc: Detect the mount binary running inside a privileged container.
  condition: >
    spawned_process
    and container
    and container.privileged = true
    and proc.name = mount
  output: >
    Mount executed in privileged container
    (cmd=%proc.cmdline container=%container.name image=%container.image.repository)
  priority: WARNING
  tags: [container, mitre_privilege_escalation, T1611]

- rule: Docker Socket Accessed From Container
  desc: A container process reads/writes the host Docker daemon socket.
  condition: >
    container
    and (evt.type in (open, openat, openat2, connect))
    and fd.name = /var/run/docker.sock
  output: >
    Container touched docker.sock - possible daemon-API escape
    (proc=%proc.name cmd=%proc.cmdline container=%container.name)
  priority: CRITICAL
  tags: [container, mitre_execution, T1610]
步骤 6:检测反弹 Shell 和敏感文件读取
- rule: Reverse Shell From Container
  desc: A shell in a container with stdin/stdout wired to a network socket.
  condition: >
    spawned_process
    and container
    and proc.name in (shell_binaries)
    and (fd.num in (0, 1, 2))
    and fd.type in (ipv4, ipv6)
  output: >
    Reverse shell detected in container
    (proc=%proc.cmdline connection=%fd.name container=%container.name)
  priority: CRITICAL
  tags: [container, mitre_execution, T1059.004]

- rule: Read Sensitive Host File From Container
  desc: Container reads /etc/shadow or similar after a likely escape.
  condition: >
    container
    and (evt.type in (open, openat, openat2))
    and evt.is_open_read=true
    and fd.name in (/etc/shadow, /etc/sudoers, /root/.ssh/id_rsa)
  output: >
    Sensitive file read from container (file=%fd.name proc=%proc.cmdline
     container=%container.name)
  priority: WARNING
  tags: [container, mitre_credential_access]
步骤 7:验证规则语法并加载
# Dry-run validate a rules file without starting the engine
sudo falco --validate /etc/falco/rules.d/custom-escape.yaml

# Run Falco with only the custom rules to test
sudo falco -r /etc/falco/rules.d/custom-escape.yaml

# Helm: ship custom rules via values (mounted into /etc/falco/rules.d)
helm upgrade falco falcosecurity/falco -n falco --reuse-values \
  --set-file "customRules.custom-escape\.yaml"=./custom-escape.yaml
步骤 8:触发并确认(紫队)
# In a test container, trigger the setns rule
kubectl run pwn --rm -it --image=alpine --overrides='
{"spec":{"hostPID":true,"containers":[{"name":"pwn","image":"alpine",
"securityContext":{"privileged":true},"stdin":true,"tty":true,
"command":["sh"]}]}}' -- sh -c 'nsenter -t 1 -m -u -i -n -p -- id'

# Confirm the alert fired
kubectl logs -n falco -l app.kubernetes.io/name=falco | grep -i "Namespace breakout"
步骤 9:将告警转发到 SIEM
# Deploy Falcosidekick to fan out alerts (Elastic, Slack, Splunk, etc.)
helm upgrade falco falcosecurity/falco -n falco --reuse-values \
  --set falcosidekick.enabled=true \
  --set falcosidekick.config.elasticsearch.hostport=https://elastic:9200 \
  --set falcosidekick.config.elasticsearch.index=falco

工具与资源

工具用途来源
Falco运行时系统调用检测引擎https://falco.org
falcoctl驱动 + 规则工件管理器https://github.com/falcosecurity/falcoctl
falcosecurity/rules官方维护的默认规则集https://github.com/falcosecurity/rules
Falcosidekick向 SIEM/聊天工具分发告警https://github.com/falcosecurity/falcosidekick
Falco Helm chartKubernetes DaemonSet 部署https://github.com/falcosecurity/charts

关键 Falco 过滤字段

字段含义
evt.type系统调用名称(execve、setns、open、connect)
evt.dir事件方向(< 退出,> 进入)
proc.name / proc.cmdline进程名称 / 完整命令行
container.id / container.privileged容器标识 / 特权标志
container.image.repository镜像名称
fd.name / fd.type文件/socket 路径 / 类型(ipv4、ipv6)
evt.is_open_write / evt.is_open_read打开意图
user.name操作用户

验证标准

  • 使用现代 eBPF 驱动安装 Falco(在所有节点上以 DaemonSet 部署)
  • 使用 falco --validate 验证自定义规则文件
  • 已加载 release_agent / setns / privileged-mount / docker.sock 规则
  • 已加载反弹 shell 和敏感文件读取规则
  • 每条规则均在实验环境中触发,并在日志中确认告警
  • 已适当设置优先级(逃逸原语使用 CRITICAL)
  • 已通过 Falcosidekick 将告警转发至 SIEM
  • 规则标签包含相关的 MITRE 技术 ID

评论

支持 Markdown