Skip to content

Lesson 3 of 9 · 27m

Image Layers, Volumes, and Runtime State

Interpret overlay filesystems, image history, mounts, deleted files, and runtime configuration to separate attacker changes from the base image.

Container filesystem analysis is where careful investigators start making confident mistakes. The container root filesystem is usually a composite: read-only image layers, a writable upper layer, bind mounts, tmpfs mounts, and orchestrator-injected files. Copy one directory without understanding that composition and you may miss attacker changes or blame the image vendor for the intrusion.

OverlayFS is the mental model

A typical overlay mount looks like this in host mount metadata:

type=overlay
lowerdir=/var/lib/docker/overlay2/l/AB12:.../CD34
upperdir=/var/lib/docker/overlay2/9f.../diff
merged=/var/lib/docker/overlay2/9f.../merged

The merged view is what the container sees. The upper directory receives writes. Whiteout files represent deletions. A file absent from the merged view may still exist in a lower layer or may have been hidden by a whiteout. Resolve actual paths through metadata rather than guessing:

docker inspect 4f7c9c... --format '{{json .GraphDriver.Data}}' | jq
crictl inspect 9c31d... | jq '.info.runtimeSpec.mounts'

Separate image content from attacker content

Image history explains which instructions created which layers:

docker image inspect nginx:1.27 --format '{{json .RootFS.Layers}}' | jq
docker history --no-trunc nginx:1.27

An entrypoint script baked into the image is not attacker-authored merely because it is unfamiliar. Conversely, /tmp/.x/cache in the writable upper layer deserves scrutiny even if it uses a system-sounding name.

For containerd, namespaces matter:

sudo ctr -n k8s.io images list
sudo ctr -n k8s.io snapshots ls
sudo ctr -n moby content ls

Kubernetes commonly uses k8s.io; Docker's containerd integration uses moby. "No images" often means you queried the wrong namespace.

Deleted does not mean unreachable

Open descriptors can keep deleted executables alive:

sudo ls -l /proc/23841/exe
sudo ls -l /proc/23841/fd | grep deleted

A process can execute /tmp/payload, unlink it, and continue running from the inode. /proc/<pid>/exe may still expose it. If you recover content through that symlink, document that it is runtime state, not a normal filesystem copy.

Mounts and injected files break the clean-image story

Kubernetes injects service account tokens, ConfigMaps, Secrets, downward API data, hosts, and resolv.conf. Docker and Kubernetes can also bind host paths. Inspect mounts before interpreting files:

{"source":"/var/lib/kubelet/pods/7b.../volumes/kubernetes.io~secret/token",
 "destination":"/var/run/secrets/kubernetes.io/serviceaccount","type":"bind"}

A token file inside the container is normal platform behavior. The question is whether an attacker read it, replayed it, or caused it to be mounted where it should not have been.

Runtime configuration is causal evidence

Inspect environment, command, user, capabilities, privileged mode, and namespace sharing:

docker inspect 4f7c9c... --format '{{json .Config}}' | jq
crictl inspect 9c31d... | jq '.info.runtimeSpec.linux.securityContext'

privileged: true, host PID or network namespaces, SYS_ADMIN, writable host mounts, and dangerous binaries are not just hardening findings. They explain escape and lateral-movement paths.

Field notes

  • The upper layer is high-value, but lower layers are needed to understand what changed.
  • Never interpret a path before checking whether it is image content, tmpfs, a volume, or a host mount.
  • docker commit is not a forensic acquisition format.
  • Docker, containerd, and CRI-O store state differently. Version details matter.

Was this lesson helpful?

Sign in to rate