Running Hak5 C2 with HTTPS requires ports 80 and 443. Changing the listening ports will not work.
To run C2 on a server that already has a web server, use a container to avoid port conflicts.
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).
sudo apt update
sudo apt install docker.io
sudo docker run --name c2 -d -it -p 8080:443 -p 2022:22 ubuntu:latest /bin/bash
sudo docker attach c2
Set up the environment inside the container:
apt update && apt upgrade -y && apt install nano locate openssh-server -y && apt autoremove service ssh start passwd root adduser user
Copy all necessary files:
sudo docker cp c2-3.1.1_amd64_linux c2:/c2 sudo docker cp c2.db c2:/c2 sudo docker cp c2_setup_token.txt c2:/c2 sudo docker cp privkey.pem c2:/c2 sudo docker cp pubcert.pem c2:/c2 sudo docker cp sha256sums c2:/c2
Copy your SSH key to the container [Link], then connect to it and run C2 for the first time:
ssh-copy-id [email protected] -p 2022 ssh [email protected] -p 2022 /c2/c2-3.1.1_amd64_linux -hostname domain.com -https -keyFile /c2/privkey.pem -certFile /c2/pubcert.pem
Open your browser and go to https://domain.com:8080 to configure C2.
Once C2 is configured and accessible, use the commands below to manage the container:
sudo docker start c2 sudo docker exec -d c2 service ssh start sudo docker exec -d c2 /c2/c2-3.1.1_amd64_linux -hostname domain.com -https -keyFile /c2/privkey.pem -certFile /c2/pubcert.pem sudo docker stop c2
The script below automates turning the container on and off, and manages the firewall rules on the host machine:
nano c2.sh
Add the following content:
#!/bin/bash
if [ $1 == 'on' ]
then
sudo ufw allow 8080 comment 'C2 HTTPS'
sudo ufw allow 2022 comment 'C2 SSH'
sudo docker start c2
sudo docker exec -d c2 service ssh start
sudo docker exec -d c2 /c2/c2-3.1.1_amd64_linux -hostname domain.com -https -keyFile /c2/privkey.pem -certFile /c2/pubcert.pem
elif [ $1 == 'off' ]
then
sudo docker stop c2
sudo ufw deny 8080 comment 'C2 HTTPS'
sudo ufw deny 2022 comment 'C2 SSH'
else
echo ''
echo 'Missing parameter [on/off]'
echo ''
fi
Make the script executable:
chmod +x c2.sh
You can now turn the container on and off with:
./c2.sh on ./c2.sh off