From 1e954926c2787738559b6c63ee18bf089dc9e01f Mon Sep 17 00:00:00 2001 From: Josh Abraham <jabra@spl0it.org> Date: Sun, 10 Dec 2023 20:49:45 -0500 Subject: [PATCH 01/15] dry makefiles --- client/makefile | 16 +++++++++++----- makefile | 33 +++++---------------------------- teamserver/Install.sh | 2 +- teamserver/makefile | 25 +++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 34 deletions(-) create mode 100644 teamserver/makefile diff --git a/client/makefile b/client/makefile index 6d54ec21..5bc5588e 100644 --- a/client/makefile +++ b/client/makefile @@ -5,13 +5,19 @@ ifndef VERBOSE endif all: - @ mkdir build; cd build; cmake .. - @ if [ -d "Modules" ]; then echo "Modules installed"; else git clone https://github.com/HavocFramework/Modules Modules; fi - @ cmake --build build -- -j 4 + @ git submodule update --init --recursive + @ mkdir -p Build; cd Build; cmake .. + #@ if [ -d "Modules" ]; then echo "Modules installed"; else git clone --recurse-submodules https://github.com/HavocFramework/Modules Modules --single-branch --branch `git rev-parse --abbrev-ref HEAD`; fi + @ if [ -d "Modules" ]; then echo "Modules installed"; else git clone --recurse-submodules https://github.com/HavocFramework/Modules Modules --single-branch --branch dev; fi + @ cmake --build Build -- -j 4 clean: - @ rm -rf build + @ rm -rf Build + @ rm -rf Bin/* + @ rm -rf ../data/client.db @ rm -rf .idea @ rm -rf cmake-build-debug - @ rm -rf modules @ rm -rf Havoc + @ rm -rf Modules + + diff --git a/makefile b/makefile index 5d3a6dbc..9ddb9e0d 100644 --- a/makefile +++ b/makefile @@ -7,45 +7,22 @@ all: ts-build client-build # teamserver building target ts-build: - @ echo "[*] building teamserver" @ ./teamserver/Install.sh - @ cd teamserver; GO111MODULE="on" go build -ldflags="-s -w -X cmd.VersionCommit=$(git rev-parse HEAD)" -o ../havoc main.go - @ sudo setcap 'cap_net_bind_service=+ep' havoc # this allows you to run the server as a regular user + @ make -C teamserver ts-build dev-ts-compile: - @ echo "[*] compile teamserver" - @ cd teamserver; GO111MODULE="on" go build -ldflags="-s -w -X cmd.VersionCommit=$(git rev-parse HEAD)" -o ../havoc main.go + @ make -C teamserver dev-ts-compile ts-cleanup: - @ echo "[*] teamserver cleanup" - @ rm -rf ./teamserver/bin - @ rm -rf ./data/loot - @ rm -rf ./data/x86_64-w64-mingw32-cross - @ rm -rf ./data/havoc.db - @ rm -rf ./data/server.* - @ rm -rf ./teamserver/.idea - @ rm -rf ./havoc + @ make -C teamserver clean # client building and cleanup targets client-build: - @ echo "[*] building client" - @ git submodule update --init --recursive - @ mkdir client/Build; cd client/Build; cmake .. - @ if [ -d "client/Modules" ]; then echo "Modules installed"; else git clone --recurse-submodules https://github.com/HavocFramework/Modules client/Modules --single-branch --branch `git rev-parse --abbrev-ref HEAD`; fi - @ cmake --build client/Build -- -j 4 + @ make -C client client-cleanup: - @ echo "[*] client cleanup" - @ rm -rf ./client/Build - @ rm -rf ./client/Bin/* - @ rm -rf ./client/Data/database.db - @ rm -rf ./client/.idea - @ rm -rf ./client/cmake-build-debug - @ rm -rf ./client/Havoc - @ rm -rf ./client/Modules - + @ make -C client clean # cleanup target clean: ts-cleanup client-cleanup - @ rm -rf ./data/*.db @ rm -rf payloads/Demon/.idea diff --git a/teamserver/Install.sh b/teamserver/Install.sh index 84f5b633..483a5b0a 100755 --- a/teamserver/Install.sh +++ b/teamserver/Install.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [ ! -d "dir/x86_64-w64-mingw32-cross" ]; then +if [ ! -d "data/x86_64-w64-mingw32-cross" ]; then sudo apt -qq --yes install golang-go nasm mingw-w64 wget >/dev/null 2>&1 if [ ! -d "data" ]; then diff --git a/teamserver/makefile b/teamserver/makefile new file mode 100644 index 00000000..a527929f --- /dev/null +++ b/teamserver/makefile @@ -0,0 +1,25 @@ +MAKEFLAGS += -s + +ifndef VERBOSE +.SILENT: +endif + +# teamserver building target +ts-build: + @ echo "[*] building teamserver" + @ GO111MODULE="on" go build -ldflags="-s -w -X cmd.VersionCommit=$(git rev-parse HEAD)" -o ../havoc main.go + @ sudo setcap 'cap_net_bind_service=+ep' ../havoc # this allows you to run the server as a regular user + +dev-ts-compile: + @ echo "[*] compile teamserver" + @ GO111MODULE="on" go build -ldflags="-s -w -X cmd.VersionCommit=$(git rev-parse HEAD)" -o ../havoc main.go + +clean: + @ rm -rf ../teamserver/bin + @ rm -rf ../data/loot + @ rm -rf ../data/x86_64-w64-mingw32-cross + @ rm -rf ../data/i686-w64-mingw32-cross + @ rm -rf ../data/teamserver.db + @ rm -rf ../data/server.* + @ rm -rf .idea + @ rm -rf ../havoc From 877cf40180fd35f85b3048a99e4c45b612b875a7 Mon Sep 17 00:00:00 2001 From: Josh Abraham <jabra@spl0it.org> Date: Sun, 10 Dec 2023 20:52:23 -0500 Subject: [PATCH 02/15] Modules to use the same branch name --- client/makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/makefile b/client/makefile index 5bc5588e..38e6b31f 100644 --- a/client/makefile +++ b/client/makefile @@ -7,8 +7,7 @@ endif all: @ git submodule update --init --recursive @ mkdir -p Build; cd Build; cmake .. - #@ if [ -d "Modules" ]; then echo "Modules installed"; else git clone --recurse-submodules https://github.com/HavocFramework/Modules Modules --single-branch --branch `git rev-parse --abbrev-ref HEAD`; fi - @ if [ -d "Modules" ]; then echo "Modules installed"; else git clone --recurse-submodules https://github.com/HavocFramework/Modules Modules --single-branch --branch dev; fi + @ if [ -d "Modules" ]; then echo "Modules installed"; else git clone --recurse-submodules https://github.com/HavocFramework/Modules Modules --single-branch --branch `git rev-parse --abbrev-ref HEAD`; fi @ cmake --build Build -- -j 4 clean: From c7f44fc3b43bb2d72976c565e8041d8da20cb013 Mon Sep 17 00:00:00 2001 From: Josh Abraham <jabra@spl0it.org> Date: Sun, 10 Dec 2023 21:05:57 -0500 Subject: [PATCH 03/15] update Install.sh so it can be run from anywhere. --- teamserver/Install.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/teamserver/Install.sh b/teamserver/Install.sh index 483a5b0a..29683825 100755 --- a/teamserver/Install.sh +++ b/teamserver/Install.sh @@ -1,5 +1,10 @@ #!/bin/bash +MYDIR=$(pwd) +if [ "$(basename "$MYDIR")" == "teamserver" ]; then + cd .. +fi + if [ ! -d "data/x86_64-w64-mingw32-cross" ]; then sudo apt -qq --yes install golang-go nasm mingw-w64 wget >/dev/null 2>&1 @@ -20,3 +25,5 @@ if [ ! -d "data/x86_64-w64-mingw32-cross" ]; then tar zxf /tmp/mingw-musl-32.tgz -C data fi + +cd "$MYDIR" From fa92f74f82d856e0f9d0122a2c14bbf8970af83f Mon Sep 17 00:00:00 2001 From: Josh Abraham <jabra@spl0it.org> Date: Sun, 10 Dec 2023 21:12:42 -0500 Subject: [PATCH 04/15] update ts cleanup --- teamserver/Install.sh | 2 +- teamserver/makefile | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/teamserver/Install.sh b/teamserver/Install.sh index 29683825..113b123f 100755 --- a/teamserver/Install.sh +++ b/teamserver/Install.sh @@ -2,7 +2,7 @@ MYDIR=$(pwd) if [ "$(basename "$MYDIR")" == "teamserver" ]; then - cd .. + cd .. fi if [ ! -d "data/x86_64-w64-mingw32-cross" ]; then diff --git a/teamserver/makefile b/teamserver/makefile index a527929f..b2698c81 100644 --- a/teamserver/makefile +++ b/teamserver/makefile @@ -15,7 +15,6 @@ dev-ts-compile: @ GO111MODULE="on" go build -ldflags="-s -w -X cmd.VersionCommit=$(git rev-parse HEAD)" -o ../havoc main.go clean: - @ rm -rf ../teamserver/bin @ rm -rf ../data/loot @ rm -rf ../data/x86_64-w64-mingw32-cross @ rm -rf ../data/i686-w64-mingw32-cross From b357a5542bd944223613005ff0192497d1b60146 Mon Sep 17 00:00:00 2001 From: Josh Abraham <jabra@spl0it.org> Date: Sun, 10 Dec 2023 21:40:57 -0500 Subject: [PATCH 05/15] removed old cleanup folder --- client/makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/client/makefile b/client/makefile index 38e6b31f..1230d00a 100644 --- a/client/makefile +++ b/client/makefile @@ -12,7 +12,6 @@ all: clean: @ rm -rf Build - @ rm -rf Bin/* @ rm -rf ../data/client.db @ rm -rf .idea @ rm -rf cmake-build-debug From 1cfc78531227a942687ab735846ff4a039693654 Mon Sep 17 00:00:00 2001 From: Josh Abraham <jabra@spl0it.org> Date: Mon, 11 Dec 2023 14:52:29 -0500 Subject: [PATCH 06/15] added cicd builds for any branch --- .github/workflows/build.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..61283129 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,28 @@ +name: build + +on: + push: + branches: + - '*' # replace with branch if you only want a specific branch + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.18 + + - name: Install Qt + uses: jurplel/install-qt-action@v3 + + - name: Build teamserver + run: make ts-build + + - name: Build teamserver + run: make client-build From 2d7a4e6f169a8f39195be813c61b471bdb874e6c Mon Sep 17 00:00:00 2001 From: Josh Abraham <jabra@spl0it.org> Date: Mon, 11 Dec 2023 14:52:56 -0500 Subject: [PATCH 07/15] default the client build to use main or dev branch --- client/makefile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/client/makefile b/client/makefile index 1230d00a..753c3d56 100644 --- a/client/makefile +++ b/client/makefile @@ -4,10 +4,22 @@ ifndef VERBOSE .SILENT: endif +BRANCH := $(shell git rev-parse --abbrev-ref HEAD) + +# Check the value of BRANCH and set a target accordingly +ifeq ($(BRANCH), main) + TARGET_BRANCH := main +else ifeq ($(BRANCH), dev) + TARGET_BRANCH := dev +else + TARGET_BRANCH := dev +endif + + all: @ git submodule update --init --recursive @ mkdir -p Build; cd Build; cmake .. - @ if [ -d "Modules" ]; then echo "Modules installed"; else git clone --recurse-submodules https://github.com/HavocFramework/Modules Modules --single-branch --branch `git rev-parse --abbrev-ref HEAD`; fi + @ if [ -d "Modules" ]; then echo "Modules installed"; else git clone --recurse-submodules https://github.com/HavocFramework/Modules Modules --single-branch --branch $(TARGET); fi @ cmake --build Build -- -j 4 clean: From 9c5648113655f8e0f605db52f1bbaa4008844c62 Mon Sep 17 00:00:00 2001 From: Josh Abraham <jabra@spl0it.org> Date: Mon, 11 Dec 2023 14:57:30 -0500 Subject: [PATCH 08/15] Update makefile --- client/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/makefile b/client/makefile index 753c3d56..eb5f4c99 100644 --- a/client/makefile +++ b/client/makefile @@ -19,7 +19,7 @@ endif all: @ git submodule update --init --recursive @ mkdir -p Build; cd Build; cmake .. - @ if [ -d "Modules" ]; then echo "Modules installed"; else git clone --recurse-submodules https://github.com/HavocFramework/Modules Modules --single-branch --branch $(TARGET); fi + @ if [ -d "Modules" ]; then echo "Modules installed"; else git clone --recurse-submodules https://github.com/HavocFramework/Modules Modules --single-branch --branch $(TARGET_BRANCH); fi @ cmake --build Build -- -j 4 clean: From 0c787fd6ff1fc5094275eae77e0cc0e3d6412201 Mon Sep 17 00:00:00 2001 From: Josh Abraham <jabra@spl0it.org> Date: Mon, 11 Dec 2023 15:01:57 -0500 Subject: [PATCH 09/15] client-build --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 61283129..863d659e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,5 +24,5 @@ jobs: - name: Build teamserver run: make ts-build - - name: Build teamserver + - name: Build client run: make client-build From 6178b1a5ab99aea995ffa030be0bc7e52921cb64 Mon Sep 17 00:00:00 2001 From: Josh Abraham <jabra@spl0it.org> Date: Mon, 11 Dec 2023 15:20:40 -0500 Subject: [PATCH 10/15] Update build.yml exclude rewrite --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 863d659e..27f13f12 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,9 @@ on: push: branches: - '*' # replace with branch if you only want a specific branch - + branches-ignore: + - client-rewrite + jobs: build: runs-on: ubuntu-latest From 48d100dfa094e06f8456ae76672516047ced7f2b Mon Sep 17 00:00:00 2001 From: Josh Abraham <jabra@spl0it.org> Date: Mon, 11 Dec 2023 15:23:55 -0500 Subject: [PATCH 11/15] Update build.yml --- .github/workflows/build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 27f13f12..706bb0fa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,8 +2,6 @@ name: build on: push: - branches: - - '*' # replace with branch if you only want a specific branch branches-ignore: - client-rewrite From c86a17d3e572e91e13649a8647715c6bb427e420 Mon Sep 17 00:00:00 2001 From: Josh Abraham <jabra@spl0it.org> Date: Mon, 11 Dec 2023 22:56:50 -0500 Subject: [PATCH 12/15] Update build.yml --- .github/workflows/build.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 706bb0fa..86a4e8f2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,10 +1,7 @@ name: build -on: - push: - branches-ignore: - - client-rewrite - +on: [pull_request, push] + jobs: build: runs-on: ubuntu-latest From 29590c9ed1cd18ef408cc4717a6d2e36081145c3 Mon Sep 17 00:00:00 2001 From: Josh Abraham <jabra@spl0it.org> Date: Tue, 12 Dec 2023 15:18:31 -0500 Subject: [PATCH 13/15] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 86a4e8f2..355f55b5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: steps: - name: Checkout Repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Go uses: actions/setup-go@v2 From 053fac9fe74e4844a4e48e1db1647a00f328e713 Mon Sep 17 00:00:00 2001 From: Josh Abraham <jabra@spl0it.org> Date: Thu, 11 Jan 2024 09:47:06 -0500 Subject: [PATCH 14/15] Update Install.sh improved teamserver/Install.sh script --- teamserver/Install.sh | 66 ++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/teamserver/Install.sh b/teamserver/Install.sh index 113b123f..318fcc10 100755 --- a/teamserver/Install.sh +++ b/teamserver/Install.sh @@ -1,29 +1,57 @@ #!/bin/bash +set -e + MYDIR=$(pwd) + +# Check if the script is in the "teamserver" directory and adjust the current directory if [ "$(basename "$MYDIR")" == "teamserver" ]; then - cd .. + cd .. fi -if [ ! -d "data/x86_64-w64-mingw32-cross" ]; then - sudo apt -qq --yes install golang-go nasm mingw-w64 wget >/dev/null 2>&1 - - if [ ! -d "data" ]; then - mkdir data - fi - - if [ ! -f /tmp/mingw-musl-64.tgz ]; then - wget https://musl.cc/x86_64-w64-mingw32-cross.tgz -q -O /tmp/mingw-musl-64.tgz - fi - - - tar zxf /tmp/mingw-musl-64.tgz -C data - - if [ ! -f /tmp/mingw-musl-32.tgz ]; then - wget https://musl.cc/i686-w64-mingw32-cross.tgz -q -O /tmp/mingw-musl-32.tgz - fi +# Check Linux distribution +if [ -x "$(command -v lsb_release)" ]; then + DISTRIBUTION=$(lsb_release -si) +else + DISTRIBUTION=$(cat /etc/os-release | grep "^ID=" | cut -d'=' -f2 | tr -d '"') +fi - tar zxf /tmp/mingw-musl-32.tgz -C data +# Check if DISTRIBUTION is defined +if [ -n "$DISTRIBUTION" ]; then + if [ "$DISTRIBUTION" == "Ubuntu" ] || [ "$DISTRIBUTION" == "Debian" ]; then + echo "Installing required packages on $DISTRIBUTION..." + sudo apt -qq --yes install golang-go nasm mingw-w64 wget >/dev/null 2>&1 || { echo "Error: Failed to install required packages."; exit 1; } + else + echo "Warning: Unsupported distribution: $DISTRIBUTION. Please manual install the required packages." + fi +else + echo "Warning: Failed to determine the OS. Please manual install the required packages." +fi + +# Check and download cross-compiler packages if not present +if [ ! -d "data/x86_64-w64-mingw32-cross" ]; then + # Check if wget is available + if ! command -v wget &>/dev/null; then + echo "Error: wget is not installed. Please install wget and run the script again." + exit 1 + fi + + # Create data directory if it doesn't exist + if [ ! -d "data" ]; then + mkdir data || { echo "Error: Failed to create directory 'data'"; exit 1; } + fi + + # Download and extract x86_64-w64-mingw32-cross.tgz + if [ ! -f /tmp/mingw-musl-64.tgz ]; then + wget https://musl.cc/x86_64-w64-mingw32-cross.tgz -q -O /tmp/mingw-musl-64.tgz || { echo "Error: Failed to download https://musl.cc/x86_64-w64-mingw32-cross.tgz"; exit 1; } + fi + tar zxf /tmp/mingw-musl-64.tgz -C data || { echo "Error: Failed to extract /tmp/mingw-musl-64.tgz"; exit 1; } + + # Download and extract i686-w64-mingw32-cross.tgz + if [ ! -f /tmp/mingw-musl-32.tgz ]; then + wget https://musl.cc/i686-w64-mingw32-cross.tgz -q -O /tmp/mingw-musl-32.tgz || { echo "Error: Failed to download https://musl.cc/i686-w64-mingw32-cross.tgz"; exit 1; } + fi + tar zxf /tmp/mingw-musl-32.tgz -C data || { echo "Error: Failed to extract /tmp/mingw-musl-32.tgz"; exit 1; } fi cd "$MYDIR" From 5c0ba7dfa9d3e9c0da1174e2108e0c4577148351 Mon Sep 17 00:00:00 2001 From: Josh Abraham <jabra@spl0it.org> Date: Tue, 16 Jan 2024 13:25:23 -0500 Subject: [PATCH 15/15] Update makefile cleanup .tgz files. --- teamserver/makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/teamserver/makefile b/teamserver/makefile index b2698c81..afc39192 100644 --- a/teamserver/makefile +++ b/teamserver/makefile @@ -22,3 +22,5 @@ clean: @ rm -rf ../data/server.* @ rm -rf .idea @ rm -rf ../havoc + @ rm -rf /tmp/mingw-musl-64.tgz + @ rm -rf /tmp/mingw-musl-32.tgz