{"id":1298,"date":"2021-03-04T03:52:38","date_gmt":"2021-03-04T03:52:38","guid":{"rendered":"https:\/\/dft.wiki\/?p=1298"},"modified":"2021-03-04T04:01:56","modified_gmt":"2021-03-04T04:01:56","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 will required ports 80 and 443 necessarily, changing the listening ports will not work.<\/p>\n<p>To run C2 on a server that already runs a webserver will be necessary to use a container to prevent ports conflict.<\/p>\n<p>The docker will be configured HTTP port 8080 external -&gt; port 443 internal. Same to the SSH, 2022 -&gt; 22.<\/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>Setup the environment in the docker:<\/p>\n<pre>apt update &amp;&amp; apt upgrade -y &amp;&amp; apt install nano locate openssh-server -y &amp;&amp; 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 docker [<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>Access on your browser to configure the C2: <strong>https:\/\/domain.com:8080<\/strong><\/p>\n<p>After configuring the C2 and getting access to it use the commands below to manage the new docker:<\/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>Follow a script to automate turn ON and OFF plus 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>Set the script executable:<\/p>\n<pre>chmod +x c2.sh<\/pre>\n<p>Now you can turn the docker on and off using the following commands:<\/p>\n<pre>.\/c2.sh on\r\n.\/c2.sh off<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Running Hak5 C2 with HTTPS will required ports 80 and 443 necessarily, changing the listening [&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":4,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1298\/revisions"}],"predecessor-version":[{"id":1302,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1298\/revisions\/1302"}],"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}]}}