All Projects → freehackquest → fhq-server

freehackquest / fhq-server

Licence: MIT license
This is an open source platform for competitions of computer security.

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language
javascript
184084 projects - #8 most used programming language
typescript
32286 projects
CSS
56736 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to fhq-server

solveme
SolveMe - Jeopardy CTF Platform
Stars: ✭ 51 (+54.55%)
Mutual labels:  ctf, ctf-platform, ctf-challenges
bamboofox-website
☕ Bamboofox CTF training platform
Stars: ✭ 21 (-36.36%)
Mutual labels:  ctf, ctf-platform, ctf-challenges
ctf-gameserver
FAUST Gameserver for attack-defense CTFs
Stars: ✭ 38 (+15.15%)
Mutual labels:  competition, ctf
wanictf21spring-writeup
WaniCTF'21-spring official writeup & source code
Stars: ✭ 14 (-57.58%)
Mutual labels:  ctf, ctf-challenges
nsa-codebreaker-2020
My solutions to the 2020 NSA Codebreaker Challenge
Stars: ✭ 69 (+109.09%)
Mutual labels:  ctf, ctf-challenges
jerseyctf-2021-challenges
JerseyCTF 2021
Stars: ✭ 22 (-33.33%)
Mutual labels:  ctf, ctf-challenges
PTE
Platform Test Edition
Stars: ✭ 18 (-45.45%)
Mutual labels:  ctf, ctf-platform
hackergame2021-writeups
中国科学技术大学第八届信息安全大赛的官方与非官方题解
Stars: ✭ 444 (+1245.45%)
Mutual labels:  ctf, ctf-challenges
exploiting
Exploiting challenges in Linux and Windows
Stars: ✭ 122 (+269.7%)
Mutual labels:  ctf, ctf-challenges
hackergame-challenge-docker
nc 类题目的 Docker 容器资源限制、动态 flag、网页终端
Stars: ✭ 62 (+87.88%)
Mutual labels:  ctf, ctf-platform
factordb
RSA primes numbers /RSA/CTFs
Stars: ✭ 42 (+27.27%)
Mutual labels:  ctf, ctf-challenges
2020p
WeCTF 2020+ Source Code & Organizer's Writeup
Stars: ✭ 22 (-33.33%)
Mutual labels:  ctf, ctf-challenges
Open Solution Value Prediction
Open solution to the Santander Value Prediction Challenge 🐠
Stars: ✭ 34 (+3.03%)
Mutual labels:  competition, education
eth-challenge-base
xinetd docker for building ethereum contract challenges
Stars: ✭ 74 (+124.24%)
Mutual labels:  ctf, ctf-challenges
Ctf Writeups Public
Writeups for infosec Capture the Flag events by team Galaxians
Stars: ✭ 331 (+903.03%)
Mutual labels:  competition, ctf
Flag-Capture
Solutions and write-ups from security-based competitions also known as Capture The Flag competition
Stars: ✭ 84 (+154.55%)
Mutual labels:  competition, ctf
flare-on-challenges
Write-ups for FireEye's FLARE-On challenges
Stars: ✭ 24 (-27.27%)
Mutual labels:  ctf, ctf-challenges
Google Ctf
Google CTF
Stars: ✭ 2,591 (+7751.52%)
Mutual labels:  ctf, ctf-challenges
Ctfd
CTFs as you need them
Stars: ✭ 3,768 (+11318.18%)
Mutual labels:  education, ctf
Ti0sCTF-OJ
🚩Ti0sCTF (Capture The Flag) 平台 - CTF平台 - 欢迎 Star~ ✨
Stars: ✭ 43 (+30.3%)
Mutual labels:  ctf, ctf-platform

FHQ Server (backend + frontend)

Docker Pulls Github Stars Github Stars Github Forks Total alerts Language grade: Python Language grade: Python Language grade: JavaScript Known Vulnerabilities Server API Coverage

Backend && Frontend for FreeHackQuest on Qt and WebSockets

Contacts

docker-compose example

docker-compose example

Distribution

What Where Source code
fhq-server (docker) Docker Pulls
fhq-server (vm) https://freehackquest.com/dist/
client library (js) npm GitHub
client library (python) PyPI GitHub

For developers

Build all components (c++ && angular)

Ubuntu / Debian 11.0

