CTF-Cafe / CTF_Cafe_platform

A full CTF Website Server & Frontend | Extremely customizable
Other
55 stars 9 forks source link

Install DOC #109

Open Yoko02 opened 1 year ago

Yoko02 commented 1 year ago

Installation CTFCafe

Prerequisites

Nodejs v20 Npm v10 Docker Docker-compose

Install MongoDB

docker pull mongo
docker run --name mongo -d mongo
docker exec -it mongo sh
# Notez bien le "Current Mongosh Log ID"
 > mongosh
  > use admin
  > db.createUser(
    {
        user: "dbuser",
        pwd: "changeme",
        roles: [ "root" ]
    })
  > use ctfDB
  > exit
 > exit

Create script for install

Move in your favorite directory.

# For create the script
touch script.sh 
chmod 755 script.sh 

Modify script in line 6, 7 and 52. Script :

#!/bin/bash

wget https://github.com/CTF-Cafe/CTF_Cafe_platform/archive/refs/heads/master.zip
unzip master.zip
cd CTF_Cafe_platform-master/backEnd
touch .env
echo -e "# DB
SESSION_SECRET=<Current Mongosh Log ID>
MONGODB_CONNSTRING=mongodb://dbuser:changeme@<IP conteneur MongoDB>:27017/ctfDB?authSource=admin

# Routing
FRONTEND_URI=http://localhost:3000

# Mail Verification
#MAIL_VERIFICATION=<true/false>
#BACKEND_URI=<backend url same as frontend unless testing locally, will then be port 3001>
#HOST=<mail server>
#MAIL_PORT=<mail server port>
#MAIL=<mail address to send emails>
#PASS=<mail password to send emails>

# Docker API
DEPLOYER_API=http://localhost:3002
DEPLOYER_SECRET=s3cret

# Config
NODE_ENV=development
PORT=3001

# First Blood Webhook
#WEBHOOK=<discord webhook url>
#WEBHOOK_2=<custom webhook url> " >> .env
cd ../frontEnd
touch .env
echo -e "# Routing
REACT_APP_BACKEND_URI=http://localhost:3001

# Config
REACT_APP_CTF_NAME=new_ctf
GENERATE_SOURCEMAP=true

#Links
#REACT_APP_DISCORD_URI=<optional>
#REACT_APP_GITHUB_URI=<optional>
#REACT_APP_TWIITER_URI=<optional> " >> .env

cd ../dockerAPI
touch .env
echo -e "# Routing
BACKEND_URI=http://localhost:3001/
DOCKER_URI=http://localhost

# DB
MONGODB_CONNSTRING=mongodb://dbuser:changeme@<IP conteneur MongoDB>:27017/ctfDB?authSource=admin

# Secrets
SECRET_TOKEN=s3cret
#GITHUB_TOKEN=<Github Token>

# Config
PORT=3002
#RANDOM_FLAG_FORMAT=<format for random flags, i.e. FLAG{RAND}. "RAND" will be replaced>" >> .env
npm install
cd ../frontEnd
npm install
cd ../backEnd
npm install

Run script

./script.sh

Start services

In the backend directory :

# Warning, the admin password appears at the first start of the backend
npm start

In the frontend directory :

npm run start-react

In the dockerAPI directory :

npm start

Config of docker chall

Create new chall in ADMIN_MODE. In "Docker", put the github link to the file where you put your docker-compose. /!\ Warning, put the tree link /!\ Example : https://github.com/Gomez0015/CTFCafe_Docker_Chall_Test/tree/main/challTest

Useful commands

If you had a problem creating your docker instance, enter this command in the mongo database:

db.docker.drop();

It will allow you to delete the docker instances created

To know

You would not be able to access the platform on your local network, you will have to replace "localhost" with "your IP" in the ".env" of /frontEnd, /backEnd and /dockerAPI.

UweKrause commented 1 month ago

Thanks for the additional MongoDB usage advice :) Sadly I still did not manage to launch it. Backend and DockerAPI both said they cant connect to mongodb. I did find and replace the <Current Mongosh Log ID>.