The Build Host That Answered Anyone: Inspecting Containers Through an Open Docker API
The challenge
Mossgate's build-07 has a new open port. Use the open Docker API to inspect containers. Get the private registry's S3 secret key.
What you'll learn
- Find an exposed Docker Engine API with a full port scan
- Map docker ps and docker inspect to their Engine API endpoints
- Read a container's environment from Config.Env with curl and grep
- Tell a Docker Hub pull-through mirror from a private registry
- Lock down the Docker daemon and keep secrets out of environment variables
Skills tested
Prerequisites
- Using curl
- Basic grep
- What a Docker container is
How it works
The Docker CLI is only a client: every docker command is an HTTP call to the daemon's Engine API, normally over the Unix socket /var/run/docker.sock. When the daemon is also started with -H tcp://0.0.0.0:2375 and no TLS, that API answers anyone who can reach the port, with no password. /info even carries the daemon's own warning that remote access is equivalent to root on the host.
The endpoints mirror the commands: GET /containers/json is docker ps and GET /containers/<name or id>/json is docker inspect. Inspect returns the container's full configuration, including Config.Env, every environment variable it was started with. Many images are configured entirely through the environment: the distribution registry maps REGISTRY_STORAGE_S3_* variables onto its storage settings, keys included.
Scanning for open 2375 and harvesting credentials from containers is a staple of cloud botnets (TeamTNT, Kinsing, the 2024 Commando Cat campaign), which then start miners or backdoored containers. Note that 2375 is not in nmap's default top 1000 ports: a quick scan misses it, a full -p- scan does not.
Common mistakes
- Looking for a docker CLI. It is not installed and is not needed:
curlspeaks the same API. - Searching the container list for secrets.
/containers/jsonshows names, images and labels, not the environment. Inspect one container to getConfig.Env. - Taking the mirror's key.
registry-mirroris listed first and has the same variable names, butREGISTRY_PROXY_REMOTEURLmakes it a Docker Hub cache, writing tomossgate-hub-cache. Its secretXr5mTb8Lh2WqZ9vNc4Kd1Js7Pf3Ga6Ye0Uo+Bt2Eis not the private registry's. - Answering the access key ID.
REGISTRY_STORAGE_S3_ACCESSKEY(AKIA5TQZRW3LN7XJMBHC) is the public half of the pair; the secret isREGISTRY_STORAGE_S3_SECRETKEY. - Taking another secret.
REGISTRY_HTTP_SECRETonly signs upload state, andREGISTRY_PROXY_PASSWORDis the mirror's Docker Hub token. - Reaching for exec.
POST /containers/registry/execgets a 403 from the daemon's authorization plugin, which refuses exec and new containers. It lets every read through, and inspect is a read.
How to defend against it
- Never expose the daemon on TCP without TLS: keep the default Unix socket, or use
--tlsverifywith client certificates, or reach remote hosts withDOCKER_HOST=ssh://user@host. - Firewall 2375 and 2376 and alert on them in network sweeps, with full-range scans.
- Keep credentials out of environment variables: anyone who can inspect a container reads them. Prefer an IAM role (instance profile) for S3, or Docker secrets mounted as files.
- An authorization plugin that only blocks writes is not a fix: inspect, logs and file downloads are reads, and they carry the secrets.
- Scope storage keys to one bucket, and rotate every key a reachable daemon exposed.