mcpField
D
detecting-container-escape-with-falco-rules

detecting-container-escape-with-falco-rules

github.com/mukul975セキュリティ35.2k83 回インストール8 週間前に更新
リポジトリ

detecting-container-escape-with-falco-rules について

コンテナセキュリティ担当者やSOC分析者向けのFalcoルール検知スキルです。コンテナエスケープの検知例に加え、導入、アラート設定、ルールのテストと調整手順を提供します。

主な機能

  1. 01ホストマウントと名前空間エスケープの検知
  2. 02特権コンテナとカーネルモジュール読み込みの監視
  3. 03ホストの機密パスとDocker socketアクセスの検出
  4. 04FalcoルールとJSONアラートの設定
  5. 05ルールのテストと誤検知の調整

活用シーン

  1. 01Kubernetesノードでのエスケープ監視の導入
  2. 02コンテナによるホスト機密リソースへのアクセス調査
  3. 03カスタムFalcoルールの検証
  4. 04FalcoアラートのSlack転送

インストール

コマンドをコピーしてターミナルで実行します。

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

インストール後、Claude Code で/detecting-container-escape-with-falco-rulesを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

LICENSE
assets/
template.md
references/
api-reference.md
standards.md
workflows.md
scripts/
agent.py
process.py

詳細

Falco ルールによるコンテナエスケープの検知

概要

Falco は、Linux のシステムコールを監視して異常なコンテナの挙動を検知する、CNCF の卒業プロジェクトであるランタイムセキュリティツールです。ルールエンジンを使用して、ホストのファイルシステムのマウント、機密性の高いホストパスへのアクセス、カーネルモジュールのロード、特権コンテナの機能の悪用など、コンテナエスケープの手法を特定します。

使用する場面

  • Falco ルールを使ったコンテナエスケープの検知が必要なセキュリティインシデントを調査する場合
  • この分野の検知ルールや脅威ハンティング用クエリを作成する場合
  • SOC アナリストがこの種の分析に関する体系的な手順を必要とする場合
  • 関連する攻撃手法に対するセキュリティ監視のカバレッジを検証する場合

前提条件

  • eBPF ドライバーを使用する場合はカーネル 5.8 以降、またはカーネルモジュールをサポートする Linux ホスト
  • Kubernetes クラスター(v1.24 以降)、またはスタンドアロンの Docker/containerd
  • Kubernetes へのデプロイには Helm 3
  • ドライバーのインストールに必要な root または特権アクセス

Falco のインストール

Helm を使用した Kubernetes へのデプロイ
# Add Falco Helm chart
helm repo add falcosecurity https://falcosecurity.github.io/charts
helm repo update

# Install Falco with eBPF driver
helm install falco falcosecurity/falco \
  --namespace falco --create-namespace \
  --set falcosidekick.enabled=true \
  --set falcosidekick.webui.enabled=true \
  --set driver.kind=ebpf \
  --set collectors.containerd.enabled=true \
  --set collectors.containerd.socket=/run/containerd/containerd.sock

# Verify
kubectl get pods -n falco
kubectl logs -n falco -l app.kubernetes.io/name=falco --tail=20
スタンドアロンインストール(Debian/Ubuntu)
# Add Falco GPG key and repo
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
sudo apt-get install -y falco

# Start Falco
sudo systemctl enable falco
sudo systemctl start falco

コンテナエスケープ検知ルール

ルール 1:コンテナからのホストマウントを検知
- rule: Container Mounting Host Filesystem
  desc: Detect a container attempting to mount the host filesystem
  condition: >
    spawned_process and container and
    proc.name = mount and
    (proc.args contains "/host" or proc.args contains "nsenter")
  output: >
    Container mounting host filesystem
    (user=%user.name container_id=%container.id container_name=%container.name
     image=%container.image.repository command=%proc.cmdline %evt.args)
  priority: CRITICAL
  tags: [container, escape, T1611]
ルール 2:nsenter の使用(名前空間エスケープ)を検知
- rule: Nsenter Execution in Container
  desc: Detect nsenter being used to escape container namespaces
  condition: >
    spawned_process and container and proc.name = nsenter
  output: >
    nsenter executed in container - potential escape attempt
    (user=%user.name container_id=%container.id image=%container.image.repository
     command=%proc.cmdline parent=%proc.pname)
  priority: CRITICAL
  tags: [container, escape, namespace, T1611]
ルール 3:特権コンテナの起動を検知
- rule: Launch Privileged Container
  desc: Detect a privileged container being launched
  condition: >
    container_started and container and container.privileged=true
  output: >
    Privileged container started
    (user=%user.name container_id=%container.id container_name=%container.name
     image=%container.image.repository)
  priority: WARNING
  tags: [container, privileged, T1610]
ルール 4:/proc/sysrq-trigger への書き込みを検知
- rule: Write to Sysrq Trigger
  desc: Detect writes to /proc/sysrq-trigger which can crash or control the host
  condition: >
    open_write and container and fd.name = /proc/sysrq-trigger
  output: >
    Write to /proc/sysrq-trigger from container
    (user=%user.name container_id=%container.id image=%container.image.repository
     command=%proc.cmdline)
  priority: CRITICAL
  tags: [container, escape, host-manipulation]
