Skip to content

Instantly share code, notes, and snippets.

@jniltinho
Created January 25, 2023 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jniltinho/220088b892713e88c30bcebf8f085847 to your computer and use it in GitHub Desktop.
Save jniltinho/220088b892713e88c30bcebf8f085847 to your computer and use it in GitHub Desktop.
Install Ctfreak Server on Ubuntu 22.04
#!/bin/bash
## Install Ctfreak Server
## run as root
## https://ctfreak.com/
## https://ctfreak.com/docs/install/linux
FQDN=task.linuxpro.com.br
DOMAIN=linuxpro.com.br
apt-get update
apt-get install -y curl certbot nginx
systemctl stop nginx
useradd -U -M -s /bin/bash -d /opt/ctfreak ctfreak
mkdir -p /opt/ctfreak/.config
curl -o /opt/ctfreak/ctfreak -#L -k https://ctfreak.com/download/release/latest/linux/amd64
chmod +x /opt/ctfreak/ctfreak
chown -R ctfreak:ctfreak /opt/ctfreak
certbot certonly --standalone -d "$FQDN" --preferred-challenges http --agree-tos -n -m "linuxpro@$DOMAIN" --keep-until-expiring
cat <<'EOF' >/etc/nginx/sites-available/ctfreak.conf
server {
listen 443 ssl;
server_name FQDN;
access_log /var/log/nginx/FQDN.access.log;
ssl_certificate /etc/letsencrypt/live/FQDN/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/FQDN/privkey.pem;
ssl on;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1.2;
location / {
proxy_pass http://localhost:6700;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 80;
server_name FQDN;
return 301 https://$host$request_uri;
}
EOF
sed -i "s|FQDN|$FQDN|g" /etc/nginx/sites-available/ctfreak.conf
ln -s /etc/nginx/sites-available/ctfreak.conf /etc/nginx/sites-enabled/
cat <<'EOF' >/etc/systemd/system/ctfreak.service
[Unit]
Description=Run CtFreak server
After=network.target
[Service]
Type=simple
Restart=on-failure
WorkingDirectory=/opt/ctfreak
ExecStart=/opt/ctfreak/ctfreak run
User=ctfreak
Group=ctfreak
LimitNOFILE=100000
LimitNOFILESoft=100000
[Install]
WantedBy=multi-user.target
EOF
chmod 664 /etc/systemd/system/ctfreak.service
systemctl daemon-reload
systemctl enable ctfreak
systemctl start ctfreak
systemctl start nginx
## Navigate to https://$FQDN
## Log in with the default user: admin / password: ctfreak.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment