Denial Of Service on Docker
How Denial Of Service Manifests in Docker
Denial of Service (DoS) attacks in Docker environments exploit the containerization layer to exhaust resources or disrupt service availability. Unlike traditional DoS attacks targeting network bandwidth, Docker-specific DoS attacks leverage container orchestration, resource constraints, and runtime isolation mechanisms.
The most common Docker DoS vector involves resource exhaustion through container sprawl. Attackers can trigger rapid container creation using malicious images or orchestration APIs, overwhelming the Docker daemon and host system. A typical attack pattern involves exploiting Docker's REST API (listening on port 2375 or 2376 by default) to create hundreds of containers simultaneously:
POST /containers/create HTTP/1.1
Host: localhost:2375
Content-Type: application/json
{
"Image": "alpine",
"Cmd": ["sleep", "1000000"]
}
# Repeat this request rapidly to exhaust system resourcesAnother Docker-specific DoS attack targets the container runtime's memory management. When containers share the same kernel but have no proper memory limits, a single malicious container can consume all available RAM, causing the entire host to become unresponsive. This becomes particularly dangerous when using Docker Swarm or Kubernetes where a single compromised node can affect the entire cluster.
Container escape attacks can also lead to DoS conditions. By exploiting vulnerabilities in the container runtime or using privileged containers, attackers can access the host filesystem and corrupt critical system files or fill up disk space. The following Docker command creates a privileged container with host filesystem access:
docker run -it --privileged --mount type=bind,source=/,target=/host alpine shOnce inside, an attacker can execute commands like dd if=/dev/zero of=/host/swapfile bs=1M count=100000 to create massive files and exhaust disk space.
Network-based DoS attacks in Docker often target the bridge network interface. Containers can send massive amounts of network traffic, overwhelming the Docker bridge (docker0) interface. This becomes especially problematic when using Docker Compose with default bridge networking, where all containers share the same network namespace.
Resource starvation through CPU throttling is another effective Docker DoS technique. By creating containers with malicious CPU usage patterns or exploiting Docker's CPU scheduling, attackers can cause legitimate containers to starve for processing time. This is particularly effective in multi-tenant environments where resource isolation is not properly configured.
Docker-Specific Detection
Detecting DoS vulnerabilities in Docker requires monitoring both the Docker daemon and container runtime behavior. The first step is scanning your Docker environment with middleBrick's API security scanner, which includes specific checks for Docker-related DoS vulnerabilities.
middleBrick's Docker DoS detection focuses on several key areas:
- Unauthenticated API access: Scanning for Docker daemon APIs exposed without authentication on ports 2375/2376
- Resource configuration analysis: Identifying containers running without memory or CPU limits
- Privilege escalation paths: Detecting containers running with --privileged flag or mounted host filesystems
- Network exposure assessment: Finding containers with open ports that could be used for amplification attacks
The scanning process takes 5-15 seconds and provides a security risk score (A-F) with specific findings. For Docker environments, middleBrick tests the unauthenticated attack surface by attempting to access the Docker daemon API and analyzing container configurations without requiring credentials.
Manual detection techniques complement automated scanning. Use these Docker commands to identify potential DoS vulnerabilities:
# Check for exposed Docker daemon APIs
netstat -tlnp | grep -E ':(2375|2376)'
# Find containers without resource limits
docker ps -q | xargs docker inspect --format '{{.Name}}: {{.HostConfig.Memory}} {{.HostConfig.CpuCount}}'
# Identify privileged containers
docker ps -a --format 'table {{.Names}} {{.Status}} {{.Privileged}}'
# Check for mounted host filesystems
docker ps -q | xargs docker inspect --format '{{.Name}}: {{range .Mounts}}{{.Source}} -> {{.Destination}} {{end}}'System-level monitoring provides additional detection capabilities. Monitor Docker daemon logs for unusual API access patterns, track container creation rates, and watch for sudden memory or CPU spikes across your container fleet.
For production environments, implement Docker Content Trust and only pull images from verified registries. This prevents attackers from using malicious images to launch DoS attacks through container creation.
Docker-Specific Remediation
Remediating Docker DoS vulnerabilities requires a defense-in-depth approach combining Docker configuration best practices, runtime security controls, and network isolation. The following code examples demonstrate specific Docker-native solutions.
Secure Docker Daemon Configuration
Always enable TLS authentication for the Docker daemon and bind it to localhost:
# Create TLS certificates
mkdir -p /etc/docker/tls
openssl req -newkey rsa:4096 -nodes -sha256 -keyout /etc/docker/tls/docker.key -x509 -days 365 -out /etc/docker/tls/docker.crt
# Configure Docker daemon to use TLS
cat > /etc/docker/daemon.json << 'EOF'
{
"tlsverify": true,
"tlscacert": "/etc/docker/tls/docker.crt",
"tlscert": "/etc/docker/tls/docker.crt",
"tlskey": "/etc/docker/tls/docker.key",
"hosts": ["unix:///var/run/docker.sock", "https://127.0.0.1:2376"]
}
EOF
# Restart Docker
systemctl restart dockerResource Limits Implementation
Configure strict resource limits for all containers to prevent resource exhaustion:
# Run containers with memory and CPU limits
docker run -d --name secure-app \
--memory="512m" \
--memory-swap="512m" \
--cpus="0.5" \
--restart=unless-stopped \
myapp:latest
# Docker Compose with resource limits
cat > docker-compose.yml << 'EOF'
version: '3.8'
services:
web:
image: nginx:alpine
deploy:
resources:
limits:
memory: 512M
cpus: '0.5'
reservations:
memory: 256M
cpus: '0.25'
EOFNetwork Isolation
Implement network segmentation to limit DoS blast radius:
# Create isolated networks for different application tiers
docker network create --driver bridge --subnet 172.20.0.0/16 --gateway 172.20.0.1 frontend
# Connect containers to specific networks
docker run -d --name api \
--network backend \
--network-alias api \
--restart=unless-stopped \
myapp-api:latest
# Use user-defined bridge networks with custom iptables rules
docker network create --driver bridge --internal --subnet 192.168.1.0/24 isolated_networkRuntime Security Controls
Enable Docker's built-in security features to prevent container escape and resource abuse:
# Run containers without privileged access
docker run -d --name app \
--read-only \
--tmpfs /tmp \
--mount type=tmpfs,destination=/var/log \
--cap-drop ALL \
--cap-add CHOWN \
--cap-add SETGID \
--cap-add SETUID \
myapp:latest
# Use seccomp profiles to restrict system calls
docker run -d --name secured \
--security-opt seccomp=/path/to/seccomp.json \
--security-opt no-new-privileges:true \
myapp:latestMonitoring and Alerting
Implement Docker-specific monitoring to detect DoS attempts:
# Monitor container creation rates
docker events --filter 'type=container' --since '1m' | grep 'create'
# Set up alerts for unusual API access
journalctl -u docker --since '10 minutes ago' | grep 'API request'
# Monitor resource usage trends
docker stats --no-stream --format 'table {{.Container}} {{.CPUPerc}} {{.MemUsage}} {{.NetIO}}'These remediation strategies, combined with middleBrick's continuous monitoring capabilities, create a robust defense against Docker-specific DoS attacks. The Pro plan's continuous monitoring feature can automatically scan your Docker environments on a configurable schedule, alerting you to new vulnerabilities before they can be exploited.
Related CWEs: resourceConsumption
| CWE ID | Name | Severity |
|---|---|---|
| CWE-400 | Uncontrolled Resource Consumption | HIGH |
| CWE-770 | Allocation of Resources Without Limits | MEDIUM |
| CWE-799 | Improper Control of Interaction Frequency | MEDIUM |
| CWE-835 | Infinite Loop | HIGH |
| CWE-1050 | Excessive Platform Resource Consumption | MEDIUM |