githubEdit

Docker && Kubernetes

Basic Docker commands

# Search in docker hub
docker search wpscan

# Run docker container from docker hub
docker run ubuntu:latest echo "Welcome to Ubuntu"

# Run docker container from docker hub with interactive tty
docker run --name samplecontainer -it ubuntu:latest /bin/bash

# List running containers
docker ps

# List all containers
docker ps -a

# List docker images
docker images

# Run docker in background
docker run --name pingcontainer -d alpine:latest ping 127.0.0.1 -c 50

# Get container logs (follow)
docker logs -f pingcontainer

# Run container service in specified port
docker run -d --name nginxalpine -p 7777:80 nginx:alpine

# Access tty of running container
docker exec -it nginxalpine sh

# Get low-level info of docker object
docker inspect (container or image)

# Show image history
docker history jess/htop

# Stop container
docker stop dummynginx

# Remove container
docker rm dummynginx

# Run docker with specified PID namespace
docker run --rm -it --pid=host jess/htop

# Show logs (examples)
docker logs containername
docker logs -f containername

# Show service defined logs
docker service logs

# Look generated real time events by docker runtime
docker system events
docker events --since '10m'
docker events --filter 'image=alpine'
docker events --filter 'event=stop'

# Compose application (set up multicontainer docker app)
docker-compose up -d

# List docker volumes
docker volume ls

# Create volume
docker volume create vol1

# List docker networks
docker network ls

# Create docker network
docker network create net1

# Remove capability of container
docker run --rm -it --cap-drop=NET_RAW alpine sh

# Check capabilities inside container (example image id)
docker run --rm -it 71aa5f3f90dc bash
capsh --print

# Run full privileged container
docker run --rm -it --privileged=true 71aa5f3f90dc bash
capsh --print

# From full privileged container you can access host devices
more /dev/kmsg

# Creating container groups
docker run -d --name='low_priority' --cpuset-cpus=0 --cpu-shares=10 alpine md5sum /dev/urandom
docker run -d --name='high_priority' --cpuset-cpus=0 --cpu-shares=50 alpine md5sum /dev/urandom

# Stopping cgroups
docker stop low_priority high_priority

# Remove cgroups
docker rm low_priority high_priority

# Setup docker swarm cluster
docker swarm init

# Check swarm nodes
docker node ls

# Start new service in cluster
docker service create --replicas 1 --publish 5555:80 --name nginxservice nginx:alpine

# List services
docker service ls

# Inspect service
docker service inspect --pretty nginxservice

# Remove service
docker service rm nginxservice

# Leave cluster
docker swarm leave (--force if only one node)

# Start portainer
docker run -d -p 9000:9000 --name portainer \
  --restart always -v /var/run/docker.sock:/var/run/docker.sock \
  -v /opt/portainer:/data portainer/portainer

Tools referenced:

  • https://github.com/lightspin-tech/red-kube


Image integrity & vulnerability checks


Detecting if inside a Docker container (quick checks)

  • MAC Address ranges: Docker uses a range from 02:42:ac:11:00:00 to 02:42:ac:11:ff:ff

  • List of running processes (ps aux) — a small number of processes can indicate a container

  • CGROUPs: cat /proc/1/cgroup — should show docker process running

  • Check for existence of docker.sock: ls -al /var/run/docker.sock

  • Check for container capabilities: capsh --print

  • On pentests, check for TCP ports 2375 and 2376 — default docker daemon ports


Escape NET_ADMIN Docker container (notes / snippets)

You can replace the 'ps aux' command with other actions (example given: appending an SSH key):


Attack insecure volume mounts (post-RCE in container)

Commands executed inside compromised container:


Attack: Docker API exposed (misconfiguration)


Audit Docker runtime & registries

Runtime checks:

Public registry (default registry port 5000):

Private registry examples and notes:

To check configured credentials on a host:


Attack container capabilities (notes)

  • Check capabilities: capsh --print

  • Example workflow:

    • Upload payload (e.g., msfvenom raw payload)

    • Identify any process running as root: ps aux | grep root

    • Use injector to inject into a target PID running as root

Example payload generation:


Useful tools (Docker / Container)

  • https://github.com/anchore/grype

  • https://github.com/aquasecurity/trivy

  • https://github.com/cr0hn/dockerscan

  • https://github.com/P3GLEG/Whaler

  • https://github.com/RhinoSecurityLabs/ccat

  • https://github.com/stealthcopter/deepce


Kubernetes — Pentester Notes

Links:

  • Kubernetes for Pentesters: Part 1 — https://trustedsec.com/blog/kubernetes-for-pentesters-part-1

  • A Pentester’s Approach to Kubernetes Security — https://blog.appsecco.com/a-pentesters-approach-to-kubernetes-security-part-1-2b328252954a and part 2

  • Penetration testing a Kubernetes environment — https://bobvanderstaak.medium.com/penetration-testing-a-kubernetes-environment-72719f9e1010

Concepts

  • Kubernetes is a security orchestrator.

  • Kubernetes master provides an API to interact with nodes.

  • Each Kubernetes node runs kubelet (interacts with API) and kube-proxy (reflects Kubernetes networking services on each node).

  • Kubernetes objects are abstractions of states of your system:

    • Pods: collection of containers sharing network and namespace on the same node.

    • Services: group of pods running in the cluster.

    • Volumes: directory accessible to all containers in a pod; solves ephemeral storage problems when containers restart.

    • Namespaces: scope of Kubernetes objects, like a workspace (e.g., dev-space).

Common kubectl commands

Known vulnerabilities (examples):

  • CVE-2016-9962

  • CVE-2018-1002105

  • CVE-2019-5736

  • CVE-2019-9901

External recon

Common open ports and endpoints (images shown in original content):

  • See images in original source for common ports and endpoints.

Quick attacks & enumeration

Attack: Private registry misconfiguration (example)

Attack: Cluster metadata via SSRF

Attack: Escaping pod volume mounts to access node/host

Kubernetes tools referenced

Other tools listed earlier:

  • https://github.com/anchore/grype



Last updated