Requirements:

$ sudo apt install git-core g++ make cmake qtchooser qt5-default \
   libqt5websockets5 libqt5websockets5-dev libqt5sql5-mysql \
   libwebsockets-dev libcurl4-openssl-dev \
   zlib1g zlib1g-dev \
   libpng-dev \
   libmysqlclient-dev \
   mysql-server mysql-client \
   build-essential curl

Install latest nodejs (for web-user)

$ curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
$ sudo apt-get install nodejs

Configure database:

Run mysql console:

$ mysql -h localhost -u root -p

Execute next queries for create empty database:

> CREATE DATABASE `fhqtravis` CHARACTER SET utf8 COLLATE utf8_general_ci;
> CREATE USER 'travis'@'localhost' IDENTIFIED BY '';
> GRANT ALL PRIVILEGES ON fhqtravis.* TO 'travis'@'localhost' WITH GRANT OPTION;
> FLUSH PRIVILEGES;

Clone repository:

$ git clone https://github.com/freehackquest/fhq-server ~/fhq-server.git

Build angular:

$ cd ~/fhq-server.git/web-user
$ npm install
$ npm run build --prod

Build c++ server:

$ cd ~/fhq-server.git/
$ ./build_simple.sh
$ ./fhq-server -wd ./ci/travis/data start
  • web-user you can see here: http://localhost:7080/
  • web-admin: http://localhost:7080/admin/

Note: default login/password: admin/admin

Also you can start web angular for develop: Will need backend runned (!)

$ cd ~/fhq-server.git/web-user
$ npm run start

So you can see web user here: http://localhost:4200/

Unit-tests

Build and run unit-tests:

$ cd ~/fhq-server.git/unit-tests.wsjcpp
$ ./build_simple.sh
$ ./unit-tests

Server api tests

Based on python3 and pytest. Also please check code by pylint.

Install Requirements:

$ sudo apt install python3-pip 
$ pip3 install websocket-client requests pytest pytest-env docker pylint

