mcpField
D
detecting-container-escape-attempts

detecting-container-escape-attempts

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

detecting-container-escape-attempts について

セキュリティ運用分析担当者向けのコンテナエスケープ検出スキルです。Falco、監査ルール、ランタイム監視を使って兆候を特定する手順を示します。

主な機能

  1. 01システムコールとプロセス活動の監視
  2. 02名前空間とケイパビリティの悪用検出
  3. 03機密マウントとファイル変更の監視
  4. 04Falcoカスタム検出ルールの設定
  5. 05アラートパイプラインによるイベント転送

活用シーン

  1. 01コンテナエスケープ関連インシデントの調査
  2. 02検出ルールと脅威ハンティングクエリの作成
  3. 03ランタイム監視範囲の検証

インストール

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

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

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

同梱ファイル

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

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

詳細

コンテナーエスケープの試行を検知する

概要

コンテナーエスケープは、攻撃者がコンテナーの分離を突破し、ホストシステムや他のコンテナーにアクセスする重大な攻撃手法です。検知では、Falco、Sysdig などのランタイムセキュリティツールやカスタム seccomp/audit ルールを使用し、名前空間の操作、ケイパビリティの悪用、カーネルエクスプロイト、機密パスのマウント、異常なシステムコールのパターンなどのエスケープの兆候を監視します。

使用する場面

  • コンテナーエスケープの試行を検知する必要があるセキュリティインシデントを調査する場合
  • この領域の検知ルールや脅威ハンティングクエリを作成する場合
  • SOC アナリストが、この種の分析に関する体系的な手順を必要とする場合
  • 関連する攻撃手法に対するセキュリティ監視の適用範囲を検証する場合

前提条件

  • カーネル 5.10 以降を搭載した Linux ホスト(eBPF をサポート)
  • Falco 0.37 以降がインストール済み(カーネルモジュールまたは eBPF プローブ)
  • Docker Engine または containerd ランタイム
  • auditd が設定済み
  • eBPF/カーネルモジュールの読み込みに必要な root アクセス

基本概念

一般的なコンテナーエスケープの手法
手法テクニックMITRE ID
特権コンテナーホストファイルシステムをマウントする、カーネルモジュールを読み込むT1611
Docker ソケットのマウント内部から特権コンテナーを作成するT1610
カーネルエクスプロイトCVE-2022-0185(fsconfig)、Dirty Pipe、runc の CVET1068
ケイパビリティの悪用CAP_SYS_ADMIN、CAP_SYS_PTRACE、CAP_NET_ADMINT1548
機密性の高いマウント/proc/sysrq-trigger、/proc/kcore、cgroup release_agentT1611
名前空間からのエスケープnsenter、unshare によるホスト名前空間への移行T1611
シンボリックリンク/バインドマウント/proc/self/root を経由したエスケープT1611
検知レイヤー
  1. システムコールの監視 - eBPF/カーネルモジュールでシステムコールをリアルタイムに取得します
  2. ファイル整合性 - エスケープを可能にするパスの変更を検知します
  3. プロセスの監視 - プロセスの作成や名前空間の変更を追跡します
  4. ネットワークの監視 - コンテナーからホストへの接続を検知します
  5. 監査ログ - ケイパビリティやマウント操作を Linux auditd で記録します

ワークフロー

ステップ 1:ランタイム検知用に Falco をデプロイする
# falco-values.yaml for Helm deployment
falco:
  driver:
    kind: ebpf   # or modern_ebpf for kernel 5.8+
  rules_files:
    - /etc/falco/falco_rules.yaml
    - /etc/falco/falco_rules.local.yaml
    - /etc/falco/rules.d
  json_output: true
  json_include_output_property: true
  http_output:
    enabled: true
    url: "http://falcosidekick:2801"
  grpc:
    enabled: true
  priority: warning
# Install Falco via Helm
helm repo add falcosecurity https://falcosecurity.github.io/charts
helm install falco falcosecurity/falco \
  --namespace falco-system --create-namespace \
  -f falco-values.yaml
ステップ 2:エスケープ検知用のカスタム Falco ルール
# /etc/falco/rules.d/container_escape.yaml

# Detect container escape via privileged container
- rule: Container Escape via Privileged Mode
  desc: Detect attempts to escape container using privileged capabilities
  condition: >
    spawned_process and container and
    (proc.name in (nsenter, unshare, mount, umount, modprobe, insmod) or
     (proc.name = chroot and proc.args contains "/host"))
  output: >
    Container escape attempt via privileged operation
    (user=%user.name container=%container.name image=%container.image.repository
     command=%proc.cmdline pid=%proc.pid %container.info)
  priority: CRITICAL
  tags: [container, escape, T1611]

# Detect Docker socket access from container
- rule: Container Access to Docker Socket
  desc: Detect container reading/writing to Docker socket
  condition: >
    (open_read or open_write) and container and
    fd.name = /var/run/docker.sock
  output: >
    Docker socket accessed from container
    (user=%user.name container=%container.name image=%container.image.repository
     fd=%fd.name command=%proc.cmdline %container.info)
  priority: CRITICAL
  tags: [container, escape, docker_socket]

# Detect sensitive proc filesystem access
- rule: Container Access to Sensitive Proc Paths
  desc: Detect container accessing host-sensitive proc paths
  condition: >
    open_read and container and
    (fd.name startswith /proc/sysrq-trigger or
     fd.name startswith /proc/kcore or
     fd.name startswith /proc/kmsg or
     fd.name startswith /proc/kallsyms or
     fd.name startswith /sys/kernel)
  output: >
    Sensitive proc/sys access from container
    (user=%user.name container=%container.name path=%fd.name
     command=%proc.cmdline %container.info)
  priority: CRITICAL
  tags: [container, escape, proc_access]

