fixing things
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
LISTEN_PORT=4444
|
||||
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="/opt/beacons/windows.exe"
|
||||
LINUX_BEACON="/opt/beacons/linux"
|
||||
MACOS_BEACON="/opt/beacons/macos"
|
||||
WINDOWS_BEACON="/root/Tools/beacons/windows.exe"
|
||||
LINUX_BEACON="/root/Tools/beacons/linux"
|
||||
MACOS_BEACON="/root/Tools/beacons/macos"
|
||||
|
||||
# Set secure permissions
|
||||
umask 077
|
||||
@@ -16,7 +16,7 @@ umask 077
|
||||
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 >> /opt/shell-handler/activity.log.enc
|
||||
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
|
||||
|
||||
@@ -0,0 +1,405 @@
|
||||
#!/bin/bash
|
||||
# post_install_c2.sh - Post-installation setup for C2 server
|
||||
|
||||
# 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 Post-Installation Setup - C2 Server ${NC}"
|
||||
echo -e "${BLUE}==================================================${NC}"
|
||||
|
||||
# Function to check if domain resolves to current IP
|
||||
check_dns() {
|
||||
domain=$1
|
||||
current_ip=$(curl -s ifconfig.me)
|
||||
resolved_ip=$(dig +short $domain)
|
||||
|
||||
if [ "$resolved_ip" = "$current_ip" ]; then
|
||||
echo -e "${GREEN}DNS check passed for $domain!${NC}"
|
||||
return 0
|
||||
else
|
||||
echo -e "${YELLOW}DNS check failed for $domain${NC}"
|
||||
echo -e "Current IP: $current_ip"
|
||||
echo -e "Resolved IP: $resolved_ip"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to set up Let's Encrypt
|
||||
setup_letsencrypt() {
|
||||
domain=$1
|
||||
email=$2
|
||||
|
||||
echo -e "\n${BLUE}Setting up Let's Encrypt for $domain${NC}"
|
||||
|
||||
# Check if certificate already exists
|
||||
if [ -d "/etc/letsencrypt/live/$domain" ]; then
|
||||
echo -e "${YELLOW}Certificate already exists for $domain${NC}"
|
||||
read -p "Do you want to renew it? (y/n): " renew
|
||||
if [ "$renew" != "y" ]; then
|
||||
echo -e "${YELLOW}Skipping certificate renewal${NC}"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Stop nginx if running to free up port 80
|
||||
systemctl stop nginx 2>/dev/null
|
||||
|
||||
# Get certificate
|
||||
certbot certonly --standalone -d $domain -m $email --agree-tos --non-interactive
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Successfully obtained certificate for $domain${NC}"
|
||||
return 0
|
||||
else
|
||||
echo -e "${RED}Failed to obtain certificate for $domain${NC}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to set up mail subdomain
|
||||
setup_mail_subdomain() {
|
||||
domain=$1
|
||||
mail_domain="mail.$domain"
|
||||
email=$2
|
||||
|
||||
echo -e "\n${BLUE}Setting up Let's Encrypt for mail subdomain $mail_domain${NC}"
|
||||
|
||||
if [ -d "/etc/letsencrypt/live/$mail_domain" ]; then
|
||||
echo -e "${YELLOW}Certificate already exists for $mail_domain${NC}"
|
||||
read -p "Do you want to renew it? (y/n): " renew
|
||||
if [ "$renew" != "y" ]; then
|
||||
echo -e "${YELLOW}Skipping certificate renewal${NC}"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
certbot certonly --standalone -d $mail_domain -m $email --agree-tos --non-interactive
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Successfully obtained certificate for $mail_domain${NC}"
|
||||
return 0
|
||||
else
|
||||
echo -e "${RED}Failed to obtain certificate for $mail_domain${NC}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to start services
|
||||
start_services() {
|
||||
echo -e "\n${BLUE}Starting required services${NC}"
|
||||
|
||||
# Restart Sliver
|
||||
systemctl restart sliver
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Sliver C2 started successfully${NC}"
|
||||
else
|
||||
echo -e "${RED}Failed to start Sliver C2${NC}"
|
||||
fi
|
||||
|
||||
# Start nginx
|
||||
systemctl start nginx
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}NGINX started successfully${NC}"
|
||||
else
|
||||
echo -e "${RED}Failed to start NGINX${NC}"
|
||||
fi
|
||||
|
||||
# Start Postfix
|
||||
systemctl start postfix
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Postfix started successfully${NC}"
|
||||
else
|
||||
echo -e "${RED}Failed to start Postfix${NC}"
|
||||
fi
|
||||
|
||||
# Start Dovecot
|
||||
systemctl start dovecot
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Dovecot started successfully${NC}"
|
||||
else
|
||||
echo -e "${RED}Failed to start Dovecot${NC}"
|
||||
fi
|
||||
|
||||
# Start the beacon server
|
||||
if pgrep -f "serve-beacons.sh" > /dev/null; then
|
||||
echo -e "${YELLOW}Beacon server already running${NC}"
|
||||
else
|
||||
nohup /root/Tools/serve-beacons.sh > /dev/null 2>&1 &
|
||||
echo -e "${GREEN}Started beacon server${NC}"
|
||||
fi
|
||||
|
||||
# If tracker is installed, start it
|
||||
if [ -d "/root/Tools/tracker" ]; then
|
||||
systemctl start tracker
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Email tracker started successfully${NC}"
|
||||
else
|
||||
echo -e "${RED}Failed to start email tracker${NC}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to generate DKIM DNS records
|
||||
generate_dkim_records() {
|
||||
domain=$1
|
||||
|
||||
if [ -f "/etc/opendkim/keys/$domain/mail.txt" ]; then
|
||||
echo -e "\n${BLUE}DKIM DNS Record Information for $domain${NC}"
|
||||
echo -e "${YELLOW}Add the following TXT record to your DNS:${NC}"
|
||||
echo -e "${GREEN}=================================================${NC}"
|
||||
echo -e "Name: mail._domainkey.$domain"
|
||||
echo -e "Value:"
|
||||
cat /etc/opendkim/keys/$domain/mail.txt | grep -v "^;" | tr -d '\n'
|
||||
echo -e "\n${GREEN}=================================================${NC}"
|
||||
else
|
||||
echo -e "${RED}DKIM key file not found at /etc/opendkim/keys/$domain/mail.txt${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to create DMARC record recommendation
|
||||
recommend_dmarc() {
|
||||
domain=$1
|
||||
|
||||
echo -e "\n${BLUE}DMARC Record Recommendation for $domain${NC}"
|
||||
echo -e "${YELLOW}Add the following TXT record to your DNS:${NC}"
|
||||
echo -e "${GREEN}=================================================${NC}"
|
||||
echo -e "Name: _dmarc.$domain"
|
||||
echo -e "Value: v=DMARC1; p=reject; rua=mailto:admin@$domain; ruf=mailto:admin@$domain; pct=100"
|
||||
echo -e "${GREEN}=================================================${NC}"
|
||||
}
|
||||
|
||||
# Function to test SSH connection to redirector
|
||||
test_redirector_ssh() {
|
||||
redirector_ip=$1
|
||||
ssh_key=$2
|
||||
ssh_user=${3:-"root"}
|
||||
|
||||
echo -e "\n${BLUE}Testing SSH connection to redirector at $redirector_ip${NC}"
|
||||
|
||||
if [ -f "$ssh_key" ]; then
|
||||
# Try SSH with 5-second timeout
|
||||
ssh -i "$ssh_key" -o StrictHostKeyChecking=no -o ConnectTimeout=5 "$ssh_user@$redirector_ip" "echo 'SSH connection successful'" >/dev/null 2>&1
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}SSH connection to redirector successful${NC}"
|
||||
return 0
|
||||
else
|
||||
echo -e "${RED}SSH connection to redirector failed${NC}"
|
||||
echo -e "${YELLOW}Please check the redirector IP and SSH key${NC}"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo -e "${RED}SSH key file not found at $ssh_key${NC}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to execute post-install on redirector
|
||||
setup_redirector() {
|
||||
redirector_ip=$1
|
||||
ssh_key=$2
|
||||
ssh_user=${3:-"root"}
|
||||
|
||||
echo -e "\n${BLUE}Preparing to set up redirector at $redirector_ip${NC}"
|
||||
|
||||
# Check if redirector post-install script exists, copy if not
|
||||
ssh -i "$ssh_key" -o StrictHostKeyChecking=no "$ssh_user@$redirector_ip" "test -f /root/Tools/post_install_redirector.sh" >/dev/null 2>&1
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${YELLOW}Copying post-install script to redirector...${NC}"
|
||||
|
||||
# Create the script first
|
||||
cat > /tmp/post_install_redirector.sh << 'EOF'
|
||||
#!/bin/bash
|
||||
# post_install_redirector.sh - Post-installation setup for redirector
|
||||
|
||||
# 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 Post-Installation Setup - Redirector ${NC}"
|
||||
echo -e "${BLUE}==================================================${NC}"
|
||||
|
||||
# Function to check if domain resolves to current IP
|
||||
check_dns() {
|
||||
domain=$1
|
||||
current_ip=$(curl -s ifconfig.me)
|
||||
resolved_ip=$(dig +short $domain)
|
||||
|
||||
if [ "$resolved_ip" = "$current_ip" ]; then
|
||||
echo -e "${GREEN}DNS check passed for $domain!${NC}"
|
||||
return 0
|
||||
else
|
||||
echo -e "${YELLOW}DNS check failed for $domain${NC}"
|
||||
echo -e "Current IP: $current_ip"
|
||||
echo -e "Resolved IP: $resolved_ip"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to set up Let's Encrypt
|
||||
setup_letsencrypt() {
|
||||
domain=$1
|
||||
email=$2
|
||||
|
||||
echo -e "\n${BLUE}Setting up Let's Encrypt for $domain${NC}"
|
||||
|
||||
# Check if certificate already exists
|
||||
if [ -d "/etc/letsencrypt/live/$domain" ]; then
|
||||
echo -e "${YELLOW}Certificate already exists for $domain${NC}"
|
||||
read -p "Do you want to renew it? (y/n): " renew
|
||||
if [ "$renew" != "y" ]; then
|
||||
echo -e "${YELLOW}Skipping certificate renewal${NC}"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Stop nginx if running to free up port 80
|
||||
systemctl stop nginx 2>/dev/null
|
||||
|
||||
# Get certificate
|
||||
certbot certonly --standalone -d $domain -m $email --agree-tos --non-interactive
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Successfully obtained certificate for $domain${NC}"
|
||||
return 0
|
||||
else
|
||||
echo -e "${RED}Failed to obtain certificate for $domain${NC}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to start services
|
||||
start_services() {
|
||||
echo -e "\n${BLUE}Starting required services${NC}"
|
||||
|
||||
# Start nginx
|
||||
systemctl start nginx
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}NGINX started successfully${NC}"
|
||||
else
|
||||
echo -e "${RED}Failed to start NGINX${NC}"
|
||||
fi
|
||||
|
||||
# Start shell handler
|
||||
systemctl start shell-handler
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Shell handler started successfully${NC}"
|
||||
else
|
||||
echo -e "${RED}Failed to start shell handler${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Main execution
|
||||
echo -e "\n${BLUE}Beginning redirector setup process...${NC}"
|
||||
|
||||
# Get domain information
|
||||
read -p "Enter redirector domain (e.g., cdn.example.com): " redirector_domain
|
||||
read -p "Enter email for Let's Encrypt: " email
|
||||
|
||||
# Check if DNS is properly configured
|
||||
echo -e "\n${BLUE}Checking DNS configuration...${NC}"
|
||||
check_dns $redirector_domain
|
||||
|
||||
# Set up Let's Encrypt
|
||||
setup_letsencrypt $redirector_domain $email
|
||||
|
||||
# Start services
|
||||
start_services
|
||||
|
||||
echo -e "\n${GREEN}Redirector setup complete!${NC}"
|
||||
echo -e "${YELLOW}Make sure to check the logs if you encounter any issues.${NC}"
|
||||
EOF
|
||||
|
||||
# Make the script executable
|
||||
chmod +x /tmp/post_install_redirector.sh
|
||||
|
||||
# Copy to redirector
|
||||
scp -i "$ssh_key" -o StrictHostKeyChecking=no /tmp/post_install_redirector.sh "$ssh_user@$redirector_ip:/root/Tools/"
|
||||
|
||||
# Make executable on redirector
|
||||
ssh -i "$ssh_key" -o StrictHostKeyChecking=no "$ssh_user@$redirector_ip" "chmod +x /root/Tools/post_install_redirector.sh"
|
||||
|
||||
echo -e "${GREEN}Post-install script copied to redirector${NC}"
|
||||
else
|
||||
echo -e "${GREEN}Post-install script already exists on redirector${NC}"
|
||||
fi
|
||||
|
||||
# Ask to run the script
|
||||
read -p "Run redirector setup now? (y/n): " run_setup
|
||||
|
||||
if [ "$run_setup" = "y" ]; then
|
||||
echo -e "${BLUE}Connecting to redirector and running setup script...${NC}"
|
||||
ssh -i "$ssh_key" -o StrictHostKeyChecking=no -t "$ssh_user@$redirector_ip" "cd /root/Tools && ./post_install_redirector.sh"
|
||||
else
|
||||
echo -e "${YELLOW}Skipping redirector setup${NC}"
|
||||
echo -e "You can run it later by SSHing to the redirector and executing /root/Tools/post_install_redirector.sh"
|
||||
fi
|
||||
}
|
||||
|
||||
# Main execution
|
||||
echo -e "\n${BLUE}Beginning C2 server setup process...${NC}"
|
||||
|
||||
# Get domain information
|
||||
read -p "Enter primary domain: " domain
|
||||
read -p "Enter email for Let's Encrypt: " email
|
||||
|
||||
# Check if DNS is properly configured
|
||||
echo -e "\n${BLUE}Checking DNS configuration...${NC}"
|
||||
check_dns $domain
|
||||
check_dns "mail.$domain"
|
||||
|
||||
# Set up Let's Encrypt
|
||||
setup_letsencrypt $domain $email
|
||||
setup_mail_subdomain $domain $email
|
||||
|
||||
# Configure applications to use the certificates
|
||||
if [ -f "/etc/postfix/main.cf" ]; then
|
||||
echo -e "\n${BLUE}Configuring Postfix to use the certificates...${NC}"
|
||||
sed -i "s|^smtpd_tls_cert_file =.*|smtpd_tls_cert_file = /etc/letsencrypt/live/$domain/fullchain.pem|" /etc/postfix/main.cf
|
||||
sed -i "s|^smtpd_tls_key_file =.*|smtpd_tls_key_file = /etc/letsencrypt/live/$domain/privkey.pem|" /etc/postfix/main.cf
|
||||
fi
|
||||
|
||||
if [ -f "/root/Tools/gophish/config.json" ]; then
|
||||
echo -e "\n${BLUE}Configuring GoPhish to use the certificates...${NC}"
|
||||
sed -i "s|\"cert_path\":.*|\"cert_path\": \"/etc/letsencrypt/live/$domain/fullchain.pem\",|" /root/Tools/gophish/config.json
|
||||
sed -i "s|\"key_path\":.*|\"key_path\": \"/etc/letsencrypt/live/$domain/privkey.pem\",|" /root/Tools/gophish/config.json
|
||||
fi
|
||||
|
||||
# Start services
|
||||
start_services
|
||||
|
||||
# Generate DKIM and DMARC recommendations
|
||||
generate_dkim_records $domain
|
||||
recommend_dmarc $domain
|
||||
|
||||
# Ask for redirector information
|
||||
echo -e "\n${BLUE}Do you want to set up the redirector now?${NC}"
|
||||
read -p "Enter redirector IP (leave empty to skip): " redirector_ip
|
||||
|
||||
if [ -n "$redirector_ip" ]; then
|
||||
read -p "Enter SSH key path: " ssh_key
|
||||
read -p "Enter SSH user (default: root): " ssh_user
|
||||
|
||||
if [ -z "$ssh_user" ]; then
|
||||
ssh_user="root"
|
||||
fi
|
||||
|
||||
if test_redirector_ssh "$redirector_ip" "$ssh_key" "$ssh_user"; then
|
||||
setup_redirector "$redirector_ip" "$ssh_key" "$ssh_user"
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}Skipping redirector setup${NC}"
|
||||
fi
|
||||
|
||||
echo -e "\n${GREEN}C2 server setup complete!${NC}"
|
||||
echo -e "${YELLOW}Make sure to set up DNS records as described above if you haven't already.${NC}"
|
||||
@@ -0,0 +1,156 @@
|
||||
#!/bin/bash
|
||||
# post_install_redirector.sh - Post-installation setup for redirector
|
||||
|
||||
# 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 Post-Installation Setup - Redirector ${NC}"
|
||||
echo -e "${BLUE}==================================================${NC}"
|
||||
|
||||
# Function to check if domain resolves to current IP
|
||||
check_dns() {
|
||||
domain=$1
|
||||
current_ip=$(curl -s ifconfig.me)
|
||||
resolved_ip=$(dig +short $domain)
|
||||
|
||||
if [ "$resolved_ip" = "$current_ip" ]; then
|
||||
echo -e "${GREEN}DNS check passed for $domain!${NC}"
|
||||
return 0
|
||||
else
|
||||
echo -e "${YELLOW}DNS check failed for $domain${NC}"
|
||||
echo -e "Current IP: $current_ip"
|
||||
echo -e "Resolved IP: $resolved_ip or not set"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to set up Let's Encrypt
|
||||
setup_letsencrypt() {
|
||||
domain=$1
|
||||
email=$2
|
||||
|
||||
echo -e "\n${BLUE}Setting up Let's Encrypt for $domain${NC}"
|
||||
|
||||
# Check if certificate already exists
|
||||
if [ -d "/etc/letsencrypt/live/$domain" ]; then
|
||||
echo -e "${YELLOW}Certificate already exists for $domain${NC}"
|
||||
read -p "Do you want to renew it? (y/n): " renew
|
||||
if [ "$renew" != "y" ]; then
|
||||
echo -e "${YELLOW}Skipping certificate renewal${NC}"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Stop nginx if running to free up port 80
|
||||
systemctl stop nginx 2>/dev/null
|
||||
|
||||
# Get certificate
|
||||
certbot certonly --standalone -d $domain -m $email --agree-tos --non-interactive
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Successfully obtained certificate for $domain${NC}"
|
||||
return 0
|
||||
else
|
||||
echo -e "${RED}Failed to obtain certificate for $domain${NC}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to update NGINX configuration
|
||||
update_nginx_config() {
|
||||
domain=$1
|
||||
|
||||
# Check if NGINX config exists and contains the domain
|
||||
if [ -f "/etc/nginx/sites-available/default" ]; then
|
||||
if grep -q "$domain" "/etc/nginx/sites-available/default"; then
|
||||
echo -e "\n${BLUE}Updating NGINX configuration to use SSL certificate${NC}"
|
||||
|
||||
# Update SSL certificate paths
|
||||
sed -i "s|ssl_certificate .*|ssl_certificate /etc/letsencrypt/live/$domain/fullchain.pem;|" /etc/nginx/sites-available/default
|
||||
sed -i "s|ssl_certificate_key .*|ssl_certificate_key /etc/letsencrypt/live/$domain/privkey.pem;|" /etc/nginx/sites-available/default
|
||||
|
||||
echo -e "${GREEN}NGINX configuration updated${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}Domain $domain not found in NGINX configuration${NC}"
|
||||
fi
|
||||
else
|
||||
echo -e "${RED}NGINX configuration file not found${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to start services
|
||||
start_services() {
|
||||
echo -e "\n${BLUE}Starting required services${NC}"
|
||||
|
||||
# Start nginx
|
||||
systemctl start nginx
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}NGINX started successfully${NC}"
|
||||
else
|
||||
echo -e "${RED}Failed to start NGINX${NC}"
|
||||
fi
|
||||
|
||||
# Start shell handler
|
||||
systemctl start shell-handler
|
||||
if [ $? -eq 0 ]; then
|
||||
echo -e "${GREEN}Shell handler started successfully${NC}"
|
||||
else
|
||||
echo -e "${RED}Failed to start shell handler${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to display port information
|
||||
show_port_info() {
|
||||
# Display shell handler port
|
||||
if [ -f "/etc/systemd/system/shell-handler.service" ]; then
|
||||
SHELL_PORT=$(grep "LISTEN_PORT=" /root/Tools/shell-handler/persistent-listener.sh | cut -d'=' -f2)
|
||||
echo -e "\n${BLUE}Shell Handler Port Information:${NC}"
|
||||
echo -e "Shell Handler is using port: ${GREEN}$SHELL_PORT${NC}"
|
||||
fi
|
||||
|
||||
# Display nginx listening ports
|
||||
echo -e "\n${BLUE}NGINX Listening Ports:${NC}"
|
||||
netstat -tlpn | grep nginx
|
||||
}
|
||||
|
||||
# Main execution
|
||||
echo -e "\n${BLUE}Beginning redirector setup process...${NC}"
|
||||
|
||||
# Get domain information
|
||||
read -p "Enter redirector domain (e.g., cdn.example.com): " redirector_domain
|
||||
read -p "Enter email for Let's Encrypt: " email
|
||||
|
||||
# Check if DNS is properly configured
|
||||
echo -e "\n${BLUE}Checking DNS configuration...${NC}"
|
||||
check_dns $redirector_domain
|
||||
|
||||
# Confirm proceeding even if DNS check fails
|
||||
if [ $? -ne 0 ]; then
|
||||
echo -e "${YELLOW}DNS check failed but we can proceed anyway.${NC}"
|
||||
echo -e "${YELLOW}Make sure to set up DNS records before trying to obtain certificates.${NC}"
|
||||
read -p "Do you want to proceed anyway? (y/n): " proceed
|
||||
if [ "$proceed" != "y" ]; then
|
||||
echo -e "${RED}Setup aborted.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Set up Let's Encrypt
|
||||
setup_letsencrypt $redirector_domain $email
|
||||
|
||||
# Update NGINX configuration
|
||||
update_nginx_config $redirector_domain
|
||||
|
||||
# Start services
|
||||
start_services
|
||||
|
||||
# Show port information
|
||||
show_port_info
|
||||
|
||||
echo -e "\n${GREEN}Redirector setup complete!${NC}"
|
||||
echo -e "${YELLOW}Make sure DNS records are properly configured for continued operation.${NC}"
|
||||
@@ -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
|
||||
@@ -45,14 +45,14 @@ done
|
||||
|
||||
# Clear all logs
|
||||
echo "[+] Clearing logs..."
|
||||
bash /opt/c2/clean-logs.sh
|
||||
bash /root/Tools/clean-logs.sh
|
||||
|
||||
# Securely delete operational files
|
||||
echo "[+] Removing operational files..."
|
||||
operational_dirs=(
|
||||
"/opt/c2"
|
||||
"/opt/beacons"
|
||||
"/opt/payloads"
|
||||
"/root/Tools"
|
||||
"/root/Tools/beacons"
|
||||
"/root/Tools/payloads"
|
||||
"/root/.sliver"
|
||||
"/root/.msf4"
|
||||
"/root/.gophish"
|
||||
|
||||
@@ -18,7 +18,7 @@ logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(levelname)s - %(message)s',
|
||||
handlers=[
|
||||
logging.FileHandler('/opt/tracker/data/tracker.log'),
|
||||
logging.FileHandler('/root/Tools/tracker/data/tracker.log'),
|
||||
logging.StreamHandler()
|
||||
]
|
||||
)
|
||||
@@ -27,7 +27,7 @@ logging.basicConfig(
|
||||
app = Flask(__name__)
|
||||
|
||||
# Directory to store tracking data
|
||||
DATA_DIR = '/opt/tracker/data'
|
||||
DATA_DIR = '/root/Tools/tracker/data'
|
||||
os.makedirs(DATA_DIR, exist_ok=True)
|
||||
|
||||
# Path to 1x1 transparent pixel
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
set -e
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
SLIVER_DIR="${TEMP_DIR}/sliver"
|
||||
LOG_FILE="/opt/c2/sliver_randomizer.log"
|
||||
LOG_FILE="/root/Tools/sliver_randomizer.log"
|
||||
|
||||
# Function to log messages
|
||||
log() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
# CLI tool to view email tracking stats
|
||||
|
||||
DATA_FILE="/opt/tracker/data/tracking_data.json"
|
||||
DATA_FILE="/root/Tools/tracker/data/tracking_data.json"
|
||||
|
||||
function show_summary() {
|
||||
if [ ! -f "$DATA_FILE" ]; then
|
||||
|
||||
@@ -5,8 +5,8 @@ After=network.target
|
||||
[Service]
|
||||
User=tracker
|
||||
Group=tracker
|
||||
WorkingDirectory=/opt/tracker
|
||||
ExecStart=/opt/tracker/venv/bin/python /opt/tracker/simple_email_tracker.py
|
||||
WorkingDirectory=/root/Tools/tracker
|
||||
ExecStart=/root/Tools/tracker/venv/bin/python /root/Tools/tracker/simple_email_tracker.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
|
||||
Reference in New Issue
Block a user