ルール 5:コンテナからのカーネルモジュールのロードを検知
- rule: Container Loading Kernel Module
  desc: Detect a container attempting to load a kernel module
  condition: >
    spawned_process and container and
    (proc.name in (insmod, modprobe) or
     (proc.name = init_module))
  output: >
    Kernel module loading from container
    (user=%user.name container_id=%container.id image=%container.image.repository
     command=%proc.cmdline)
  priority: CRITICAL
  tags: [container, escape, kernel, T1611]
ルール 6:cgroups 経由のコンテナブレイクアウトを検知
- rule: Write to Cgroup Release Agent
  desc: Detect writes to cgroup release_agent which is a known container escape vector
  condition: >
    open_write and container and
    fd.name endswith release_agent
  output: >
    Container writing to cgroup release_agent - escape attempt
    (user=%user.name container_id=%container.id image=%container.image.repository
     file=%fd.name command=%proc.cmdline)
  priority: CRITICAL
  tags: [container, escape, cgroup, CVE-2022-0492]
ルール 7:ホストの /etc/shadow へのアクセスを検知
- rule: Container Reading Host Shadow File
  desc: Detect a container reading /etc/shadow on the host via mounted volume
  condition: >
    open_read and container and
    (fd.name = /etc/shadow or fd.name startswith /host/etc/shadow)
  output: >
    Container reading host shadow file
    (user=%user.name container_id=%container.id image=%container.image.repository
     file=%fd.name command=%proc.cmdline)
  priority: CRITICAL
  tags: [container, credential-access, T1003]
ルール 8:Docker ソケットへのアクセスを検知
- rule: Container Accessing Docker Socket
  desc: Detect a container accessing the Docker socket which allows host control
  condition: >
    (open_read or open_write) and container and
    fd.name = /var/run/docker.sock
  output: >
    Container accessing Docker socket
    (user=%user.name container_id=%container.id image=%container.image.repository
     command=%proc.cmdline)
  priority: CRITICAL
  tags: [container, escape, docker-socket, T1610]

カスタムルールファイルの全体例

# /etc/falco/rules.d/container-escape.yaml
- list: escape_binaries
  items: [nsenter, chroot, unshare, mount, umount, pivot_root]

- macro: container_escape_attempt
  condition: >
    spawned_process and container and
    proc.name in (escape_binaries)

- rule: Container Escape Binary Execution
  desc: Detect execution of binaries commonly used for container escape
  condition: container_escape_attempt
  output: >
    Escape-related binary executed in container
    (user=%user.name container=%container.name image=%container.image.repository
     command=%proc.cmdline parent=%proc.pname pid=%proc.pid)
  priority: CRITICAL
  tags: [container, escape, mitre_T1611]

- rule: Sensitive File Access from Container
  desc: Detect container access to sensitive host files
  condition: >
    (open_read or open_write) and container and
    (fd.name startswith /proc/1/ or
     fd.name = /etc/shadow or
     fd.name = /etc/kubernetes/admin.conf or
     fd.name startswith /var/lib/kubelet/)
  output: >
    Sensitive file accessed from container
    (container=%container.name image=%container.image.repository
     file=%fd.name command=%proc.cmdline user=%user.name)
  priority: CRITICAL
  tags: [container, sensitive-file, mitre_T1005]

Falco の設定

# /etc/falco/falco.yaml (key settings)
rules_files:
  - /etc/falco/falco_rules.yaml
  - /etc/falco/rules.d/container-escape.yaml

json_output: true
json_include_output_property: true
json_include_tags_property: true

log_stderr: true
log_syslog: true
log_level: info

priority: WARNING

stdout_output:
  enabled: true

syslog_output:
  enabled: true

http_output:
  enabled: true
  url: http://falcosidekick:2801
  insecure: true

grpc:
  enabled: true
  bind_address: "unix:///run/falco/falco.sock"
  threadiness: 8

grpc_output:
  enabled: true

アラート連携

Falcosidekick 経由で Slack に転送
# Falcosidekick values.yaml
config:
  slack:
    webhookurl: "https://hooks.slack.com/services/XXXXX"
    minimumpriority: "warning"
    messageformat: |
      *{{.Priority}}* - {{.Rule}}
      Container: {{.OutputFields.container_name}}
      Image: {{.OutputFields.container_image_repository}}
      Command: {{.OutputFields.proc_cmdline}}

ルールのテスト

# Simulate container escape attempt (in a test container)
kubectl run test-escape --image=alpine --restart=Never -- sh -c "cat /etc/shadow"

# Simulate nsenter
kubectl run test-nsenter --image=alpine --restart=Never --overrides='{"spec":{"hostPID":true}}' -- nsenter -t 1 -m -u -i -n -- cat /etc/hostname

# Check Falco alerts
kubectl logs -n falco -l app.kubernetes.io/name=falco --tail=50 | grep -i escape

ベストプラクティス

  1. Falco を DaemonSet としてデプロイし、すべてのノードを確実にカバーします
  2. カーネルモジュールより eBPF ドライバーを使用し、安全性を高めます
  3. デフォルトのルール(maturity_stable)から始め、その後カスタムルールを追加します
  4. Falcosidekick 経由でアラートを SIEM/SOAR に転送します
  5. 相関分析のため、ルールに MITRE ATT&CK の手法 ID をタグ付けします
  6. ルールをテストし、強制適用の前に許可モードで動作を確認します
  7. 既知の正常なプロセスに対する例外リストを追加し、誤検知を調整します
  8. Prometheus のメトリクスエンドポイントで Falco の健全性を監視します

コメント