Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

4.7 KB
Raw Blame
id: privileged-container-run
version: 5
title: Container started with host-escaping privileges
description: >
  A docker/podman run or exec — including Compose v2 (`docker compose run`) and the
  legacy `docker-compose` binary — grants container-escape primitives: --privileged,
  host namespace sharing (--pid/--net/--network/--ipc/--uts host), a root-filesystem
  bind mount (-v /:..., --volume=/:..., or --mount with source=/), a kernel capability
  add (--cap-add), or a mount of the docker socket. The docker/podman token is
  anchored to command/segment start (allowing a flagged sudo, env, or VAR=value
  prefix) so it is not matched inside an unrelated commit message.
severity: high
status: stable
posture: detect
taxonomy:
  beacon_category: risky-command
  owasp_llm: LLM06
  mitre_atlas: AML.T0050

match: >
  e.event.action == "command.executed" &&
  e.command.command.matches("(?i)(^|;|&&|\\|\\|)\\s*(sudo(\\s+-\\S+)*\\s+|env\\s+|([A-Za-z_][A-Za-z0-9_]*=\\S*\\s+)+)*(docker|podman)(-compose)?\\s+(container\\s+|compose\\s+)?(run|exec)\\b") &&
  e.command.command.matches("(?i)(--privileged|--(pid|net|network|ipc|uts)[= ]host|(-v|--volume)(=|\\s+)['\"]?/:|--mount[= ]\\S*\\b(source|src)=/(,|['\"]|\\s|$)|--cap-add[= ]|/var/run/docker\\.sock\\b)")

emit:
  reason: "Container started with host-escaping privileges"

tests:
  - name: docker_run_privileged
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "docker run --privileged -v /:/host ubuntu sh" }
        session: { id: s1 }
  - name: docker_container_run_privileged
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "docker container run --privileged ubuntu" }
        session: { id: s1 }
  - name: docker_compose_run_privileged
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "docker compose run --privileged web" }
        session: { id: s1 }
  - name: docker_compose_legacy_binary
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "docker-compose run --privileged web" }
        session: { id: s1 }
  - name: podman_run_host_pid
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "podman run --pid host alpine ps aux" }
        session: { id: s1 }
  - name: docker_run_ipc_host
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "docker run --ipc=host ubuntu" }
        session: { id: s1 }
  - name: m_varprefix
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "DOCKER_HOST=tcp://x docker run --privileged ubuntu" }
        session: { id: s1 }
  - name: m_sudoE
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "sudo -E docker run --cap-add=SYS_ADMIN ubuntu" }
        session: { id: s1 }
  - name: volume_equals_root_bind
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "docker run --volume=/:/host ubuntu chroot /host" }
        session: { id: s1 }
  - name: mount_flag_root_bind
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "docker run --mount type=bind,source=/,target=/host ubuntu" }
        session: { id: s1 }
  - name: quoted_mount_root_bind_source_last
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "docker run --mount \"type=bind,target=/host,source=/\" ubuntu" }
        session: { id: s1 }
  - name: quoted_volume_root_bind
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "docker run -v '/:/host' ubuntu chroot /host" }
        session: { id: s1 }
  - name: quoted_mount_project_bind
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "docker run --mount \"type=bind,source=/src/app,target=/app\" node:20 npm test" }
        session: { id: s1 }
  - name: mount_flag_project_bind
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "docker run --mount type=bind,source=/src/app,target=/app node:20 npm test" }
        session: { id: s1 }
  - name: docker_run_normal
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "docker run --rm -it node:20 npm test" }
        session: { id: s1 }
  - name: docker_in_commit_message
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "git commit -m 'docker run --net=host fix'" }
        session: { id: s1 }