HackTricks
Search…
Pentesting
Powered By GitBook
Docker Forensics

Container modification

There are suspicions that some docker container was compromised:
1
docker ps
2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3
cc03e43a052a lamp-wordpress "./run.sh" 2 minutes ago Up 2 minutes 80/tcp wordpress
Copied!
You can easily find the modifications done to this container respecting to the image with:
1
docker diff wordpress
2
C /var
3
C /var/lib
4
C /var/lib/mysql
5
A /var/lib/mysql/ib_logfile0
6
A /var/lib/mysql/ib_logfile1
7
A /var/lib/mysql/ibdata1
8
A /var/lib/mysql/mysql
9
A /var/lib/mysql/mysql/time_zone_leap_second.MYI
10
A /var/lib/mysql/mysql/general_log.CSV
11
...
Copied!
In the previous command C means Changed and A, Added. If you find that some interesting file like /etc/shadow was modified you can download it from the container to check for malicious activity with:
1
docker cp wordpress:/etc/shadow .
Copied!
You can also compare it with the original one running a new container and extracting the file from it:
1
docker run -d lamp-wordpress
2
docker cp b5d53e8b468e:/etc/shadow original_shadow #Get the file from the newly created container
3
diff original_shadow shadow
Copied!
If you find that some suspicious file was added you can access the container and check it:
1
docker exec -it wordpress bash
Copied!

Images modifications

When you are given an exported docker image (probably in .tar format) you can use container-diff to extract a summary of the modifications:
1
docker save <image> > image.tar #Export the image to a .tar file
2
container-diff analyze -t sizelayer image.tar
3
container-diff analyze -t history image.tar
4
container-diff analyze -t metadata image.tar
Copied!
Then, you can decompress the image and access the blobs to search for suspicious files you may have found in the changes history:
1
tar -xf image.tar
Copied!
In order to find added/modified files in docker images you can also use the dive (download it from releases) utility:
1
#First you need to load the image in your docker repo
2
sudo docker load < image.tar 1
3
Loaded image: flask:latest
4
5
#And then open it with dive:
6
sudo dive flask:latest
Copied!
This allow you to navigate through the different blobs of docker images and check which files were modified/added. Red means added and yellow means modified. Use tab to move to the other view and space to to collapse/open folders.
With die you won't be able to access the content of the different stages of the image. To do so you will need to decompress each layer and access it. You can decompress all the layers from an image from the directory where the image was decompressed executing:
1
tar -xf image.tar
2
for d in `find * -maxdepth 0 -type d`; do cd $d; tar -xf ./layer.tar; cd ..; done
Copied!

Credentials from memory

Note that when you run a docker container inside a host you can see the processes running on the container from the host just running ps -ef
Therefore (as root) you can dump the memory of the processes from the host and search for credentials just like in the following example.
Last modified 21d ago