| name | docker-forensics |
| description | Perform forensic analysis on Docker containers and images. Use this skill whenever investigating compromised containers, analyzing suspicious Docker images, extracting credentials from container memory, or comparing container states. Trigger when users mention Docker forensics, container investigation, image analysis, docker diff, container-diff, dive tool, or need to find modifications in Docker environments. |
Docker Forensics Skill
A comprehensive guide for performing forensic analysis on Docker containers and images.
When to Use This Skill
Use this skill when:
- Investigating potentially compromised Docker containers
- Analyzing suspicious Docker images (especially
.tar exports)
- Comparing container states to detect modifications
- Extracting credentials from container process memory
- Auditing Docker image layers for malicious content
- Documenting container changes for incident response
Container Forensics
Detect Container Modifications
Find what files have been changed or added in a running container compared to its base image:
docker diff <container_name_or_id>
Output interpretation:
A = Added file
C = Changed file
D = Deleted file
Example:
docker diff wordpress
C /var
C /var/lib
A /var/lib/mysql/ib_logfile0
A /etc/shadow
Extract Files from Container
Copy suspicious files from a container to your local system for analysis:
docker cp <container_name_or_id>:<path_to_file> <local_destination>
Example:
docker cp wordpress:/etc/shadow ./shadow_from_container
Compare Files Against Original
To verify if a file was modified, compare it against the original from a fresh container:
docker run -d <image_name> temp_container
docker cp temp_container:<path_to_file> ./original_file
diff ./original_file ./shadow_from_container
docker rm -f temp_container
Access Container for Investigation
Enter a running container to investigate suspicious files:
docker exec -it <container_name_or_id> bash
If bash isn't available, try:
docker exec -it <container_name_or_id> sh
Image Forensics
Basic Image Analysis
Get detailed information about an image:
docker inspect <image_name_or_id>
View the complete history of changes made to the image:
docker history --no-trunc <image_name_or_id>
Export and Analyze Images
Export an image to a tar file for offline analysis:
docker save <image_name> > image.tar
Use container-diff Tool
container-diff provides automated image analysis:
container-diff analyze -t sizelayer image.tar
container-diff analyze -t history image.tar
container-diff analyze -t metadata image.tar
Use dive Tool
dive provides an interactive interface to explore image layers:
sudo docker load < image.tar
sudo dive <image_name:tag>
dive navigation:
- Red = Added files
- Yellow = Modified files
- Tab = Switch between views
- Space = Collapse/expand folders
Decompress Image Layers
To access individual layer contents:
tar -xf image.tar
for d in $(find * -maxdepth 0 -type d); do
cd $d
tar -xf ./layer.tar
cd ..
done
Generate Dockerfile from Image
Reconstruct a Dockerfile from an existing image:
docker run -v /var/run/docker.sock:/var/run/docker.sock --rm alpine/dfimage -sV=1.36 <image_name>
Credential Extraction from Memory
Process Memory Analysis
Docker container processes are visible on the host system. You can dump their memory to search for credentials:
ps -ef | grep <container_process>
sudo gdb -p <pid> -batch -ex "dump memory /tmp/memdump.bin 0x0 $(cat /proc/<pid>/maps | grep 'heap' | awk '{print $2}')"
grep -a -i "password\|api_key\|secret\|token" /tmp/memdump.bin
Note: This technique works because container processes run on the host and their memory can be accessed from the host system.
Investigation Workflow
Step-by-Step Container Investigation
-
Identify the container
docker ps -a
-
Check for modifications
docker diff <container_id>
-
Extract suspicious files
docker cp <container_id>:<suspicious_path> ./
-
Compare with original
docker run -d <image> temp
docker cp temp:<path> ./original
diff ./original ./suspicious
docker rm -f temp
-
Access container if needed
docker exec -it <container_id> bash
Step-by-Step Image Investigation
-
Load the image
docker load < image.tar
-
Get basic info
docker inspect <image>
docker history --no-trunc <image>
-
Analyze with tools
container-diff analyze -t history image.tar
dive <image>
-
Decompress layers for deep inspection
tar -xf image.tar
for d in $(find * -maxdepth 0 -type d); do cd $d; tar -xf ./layer.tar; cd ..; done
Common Indicators of Compromise
Look for these suspicious patterns:
- Modified system files:
/etc/shadow, /etc/passwd, /etc/hosts
- Unexpected binaries: Files in
/tmp, /var/tmp, or unusual locations
- Hidden files: Files starting with
. in unexpected directories
- Network tools:
nc, netcat, curl, wget in containers that shouldn't have them
- Shell access:
/bin/bash or /bin/sh in containers that should be single-purpose
- Credential files:
.env, .aws/credentials, config files with secrets
- Persistence mechanisms: Modified
/etc/crontab, systemd services, or startup scripts
Best Practices
- Document everything: Save outputs of all forensic commands
- Preserve evidence: Work on copies, not originals
- Use read-only mounts: When possible, mount containers read-only to prevent further changes
- Check timestamps: Compare file modification times against expected deployment times
- Verify checksums: Compare file hashes against known-good baselines
- Search for artifacts: Look for shell history, temporary files, and logs
Tools Reference
| Tool | Purpose | Installation |
|---|
docker diff | Compare container to image | Built-in |
container-diff | Image analysis | GitHub releases |
dive | Interactive layer explorer | GitHub releases |
dfimage | Generate Dockerfile from image | docker pull alpine/dfimage |
gdb | Memory dumping | apt install gdb or yum install gdb |