Exists two ways:

  1. When using a fresh compiled fhq-server on local machine
  2. Use a docker image latest version from hub.docker.com (here: https://hub.docker.com/r/freehackquest/fhq-server)

Server api tests - first way (local binary mode)

Expected that repository already got and fhq-server compiled. Also database configured for ci/travis/data.

Run tests (will be deprecated):

$ cd ~/fhq-server.git/fhq-server-tests
$ ./update_freehackquest_libclient_py.sh # update auto-generate-client-library
$ python3 run_tests.py # run tests

New running tests (based on pytest):

$ cd ~/fhq-server.git/tests/server-api-tests/
$ ./update_freehackquest_libclient_py.sh # update auto-generate-client-library
$ python3 -m pylint --rcfile=.pylintrc *.py
$ python3 -m pytest -rAs -c env-travis.ini .

Server api tests - second way (docker mode)

Since you do not have a local server, you need to install the client library:

$ pip3 install freehackquest-libclient-py

Donwload docker images:

$ docker pull freehackquest/fhq-server
$ docker pull mysql:5.7

And now you can try run server-api-tests

$ cd ~/fhq-server.git/tests/server-api-tests
$ python3 -m pylint --rcfile=.pylintrc *.py
$ python3 -m pytest -rAs -c env-docker.ini .

Check the leaks mememory via valgrind

Requirements:

$ sudo apt install valgrind # ubuntu and debian

Terminal1:

$ cd ~/fhq-server.git/
$ valgrind --leak-check=full \
    --show-leak-kinds=all \
    --track-origins=yes \
    --verbose \
    --log-file=valgrind-out.txt \
    ./fhq-server -wd ./ci/travis/data

Terminal2:

$ cd ~/fhq-server.git/fhq-server-tests
$ python3 run_tests.py

or run new pytests

$ cd ~/fhq-server.git/tests/server-api-tests
$ python3 -m pytest -rAs -c env-local.ini .

Web User Interface

Fast to fix and develop for current server version

$ git clone [email protected]:freehackquest/fhq-server.git ~/fhq-server.git
$ cd ~/fhq-server.git/web-user
$ npm install 
$ npm run start

In a file ~/fhq-server.git/web-user/src/app/services/fhq.service.ts And then you can just uncomment line:

// baseUrl = 'ws://freehackquest.com/api-ws/';

to

baseUrl = 'ws://freehackquest.com/api-ws/';

And now your local web site will be connected to offical server.

Notice: but please never do commit for this line

Build docker image

If you wanna fresh enviroment

$ ./rebuild_environment_images.sh

Rebuild fresh docker

$ docker build -t sea5kg/fhq-server:latest .
$ docker tag sea5kg/fhq-server:latest sea5kg/fhq-server:v0.2.xx

Ubuntu - install from ppa (outdated)

Note: Not working now

https://launchpad.net/~freehackquest/+archive/ubuntu/fhq-server

$ sudo add-apt-repository ppa:freehackquest/fhq-server
$ sudo apt update
$ sudo apt install fhq-server

Configure systemd on host system (Ubuntu/Debian)

Note: Before your need build of fhq-server and install to /usr/bin/fhq-server Note: Prepare mysql empty database for fhq-server Note: last updated for fhq-server-v0.2.35

Create the file /etc/systemd/system/fhq-server.service with content

[Unit]
Description=FreeHackQuest Server
After=syslog.target
After=network.target
After=mysql.service
Requires=mysql.service

[Service]
WorkingDirectory=/usr/share/fhq-server
User=root
Group=root
ExecStart=/bin/sh -c '/usr/bin/fhq-server start > /var/log/fhq-server/access.log 2> /var/log/fhq-server/error.log'

TimeoutSec=30
Restart=always

[Install]
WantedBy=multi-user.target
Alias=fhq-server.service

Create directories

$ sudo mkdir /etc/fhq-server/
$ sudo mkdir /var/log/fhq-server/
$ sudo mkdir /usr/share/fhq-server/
$ sudo mkdir /usr/share/fhq-server/web-admin
$ sudo mkdir /usr/share/fhq-server/web-user
$ sudo mkdir /usr/share/fhq-server/fhqjad-store

Create config file /etc/fhq-server/fhq-server.conf with content

## Database Configuration
usemysql = yes
storage_type = mysql
dbhost = 127.0.0.1
dbname = fhq
dbport = 3306
dbuser = fhq
dbpass = fhq

## Server configurations
port = 1234
ssl_on = no
ssl_port = 4613
ssl_key_file = /etc/ssl/private/test-selfsigned.key
ssl_cert_file = /etc/ssl/certs/test-selfsigned.crt

# Web Configuration
web_port = 7080
web_max_threads = 1
web_admin_folder = /usr/share/fhq-server/web-admin
web_user_folder = /usr/share/fhq-server/web-user

web_public_folder = /usr/share/fhq-server/public/
web_public_folrer_url = http://localhost:7080/public/

# Jobs Pool Config
jobs_fast_threads = 2
jobs_slow_threads = 1

# fhqjad-store
web_fhqjad_store = /usr/share/fhq-server/fhqjad-store

Reload and restart

$ sudo systemctl daemon-reload
$ sudo systemctl enable fhq-server
$ sudo systemctl restart fhq-server.service

Uninstall

$ sudo systemctl stop fhq-server.service
$ sudo systemctl disable fhq-server.service
$ sudo rm /etc/systemd/system/fhq-server.service
$ sudo systemctl daemon-reload
$ sudo systemctl reset-failed

Sample for init.d script and watchdog cron script

Create a file /etc/init.d/fhq-server with content:

#!/bin/bash

### BEGIN INIT INFO
# Provides:          fhq-server
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
# Required-Start:    $remote_fs $syslog $network mysql
# Required-Stop:     $remote_fs $syslog
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
### END INIT INFO

DAEMON_PATH="/usr/bin/fhq-server"
NAME=freehackquestd
DESC="FreeHackQuest Server"

PIDFILE=/var/run/$NAME.pid
case "$1" in
start)
    printf "%-50s" "Starting $NAME..."
    DATE=`date +%Y%m%d-%H%M%S`
    PID=`/usr/bin/fhq-server -s > /var/log/fhq-server/access-$DATE.log 2> /var/log/fhq-server/error-$DATE.log & echo $!`
    # echo "Saving PID" $PID " to " $PIDFILE
    if [ -z $PID ]; then
        printf "%s\n" "Fail"
    else
        echo $PID > $PIDFILE
        printf "%s\n" "Ok"
    fi ;;
