githubEdit

Docker Pentesting

Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. Default ports are 2375, 2376.

Investigation

Find Docker Binary

If we cannot use docker command by default, we need to find the docker binary.

find / -name "docker" 2>/dev/null

Basic Commands

# Get comprehensive information
docker info

# List images
docker images
docker image ls
# The history of an image
docker image history <image-name>

# List containers running
docker container ls
# or
docker ps

# List all containers
docker container ls -a
# or
docker ps -a

# List secrets
docker secret ls

# Check configuration of container
docker inspect --format='{{json .Config}}' <container_id_or_name>

# Get a port which is used by the container
docker port <container_id_or_name>

# Scan vulnerabilies (CVEs)
docker scan cves <image>
docker scan cves alpine

# View the SBOM (Software Bill of Materials) for an image
# We can investigate vulnerabilities from the list of packages.
docker sbom alpine:latest
# Json format
docker sbom alpine:latest --format syft-json

# Spawn the shell in the container
docker exec -it <container_id> /bin/bash

# Kill the running docker container
docker kill <container_id>

Check if Containers Running

In target machine, observe the network status by running netstat or ss command.

Basic Operations

Run a New Container

First check the docker images listed.

Then run a new container from the image.

If you want to run a new container from a remote repository, run the following.

Start a Container which is stopped

Run Commands in a Container

Stop a Container

Remove a Container

Build a Container Image

First off, create a Dockerfile in the root directory of the project.

Now run the following command to build the container image. This command uses the Dockerfile.

Scan a Container Image

Pull a Docker Image

We need to download a docker image to start a container at first.

Remove a Docker Image

Publish a Docker Image

Before doing below, you need to sign up the Docker Hub and sign in, then create a new repository in your dashboard.

Last updated