{"id":1298,"date":"2021-03-04T03:52:38","date_gmt":"2021-03-04T03:52:38","guid":{"rendered":"https:\/\/dft.wiki\/?p=1298"},"modified":"2026-06-09T09:30:45","modified_gmt":"2026-06-09T13:30:45","slug":"installing-hak5-c2-3-1-1-in-a-docker","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=1298","title":{"rendered":"Installing Hak5 C2 3.1.1 in a Docker"},"content":{"rendered":"<p>Running Hak5 C2 with HTTPS requires ports 80 and 443. Changing the listening ports will not work.<\/p>\n<p>To run C2 on a server that already has a web server, use a container to avoid port conflicts.<\/p>\n<p>The Docker container will be configured with HTTP port 8080 (external) mapped to port 443 (internal). The same applies to SSH: 2022 (external) to 22 (internal).<\/p>\n<pre class=\" prettyprinted\"><span class=\"pln\">sudo apt update\r\nsudo apt install docker.io\r\nsudo docker run --name c2 -d -it -p 8080:443 -p 2022:22 ubuntu:latest \/bin\/bash\r\nsudo docker attach c2<\/span><\/pre>\n<p>Set up the environment inside the container:<\/p>\n<pre>apt update && apt upgrade -y && apt install nano locate openssh-server -y && apt autoremove\r\nservice ssh start\r\npasswd root\r\nadduser user<\/pre>\n<p>Copy all necessary files:<\/p>\n<pre>sudo docker cp c2-3.1.1_amd64_linux c2:\/c2\r\nsudo docker cp c2.db c2:\/c2\r\nsudo docker cp c2_setup_token.txt c2:\/c2\r\nsudo docker cp privkey.pem c2:\/c2\r\nsudo docker cp pubcert.pem c2:\/c2\r\nsudo docker cp sha256sums c2:\/c2<\/pre>\n<p>Copy your SSH key to the container [<a href=\"https:\/\/dft.wiki\/?p=423\">Link<\/a>], then connect to it and run C2 for the first time:<\/p>\n<pre>ssh-copy-id user@127.0.0.1 -p 2022\r\nssh user@127.0.0.1 -p 2022\r\n\/c2\/c2-3.1.1_amd64_linux -hostname <strong>domain.com<\/strong> -https -keyFile \/c2\/privkey.pem -certFile \/c2\/pubcert.pem<\/pre>\n<p>Open your browser and go to <strong>https:\/\/domain.com:8080<\/strong> to configure C2.<\/p>\n<p>Once C2 is configured and accessible, use the commands below to manage the container:<\/p>\n<pre>sudo docker start c2\r\nsudo docker exec -d c2 service ssh start\r\nsudo docker exec -d c2 \/c2\/c2-3.1.1_amd64_linux -hostname domain.com -https -keyFile \/c2\/privkey.pem -certFile \/c2\/pubcert.pem\r\nsudo docker stop c2<\/pre>\n<p>The script below automates turning the container on and off, and manages the firewall rules on the host machine:<\/p>\n<pre>nano c2.sh<\/pre>\n<p>Add the following content:<\/p>\n<pre>#!\/bin\/bash\r\nif [ $1 == 'on' ]\r\nthen\r\n        sudo ufw allow 8080 comment 'C2 HTTPS'\r\n        sudo ufw allow 2022 comment 'C2 SSH'\r\n        sudo docker start c2\r\n        sudo docker exec -d c2 service ssh start\r\n        sudo docker exec -d c2 \/c2\/c2-3.1.1_amd64_linux -hostname domain.com -https -keyFile \/c2\/privkey.pem -certFile \/c2\/pubcert.pem\r\nelif [ $1 == 'off' ]\r\nthen\r\n        sudo docker stop c2\r\n        sudo ufw deny 8080 comment 'C2 HTTPS'\r\n        sudo ufw deny 2022 comment 'C2 SSH'\r\nelse\r\n        echo ''\r\n        echo 'Missing parameter [on\/off]'\r\n        echo ''\r\nfi<\/pre>\n<p>Make the script executable:<\/p>\n<pre>chmod +x c2.sh<\/pre>\n<p>You can now turn the container on and off with:<\/p>\n<pre>.\/c2.sh on\r\n.\/c2.sh off<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Running Hak5 C2 with HTTPS requires ports 80 and 443. Changing the listening ports will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-1298","post","type-post","status-publish","format-standard","hentry","category-hacking"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1298","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1298"}],"version-history":[{"count":5,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1298\/revisions"}],"predecessor-version":[{"id":5775,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1298\/revisions\/5775"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1298"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}