unfucked the havoc_installer

This commit is contained in:
n0mad1k
2025-04-24 06:24:43 -04:00
parent 4e895f4eb1
commit 29f5bca435
+48 -34
View File
@@ -1,6 +1,7 @@
#!/bin/bash
# Streamlined Havoc C2 Framework installer with EDR evasion features
# This script automatically installs Havoc and prepares it for configuration
# Enhanced Havoc C2 Framework installer optimized for Red Team Operations
# This script installs and configures Havoc with EDR evasion features
# The mutation features are applied BEFORE building to ensure proper compilation
set -e
TEMP_DIR=$(mktemp -d)
@@ -11,6 +12,7 @@ COMPILER_URL="http://musl.cc/x86_64-w64-mingw32-cross.tgz"
COMPILER_DIR="/usr/bin/x86_64-w64-mingw32-cross"
COMPILER_PATH="$COMPILER_DIR/bin/x86_64-w64-mingw32-gcc"
IMPLANT_MUTATOR_SCRIPT="$HAVOC_DIR/implant_mutator.sh"
HAVOC_GITHUB="https://github.com/HavocFramework/Havoc.git"
# Function to log messages
log() {
@@ -29,12 +31,16 @@ RANDOMIZED_BUILD_ID=$(random_string 16)
# Install required dependencies
log "Installing dependencies..."
apt-get update >/dev/null 2>&1
apt-get install -y git golang-go make build-essential mingw-w64 nasm cmake \
ninja-build python3-pip libfontconfig1 libglu1-mesa-dev libgtest-dev \
libspdlog-dev libboost-all-dev libncurses5-dev libgdbm-dev libssl-dev \
libreadline-dev libffi-dev libsqlite3-dev libbz2-dev mesa-common-dev \
qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools libqt5websockets5 \
libqt5websockets5-dev binutils-dev wget >/dev/null 2>&1
apt-get install -y git build-essential apt-utils cmake libfontconfig1 libglu1-mesa-dev libgtest-dev libspdlog-dev libboost-all-dev libncurses5-dev libgdbm-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev mesa-common-dev qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools libqt5websockets5 libqt5websockets5-dev qtdeclarative5-dev golang-go qtbase5-dev libqt5websockets5-dev python3-dev libboost-all-dev mingw-w64 nasm >/dev/null 2>&1
# Fix for JSON dependency
log "Installing nlohmann-json manually..."
mkdir -p /tmp/json
cd /tmp/json
wget -q https://github.com/nlohmann/json/releases/download/v3.11.2/json.hpp
mkdir -p /usr/include/nlohmann
cp json.hpp /usr/include/nlohmann/
cd - > /dev/null
# Setup Go environment
log "Setting up Go environment..."
@@ -72,6 +78,7 @@ if [ -d "$HAVOC_DIR" ]; then
cd $HAVOC_DIR
git pull
else
# Clone with proper GitHub URL
git clone --quiet -b dev $HAVOC_GITHUB $HAVOC_DIR
cd $HAVOC_DIR
fi
@@ -81,11 +88,13 @@ mkdir -p $HAVOC_DATA_DIR
mkdir -p $HAVOC_DIR/payloads
mkdir -p $HAVOC_DIR/payloads/backup
# Apply source mutations first (before building)
log "Applying implant mutations with signature: $RANDOMIZED_BUILD_ID"
# We'll skip the metadata.go modification since it's not essential
# Initialize submodules
log "Initializing submodules..."
cd $HAVOC_DIR
git submodule init
git submodule update --recursive
# Create implant mutator script
# Create implant mutator script BEFORE building
log "Creating implant mutator script..."
cat > "$IMPLANT_MUTATOR_SCRIPT" << 'EOF'
#!/bin/bash
@@ -93,7 +102,7 @@ cat > "$IMPLANT_MUTATOR_SCRIPT" << 'EOF'
# Randomizes critical implant signatures to avoid detection
# === CONFIG ===
HAVOC_ROOT="${HAVOC_ROOT:-$HOME/Tools/Havoc}"
HAVOC_ROOT="${HAVOC_ROOT:-$HOME/Tools/havoc}"
IMPLANT_DIR="$HAVOC_ROOT/payloads/Demon"
SRC_DIR="$IMPLANT_DIR/src"
OUTPUT_DIR="$HAVOC_ROOT/payloads"
@@ -550,22 +559,34 @@ EOF
chmod +x "$IMPLANT_MUTATOR_SCRIPT"
# Build Havoc teamserver with custom compiler flags
log "Building Havoc teamserver..."
# Perform mutations BEFORE building - this is critical
log "Running implant mutations script before building..."
if [ -d "$HAVOC_DIR/payloads/Demon" ]; then
$IMPLANT_MUTATOR_SCRIPT --no-functions
if [ $? -ne 0 ]; then
log "Warning: Implant mutation script ran with errors, but continuing build..."
fi
else
log "Skipping implant mutations as Demon directory not found yet. Will be applied after build."
fi
# Install additional Go dependencies for the teamserver
log "Installing Go dependencies for teamserver..."
cd $HAVOC_DIR/teamserver
export EXTRA_GOFLAGS="-ldflags=-buildid=$(random_string 16)"
go build -trimpath -ldflags="-w -s -buildid=$(random_string 16)" -o havoc main.go
go mod download golang.org/x/sys
cd $HAVOC_DIR
# Build Havoc using make - build teamserver first
log "Building Havoc teamserver..."
cd $HAVOC_DIR
make ts-build
# Build Havoc client
log "Building Havoc client..."
cd $HAVOC_DIR/client
mkdir -p build
cd build
cmake -GNinja ..
ninja
make client-build
# Create systemd service for Havoc
log "Creating systemd service for Havoc Teamserver..."
log "Creating systemd service for Havoc teamserver..."
cat > /etc/systemd/system/havoc.service << EOF
[Unit]
Description=Advanced Security Service
@@ -576,7 +597,7 @@ Type=simple
User=root
Group=root
WorkingDirectory=$HAVOC_DIR/teamserver
ExecStart=$HAVOC_DIR/teamserver/havoc server -d
ExecStart=$HAVOC_DIR/havoc server -d
Restart=always
RestartSec=10
@@ -591,23 +612,16 @@ EOF
# Set proper permissions
log "Setting proper permissions..."
chmod 755 $HAVOC_DIR/teamserver/havoc
chmod 755 $HAVOC_DIR/client/havoc
chmod -R 755 $HAVOC_DIR
# Create symlinks to executables in /usr/local/bin
ln -sf $HAVOC_DIR/teamserver/havoc /usr/local/bin/havoc-server
ln -sf $HAVOC_DIR/client/havoc /usr/local/bin/havoc-client
ln -sf $HAVOC_DIR/havoc /usr/local/bin/havoc
ln -sf $IMPLANT_MUTATOR_SCRIPT /usr/local/bin/havoc-mutate
# Run the implant mutator
log "Running initial implant mutation..."
$IMPLANT_MUTATOR_SCRIPT --no-functions
# Enable and start Havoc service
log "Enabling and starting Havoc service..."
systemctl daemon-reload
systemctl enable havoc
systemctl start havoc
log "Havoc C2 installation completed successfully!"
log "Use the template-based configuration for additional setup."
log "Havoc C2 installation completed successfully!"