# Detect cgroup escape technique
- rule: Container Cgroup Escape Attempt
  desc: Detect writing to cgroup release_agent (escape technique)
  condition: >
    open_write and container and
    (fd.name contains release_agent or
     fd.name contains notify_on_release)
  output: >
    Cgroup escape attempt detected
    (user=%user.name container=%container.name path=%fd.name
     command=%proc.cmdline %container.info)
  priority: CRITICAL
  tags: [container, escape, cgroup]

# Detect kernel module loading from container
- rule: Container Loading Kernel Module
  desc: Detect container attempting to load kernel modules
  condition: >
    spawned_process and container and
    (proc.name in (modprobe, insmod, rmmod) or
     (evt.type = init_module or evt.type = finit_module))
  output: >
    Kernel module load attempt from container
    (user=%user.name container=%container.name command=%proc.cmdline
     %container.info)
  priority: CRITICAL
  tags: [container, escape, kernel_module]

# Detect namespace manipulation
- rule: Container Namespace Manipulation
  desc: Detect setns/unshare syscalls from container
  condition: >
    container and (evt.type = setns or evt.type = unshare) and
    not proc.name in (containerd-shim, runc)
  output: >
    Namespace manipulation from container
    (user=%user.name container=%container.name syscall=%evt.type
     command=%proc.cmdline %container.info)
  priority: CRITICAL
  tags: [container, escape, namespace]

# Detect mount operations from container
- rule: Container Mount Sensitive Filesystem
  desc: Detect container mounting host filesystems
  condition: >
    spawned_process and container and proc.name = mount and
    (proc.args contains "/dev/" or proc.args contains "proc" or
     proc.args contains "sysfs")
  output: >
    Sensitive mount operation from container
    (user=%user.name container=%container.name command=%proc.cmdline
     %container.info)
  priority: HIGH
  tags: [container, escape, mount]
ステップ 3:エスケープ防止用の Seccomp プロファイルを設定する
{
  "defaultAction": "SCMP_ACT_ERRNO",
  "archMap": [
    { "architecture": "SCMP_ARCH_X86_64", "subArchitectures": ["SCMP_ARCH_X86", "SCMP_ARCH_X32"] }
  ],
  "syscalls": [
    {
      "names": [
        "read", "write", "open", "close", "stat", "fstat", "lstat",
        "poll", "lseek", "mmap", "mprotect", "munmap", "brk",
        "rt_sigaction", "rt_sigprocmask", "ioctl", "access",
        "pipe", "select", "sched_yield", "dup", "dup2",
        "nanosleep", "getpid", "socket", "connect", "accept",
        "sendto", "recvfrom", "bind", "listen", "getsockname",
        "getpeername", "socketpair", "setsockopt", "getsockopt",
        "clone", "fork", "vfork", "execve", "exit", "wait4",
        "kill", "getuid", "getgid", "geteuid", "getegid",
        "epoll_create", "epoll_wait", "epoll_ctl", "epoll_create1",
        "futex", "set_tid_address", "set_robust_list",
        "openat", "newfstatat", "readlinkat", "fchownat",
        "clock_gettime", "clock_getres", "clock_nanosleep",
        "getrandom", "memfd_create", "statx", "rseq"
      ],
      "action": "SCMP_ACT_ALLOW"
    },
    {
      "names": ["unshare", "setns", "mount", "umount2", "pivot_root",
                "init_module", "finit_module", "delete_module",
                "kexec_load", "kexec_file_load", "ptrace",
                "reboot", "swapon", "swapoff", "sethostname",
                "setdomainname", "keyctl", "bpf"],
      "action": "SCMP_ACT_LOG",
      "comment": "Log escape-relevant syscalls for detection"
    }
  ]
}
ステップ 4:コンテナーエスケープ用の監査ルール
# /etc/audit/rules.d/container-escape.rules

# Monitor namespace operations
-a always,exit -F arch=b64 -S setns -S unshare -k container_escape
-a always,exit -F arch=b64 -S mount -S umount2 -k container_mount
-a always,exit -F arch=b64 -S init_module -S finit_module -S delete_module -k kernel_module
-a always,exit -F arch=b64 -S ptrace -k process_trace

# Monitor sensitive paths
-w /var/run/docker.sock -p rwxa -k docker_socket
-w /proc/sysrq-trigger -p w -k sysrq
-w /proc/kcore -p r -k kcore_read

# Monitor container runtime
-w /usr/bin/runc -p x -k container_runtime
-w /usr/bin/containerd -p x -k container_runtime
-w /usr/bin/docker -p x -k container_runtime
ステップ 5:リアルタイムのアラートパイプライン
# Falcosidekick configuration for alert routing
config:
  slack:
    webhookurl: "https://hooks.slack.com/services/xxx"
    minimumpriority: "critical"
    messageformat: |
      *Container Escape Alert*
      Rule: {{ .Rule }}
      Priority: {{ .Priority }}
      Output: {{ .Output }}

  elasticsearch:
    hostport: "https://elasticsearch:9200"
    index: "falco-alerts"
    minimumpriority: "warning"

  pagerduty:
    routingkey: "xxxx"
    minimumpriority: "critical"

検証コマンド

# Test Falco rules with event generator
kubectl run falco-event-generator \
  --image=falcosecurity/event-generator \
  --restart=Never \
  -- run syscall --action PtraceAttachContainer

# Check Falco alerts
kubectl logs -n falco-system -l app.kubernetes.io/name=falco --tail=50

# Verify seccomp profile is loaded
docker inspect --format '{{.HostConfig.SecurityOpt}}' <container-id>

# Check audit logs for escape-related events
ausearch -k container_escape --interpret

参考資料

コメント