status)
    printf "%-50s" "Checking $NAME..."
    if [ -f $PIDFILE ]; then
        PID=`cat $PIDFILE`
        if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
            printf "%s\n" "Process dead but pidfile exists"
        else
            echo "Running"
        fi
    else
        printf "%s\n" "Service not running"
    fi
;;
stop)
    printf "%-50s" "Stopping $NAME"
    PID=`cat $PIDFILE`
    if [ -f $PIDFILE ]; then
        kill -HUP $PID
        printf "%s\n" "Ok"
        rm -f $PIDFILE
    else
        printf "%s\n" "pidfile not found"
    fi
;;
restart)
    $0 stop
    $0 start
;;
force-reload)
    $0 stop
    $0 start
;;
*)
    echo "Usage: $0 {status|start|stop|restart|force-reload}"
    exit 1
esac

Register and add to autostart

$ sudo update-rc.d -f fhq-server remove
$ sudo update-rc.d fhq-server defaults
$ sudo /etc/init.d/fhq-server start

or for start

$ service fhq-server start

Watchdog Cron config

Create a file /opt/watchdog-fhq-server.sh with content:

#!/bin/bash

COUNT=$(ps -aux | grep fhq-server | wc -l)

if [ $COUNT -ne 2 ]; then
	echo "Need restart backend"
	service fhq-server stop
	service fhq-server restart
fi

Run edit cron config:

$ sudo crontab -e

And add to cron line: * * * * * /opt/watchdog-fhq-server.sh

Development

Method which will return lists

fhq-server input api:

optionalIntegerParam("page_size", "Pgae size")
    .addValidator(new WsjcppValidatorIntegerMinValue(0))
    .addValidator(new WsjcppValidatorIntegerMinValue(10));
optionalIntegerParam("page_index", "Page index")
    .addValidator(new WsjcppValidatorIntegerMinValue(0));

fhq-server output api:

nlohmann::json jsonResult;
jsonResult["items"] = jsonItems;
jsonResult["page_size"] = nPageSize;
jsonResult["page_index"] = nPageIndex;
jsonResult["total"] = nTotal;

nlohmann::json jsonResponse;
jsonResponse["data"] = jsonResult;
pRequest->sendMessageSuccess(cmd(), jsonResponse);

web-admin paginator:

var page_name = 'quests_proposal';
var pg = new SwaPaginator(0, r.data.total, r.data.page_size, r.data.page_index);
el.append(pg.getHtml());
pg.bindPrev(function() {
    window.fhq.changeLocationState({page_name: '', 'page_size': page_size, 'page_index': page_index - 1});
    fhq.pages[page_name]();
});

pg.bindNext(function() {
    window.fhq.changeLocationState({page_name: '', 'page_size': page_size, 'page_index': page_index + 1});
    fhq.pages[page_name]();
});

Publishing client libraries

js library

generate new library

$ ./fhq-server export-libfhqcli-web-javascript

After this merge generated files from freehackquest-libclient-web-js to repository https://github.com/freehackquest/freehackquest-libclient-web-js

Publishing will be some like this:

$ git clone https://github.com/freehackquest/freehackquest-libclient-web-js
$ cd freehackquest-libclient-web-js
$ npm login 
Username: your_login
Password: (password hidden)
Email: (this IS public) your@mail
$ npm publish .
....
+ [email protected]

python (pypi)

generate new library

$ ./fhq-server api export-freehackquest-libclient-py

After this merge generated files from freehackquest-libclient-py to repository https://github.com/freehackquest/freehackquest-libclient-py

$ git clone https://github.com/freehackquest/freehackquest-libclient-py
$ cd freehackquest-libclient-py
$ rm -rf build
$ rm -rf dist
$ rm -rf freehackquest_libclient_py.egg-info

$ python3 setup.py sdist bdist_wheel
$ python3 -m twine upload dist/*

3rdParty

Thanks For

  • Charts.js
  • Sergey Belov (found xss!)
  • Igor Polyakov
  • Maxim Samoilov (Nitive)
  • Dmitrii Mukovkin
  • Team Keva
  • Alexey Gulyaev
  • Alexander Menschikov
  • Ilya Bokov
  • Extrim Code
  • Sergey Ushev
  • Danil Dudkin
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].