Got attack box and c2-redirector working

This commit is contained in:
n0mad1k
2025-08-21 16:25:00 -04:00
parent 1450a55e50
commit f7dadf5b83
93 changed files with 14924 additions and 3727 deletions
+258
View File
@@ -0,0 +1,258 @@
#!/usr/bin/env python3
"""
Redirector infrastructure deployment module
"""
import os
import sys
import logging
# Add the project root to the path so we can import utils
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
from utils.common import (
COLORS, clear_screen, print_banner, generate_deployment_id,
setup_logging, get_public_ip, confirm_action, wait_for_input
)
from utils.provider_utils import select_provider, gather_provider_config
from utils.ssh_utils import generate_ssh_key
def gather_redirector_parameters():
"""Collect parameters specific to redirector deployments"""
clear_screen()
print_banner()
print(f"{COLORS['WHITE']}REDIRECTOR INFRASTRUCTURE SETUP{COLORS['RESET']}")
print(f"{COLORS['WHITE']}================================{COLORS['RESET']}")
config = {}
# Generate deployment ID
config['deployment_id'] = generate_deployment_id()
print(f"Deployment ID: {COLORS['CYAN']}{config['deployment_id']}{COLORS['RESET']}")
# Provider selection
provider = select_provider()
if not provider:
return None
config['provider'] = provider
# Get provider-specific configuration
provider_config = gather_provider_config(provider)
if not provider_config:
return None
config.update(provider_config)
# Redirector-specific configuration
print(f"\n{COLORS['BLUE']}Redirector Configuration{COLORS['RESET']}")
# Domain configuration
domain = input(f"Domain for redirector [required]: ")
if not domain:
print(f"{COLORS['RED']}A domain is required for redirector deployments{COLORS['RESET']}")
return None
config['domain'] = domain
# Subdomain configuration
config['redirector_subdomain'] = input("Redirector subdomain [default: cdn]: ") or "cdn"
# Backend configuration
backend_type = input("Backend type (c2/phishing/payload) [default: c2]: ") or "c2"
config['backend_type'] = backend_type
if backend_type in ['c2', 'phishing']:
backend_ip = input(f"Backend {backend_type} server IP [required]: ")
if not backend_ip:
print(f"{COLORS['RED']}Backend server IP is required{COLORS['RESET']}")
return None
config['backend_ip'] = backend_ip
backend_port = input(f"Backend {backend_type} server port [default: 443]: ") or "443"
config['backend_port'] = backend_port
# Redirector type
print(f"\n{COLORS['BLUE']}Redirector Type:{COLORS['RESET']}")
print(f"1) HTTPS Redirector")
print(f"2) DNS Redirector")
print(f"3) SMTP Redirector")
redirector_choice = input("Select redirector type [default: 1]: ") or "1"
redirector_types = {
"1": "https",
"2": "dns",
"3": "smtp"
}
config['redirector_type'] = redirector_types.get(redirector_choice, "https")
# Email for Let's Encrypt (for HTTPS redirectors)
if config['redirector_type'] == 'https':
default_email = f"admin@{config['domain']}"
config['letsencrypt_email'] = input(f"Email for Let's Encrypt [default: {default_email}]: ") or default_email
# Get operator IP for security
suggested_ip = get_public_ip()
if suggested_ip:
operator_ip = input(f"Your public IP for secure access [detected: {suggested_ip}]: ") or suggested_ip
else:
operator_ip = input("Your public IP for secure access: ")
config['operator_ip'] = operator_ip
# SSH key generation
ssh_key_path = generate_ssh_key(config['deployment_id'])
if not ssh_key_path:
print(f"{COLORS['RED']}Failed to generate SSH key{COLORS['RESET']}")
return None
config['ssh_key_path'] = f"{ssh_key_path}.pub"
# Post-deployment options
config['ssh_after_deploy'] = confirm_action("SSH into instance after deployment?", default=True)
return config
def redirector_menu():
"""Display the redirector submenu and handle user selection"""
while True:
clear_screen()
print_banner()
print(f"{COLORS['WHITE']}REDIRECTOR INFRASTRUCTURE MENU{COLORS['RESET']}")
print(f"{COLORS['WHITE']}==============================={COLORS['RESET']}")
print(f"1) C2 Redirector {COLORS['GREEN']}*COMMON*{COLORS['RESET']} {COLORS['GRAY']}(C2 traffic redirection){COLORS['RESET']}")
print(f"2) HTTPS Redirector {COLORS['GRAY']}(Web traffic redirection){COLORS['RESET']}")
print(f"3) Payload Redirector {COLORS['GRAY']}(Payload delivery redirection){COLORS['RESET']}")
print(f"4) Phishing Redirector {COLORS['GRAY']}(Phishing traffic redirection){COLORS['RESET']}")
print(f"5) DNS Redirector {COLORS['GRAY']}(DNS-based redirection){COLORS['RESET']}")
print(f"6) SMTP Redirector {COLORS['GRAY']}(Email traffic redirection){COLORS['RESET']}")
print(f"99) Return to Main Menu")
choice = input(f"\nSelect an option: ")
if choice == "1":
deploy_c2_redirector()
elif choice == "2":
deploy_https_redirector()
elif choice == "3":
deploy_payload_redirector()
elif choice == "4":
deploy_phishing_redirector()
elif choice == "5":
deploy_dns_redirector()
elif choice == "6":
deploy_smtp_redirector()
elif choice == "99":
return
else:
print(f"\n{COLORS['RED']}Invalid option. Please try again.{COLORS['RESET']}")
wait_for_input()
def deploy_https_redirector():
"""Deploy HTTPS redirector"""
config = gather_redirector_parameters()
if not config:
return
config['redirector_type'] = 'https'
config['deployment_type'] = 'https_redirector'
print(f"\n{COLORS['GREEN']}Deploying HTTPS redirector...{COLORS['RESET']}")
execute_redirector_deployment(config)
def deploy_dns_redirector():
"""Deploy DNS redirector"""
config = gather_redirector_parameters()
if not config:
return
config['redirector_type'] = 'dns'
config['deployment_type'] = 'dns_redirector'
print(f"\n{COLORS['GREEN']}Deploying DNS redirector...{COLORS['RESET']}")
execute_redirector_deployment(config)
def deploy_smtp_redirector():
"""Deploy SMTP redirector"""
config = gather_redirector_parameters()
if not config:
return
config['redirector_type'] = 'smtp'
config['deployment_type'] = 'smtp_redirector'
print(f"\n{COLORS['GREEN']}Deploying SMTP redirector...{COLORS['RESET']}")
execute_redirector_deployment(config)
def deploy_payload_redirector():
"""Deploy payload redirector"""
config = gather_redirector_parameters()
if not config:
return
config['backend_type'] = 'payload'
config['deployment_type'] = 'payload_redirector'
print(f"\n{COLORS['GREEN']}Deploying payload redirector...{COLORS['RESET']}")
execute_redirector_deployment(config)
def deploy_phishing_redirector():
"""Deploy phishing redirector"""
config = gather_redirector_parameters()
if not config:
return
config['backend_type'] = 'phishing'
config['deployment_type'] = 'phishing_redirector'
print(f"\n{COLORS['GREEN']}Deploying phishing redirector...{COLORS['RESET']}")
execute_redirector_deployment(config)
def deploy_c2_redirector():
"""Deploy C2 redirector"""
config = gather_redirector_parameters()
if not config:
return
config['backend_type'] = 'c2'
config['deployment_type'] = 'c2_redirector'
print(f"\n{COLORS['GREEN']}Deploying C2 redirector...{COLORS['RESET']}")
execute_redirector_deployment(config)
def execute_redirector_deployment(config):
"""Execute redirector infrastructure deployment"""
clear_screen()
print_banner()
print(f"\n{COLORS['GREEN']}Starting redirector deployment...{COLORS['RESET']}")
# Display configuration summary
print(f"\n{COLORS['CYAN']}Deployment Summary:{COLORS['RESET']}")
print(f"Deployment Type: {config['deployment_type']}")
print(f"Deployment ID: {config['deployment_id']}")
print(f"Provider: {config['provider']}")
print(f"Domain: {config['domain']}")
print(f"Redirector Type: {config['redirector_type']}")
print(f"Backend Type: {config.get('backend_type', 'N/A')}")
# Confirm deployment
if not confirm_action(f"\n{COLORS['YELLOW']}Proceed with redirector deployment?{COLORS['RESET']}", default=False):
print(f"\n{COLORS['YELLOW']}Deployment cancelled.{COLORS['RESET']}")
return
# Set deployment flags for redirector-only deployment
config['redirector_only'] = True
config['c2_only'] = False
# Execute the actual deployment using the deployment engine
from utils.deployment_engine import deploy_infrastructure
success = deploy_infrastructure(config)
if success:
print(f"\n{COLORS['GREEN']}Redirector infrastructure deployed successfully!{COLORS['RESET']}")
if config.get('ssh_after_deploy'):
from utils.ssh_utils import ssh_to_instance
ssh_to_instance(config)
else:
print(f"\n{COLORS['RED']}Redirector infrastructure deployment failed.{COLORS['RESET']}")
wait_for_input()
if __name__ == "__main__":
redirector_menu()
@@ -18,7 +18,7 @@
until: cache_update is success
retries: 5
delay: 10
ignore_errors: no
ignore_errors: false
- name: Install core packages first (high priority)
apt:
@@ -101,7 +101,7 @@
apt-get install -y --no-install-recommends certbot
apt-get install -y --fix-broken || true
register: certbot_manual
ignore_errors: yes
ignore_errors: true
- name: Install certbot via snap as ultimate fallback
block:
@@ -141,7 +141,7 @@
- zope.hookable
state: present
register: pip_install
ignore_errors: yes
ignore_errors: true
- name: Download and install packages manually if repositories are down
shell: |
@@ -154,7 +154,7 @@
dpkg -i python3-requests-toolbelt_*.deb || apt-get install -f -y
fi
when: pip_install is failed
ignore_errors: yes
ignore_errors: true
- name: Verify critical packages are installed
command: "{{ item.cmd }}"
@@ -165,7 +165,7 @@
- { cmd: "socat -V", name: "socat" }
- { cmd: "jq --version", name: "jq" }
- { cmd: "which certbot", name: "certbot" }
ignore_errors: yes
ignore_errors: true
- name: Create package installation report
debug:
@@ -190,7 +190,7 @@
dpkg --configure -a
when: core_packages is failed or certbot_install is failed
register: fix_broken
ignore_errors: yes
ignore_errors: true
- name: Final package status check and remediation
block:
@@ -211,6 +211,17 @@
debug:
var: final_status.stdout_lines
- name: Detect installed PHP-FPM service
shell: |
# Try to find any PHP-FPM service
if systemctl list-units --type=service --all | grep -q 'php.*fpm'; then
systemctl list-units --type=service --all | grep 'php.*fpm' | head -1 | awk '{print $1}' | sed 's/\.service//'
else
echo "php-fpm"
fi
register: php_fpm_service
failed_when: false
- name: Ensure critical services are enabled
systemd:
name: "{{ item }}"
@@ -218,8 +229,8 @@
state: started
loop:
- nginx
- php7.4-fpm
ignore_errors: yes
- "{{ php_fpm_service.stdout }}"
ignore_errors: true
register: service_start
- name: Create operational readiness marker
@@ -244,7 +255,7 @@
- name: Copy clean-logs.sh script
copy:
src: "../files/clean-logs.sh"
src: "../../../common/files/clean-logs.sh"
dest: /root/Tools/clean-logs.sh
mode: '0700'
owner: root
@@ -252,7 +263,7 @@
- name: Copy redirector post-install script
copy:
src: "../files/post_install_redirector.sh"
src: "../../../common/files/post_install_redirector.sh"
dest: "/root/Tools/post_install_redirector.sh"
mode: '0700'
owner: root
@@ -260,7 +271,7 @@
- name: Copy port randomization script
copy:
src: "../files/randomize_ports.sh"
src: "../../../common/files/randomize_ports.sh"
dest: "/root/Tools/randomize_ports.sh"
mode: '0700'
owner: root
@@ -292,7 +303,7 @@
- name: Copy shell handler script
copy:
src: "../files/havoc_shell_handler.sh"
src: "../../c2/files/havoc_shell_handler.sh"
dest: /root/Tools/shell-handler/persistent-listener.sh
mode: '0700'
owner: root
@@ -306,7 +317,7 @@
- name: Configure shell handler script with listening port
template:
src: "../files/havoc_shell_handler.sh"
src: "../../c2/files/havoc_shell_handler.sh"
dest: "/root/Tools/shell_handler.sh"
mode: 0755
vars:
@@ -327,7 +338,7 @@
mode: '0644'
owner: root
group: root
when: zero_logs | bool
when: zero_logs | default(false) | bool
- name: Create payload directory
file:
@@ -338,11 +349,11 @@
group: www-data
- name: Include traffic flow configuration
include_tasks: "../tasks/traffic_flow_config.yml"
include_tasks: "../../common/tasks/traffic_flow_config.yml"
# Run port randomization if enabled
- name: Run port randomization if enabled
include_tasks: port_randomization.yml
include_tasks: "../../common/tasks/port_randomization.yml"
when: randomize_ports | default(true) | bool
# Add just before configuring NGINX
@@ -454,4 +465,4 @@
minute: "0"
hour: "*/6"
job: "/root/Tools/clean-logs.sh > /dev/null 2>&1"
when: zero_logs | bool
when: zero_logs | default(false) | bool
@@ -0,0 +1,106 @@
<!DOCTYPE html>
<html>
<head>
<title>Sign in to your account</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #f0f0f0, #e0e0e0);
margin: 0;
padding: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.login-container {
background: white;
width: 380px;
padding: 30px 40px;
box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.logo {
text-align: left;
margin-bottom: 20px;
}
h1 {
font-size: 24px;
font-weight: 600;
margin: 20px 0 15px;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 8px 0;
margin-bottom: 15px;
border: none;
border-bottom: 1px solid #ccc;
font-size: 15px;
outline: none;
}
input:focus {
border-bottom: 1px solid #0067b8;
}
.button-container {
text-align: right;
margin-top: 20px;
}
button {
background-color: #0067b8;
color: white;
border: none;
padding: 8px 24px;
font-size: 14px;
cursor: pointer;
}
.links {
margin-top: 20px;
font-size: 13px;
}
.links a {
color: #0067b8;
text-decoration: none;
}
.footer {
position: fixed;
bottom: 0;
width: 100%;
display: flex;
justify-content: space-between;
padding: 10px 20px;
font-size: 12px;
color: #666;
}
.footer a {
color: #666;
text-decoration: none;
margin-left: 20px;
}
</style>
</head>
<body>
<div class="login-container">
<div class="logo">
<img src="https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE1Mu3b?ver=5c31" alt="Microsoft" width="108">
</div>
<h1>Sign in</h1>
<form action="process.php" method="post">
<input type="text" name="email" placeholder="Email, phone, or Skype" required>
<input type="password" name="password" placeholder="Password" required>
<div class="links">
<a href="https://signup.live.com/signup">No account? Create one!</a><br>
<a href="https://account.live.com/password/reset">Can't access your account?</a>
</div>
<div class="button-container">
<button type="submit">Next</button>
</div>
</form>
</div>
<div class="footer">
<div class="terms">
<a href="https://www.microsoft.com/en-us/servicesagreement/default.aspx">Terms of use</a>
<a href="https://www.microsoft.com/en-us/privacy/privacystatement">Privacy & cookies</a>
</div>
</div>
</body>
</html>
@@ -0,0 +1,23 @@
================================================================
C2itall Redirector Post-Installation Instructions
================================================================
To complete your setup with SSL certificates, run:
/root/Tools/post_install_redirector.sh
This script will guide you through:
- Setting up Let's Encrypt certificates
- Starting required services
- Updating NGINX configuration
For enhanced OPSEC, you can also randomize ports:
/root/Tools/randomize_ports.sh
Run these after you've configured your DNS records to point to this server.
================================================================
Deployment ID: {{ deployment_id | default('N/A') }}
Domain: {{ domain | default('N/A') }}
Infrastructure Type: Redirector
Provider: {{ provider | default('N/A') }}
================================================================
@@ -0,0 +1,22 @@
#!/bin/bash
# Let's Encrypt Certificate Setup Script
# Run this after setting up DNS records pointing to this server
# Replace these with your actual values if needed
DOMAIN="{{ domain }}"
SUBDOMAIN="{{ redirector_subdomain | default(cdn) }}"
EMAIL="admin@${DOMAIN}"
echo "================================================"
echo "Let's Encrypt Certificate Setup"
echo "================================================"
echo
echo "Before running this script, make sure:"
echo "1. DNS records are set up correctly"
echo " - ${SUBDOMAIN}.${DOMAIN} points to $(curl -s ifconfig.me)"
echo "2. Port 80 is open to the internet"
echo
echo "Run the following command to get your certificate:"
echo "certbot --nginx -d ${SUBDOMAIN}.${DOMAIN} --non-interactive --agree-tos -m ${EMAIL}"
echo
echo "================================================"
@@ -0,0 +1,28 @@
[Unit]
Description=Reverse Shell Handler Service
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/root/Tools/shell-handler/persistent-listener.sh
Restart=always
RestartSec=10
# Hide process information
PrivateTmp=true
ProtectSystem=full
NoNewPrivileges=true
# Make shell handler hard to find
StandardOutput=null
StandardError=null
# Environment variables (configured via Ansible)
Environment="C2_HOST={{ c2_ip | default('127.0.0.1') }}"
Environment="LISTEN_PORT={{ shell_handler_port | default('4444') }}"
Environment="HAVOC_PORT={{ havoc_teamserver_port | default('40056') }}"
[Install]
WantedBy=multi-user.target