Files
CoM-c2itall/tasks/configure_redirector.yml
T
2025-04-22 22:17:45 -04:00

209 lines
5.8 KiB
YAML

---
# Common task for configuring redirector with full encryption
# Shared across all providers
- name: Install required packages for redirector
apt:
name:
- nginx
- certbot
- python3-certbot-nginx
- socat
- netcat-openbsd
- secure-delete
- jq
state: present
update_cache: yes
- name: Create directories for operational scripts
file:
path: "{{ item }}"
state: directory
mode: '0700'
owner: root
group: root
with_items:
- /root/Tools
- /root/Tools/shell-handler
- name: Copy clean-logs.sh script
copy:
src: "../files/clean-logs.sh"
dest: /root/Tools/clean-logs.sh
mode: '0700'
owner: root
group: root
- name: Copy redirector post-install script
copy:
src: "../files/post_install_redirector.sh"
dest: "/root/Tools/post_install_redirector.sh"
mode: '0700'
owner: root
group: root
- name: Copy port randomization script
copy:
src: "../files/randomize_ports.sh"
dest: "/root/Tools/randomize_ports.sh"
mode: '0700'
owner: root
group: root
- name: Create redirector post-install instructions
copy:
content: |
================================================================
C2ingRed 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.
dest: "/root/POST_INSTALL_INSTRUCTIONS.txt"
mode: '0644'
owner: root
group: root
- name: Copy shell handler script
copy:
src: "../files/persistent-listener.sh"
dest: /root/Tools/shell-handler/persistent-listener.sh
mode: '0700'
owner: root
group: root
- name: Configure shell handler script with C2 IP
replace:
path: /root/Tools/shell-handler/persistent-listener.sh
regexp: 'C2_HOST="127.0.0.1"'
replace: 'C2_HOST="{{ c2_ip }}"'
- name: Configure shell handler script with listening port
replace:
path: /root/Tools/shell-handler/persistent-listener.sh
regexp: 'LISTEN_PORT=4444'
replace: 'LISTEN_PORT={{ shell_handler_port }}'
- name: Create shell handler service
template:
src: "../templates/shell-handler.service.j2"
dest: /etc/systemd/system/shell-handler.service
mode: '0644'
owner: root
group: root
- name: Configure NGINX for zero-logging if enabled
template:
src: "../templates/nginx.conf.j2"
dest: /etc/nginx/nginx.conf
mode: '0644'
owner: root
group: root
when: zero_logs | bool
# Run port randomization if enabled
- name: Run port randomization if enabled
include_tasks: port_randomization.yml
when: randomize_ports | default(true) | bool
# Configure nginx for dual HTTP/HTTPS with complete encryption
- name: Configure NGINX for secure C2 redirection
template:
src: "../templates/redirector-site-config.j2"
dest: /etc/nginx/sites-available/default
mode: '0644'
owner: root
group: root
- name: Create legitimate-looking index.html
template:
src: "../templates/redirector-index.html.j2"
dest: /var/www/html/index.html
mode: '0644'
owner: www-data
group: www-data
- name: Create SSL certificate setup instructions
template:
content: |
#!/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 }}"
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 "================================================"
dest: /root/Tools/setup-cert.sh
mode: '0700'
owner: root
group: root
- name: Configure NGINX stream module for TCP traffic
template:
content: |
# TCP stream configuration for Havoc C2
stream {
# TCP forwarding for Havoc Teamserver
server {
listen {{ havoc_teamserver_port | default(40056) }};
proxy_pass {{ c2_ip }}:{{ havoc_teamserver_port | default(40056) }};
}
# Additional Havoc ports
server {
listen {{ havoc_http_port | default(8080) }};
proxy_pass {{ c2_ip }}:{{ havoc_http_port | default(8080) }};
}
# HTTPS for Havoc
server {
listen {{ havoc_https_port | default(443) }};
proxy_pass {{ c2_ip }}:{{ havoc_https_port | default(443) }};
}
}
dest: /etc/nginx/modules-enabled/stream.conf
mode: '0644'
owner: root
group: root
notify:
- restart nginx
- name: Start and enable shell handler service
systemd:
name: shell-handler
state: started
enabled: yes
daemon_reload: yes
- name: Set up cron job for log cleaning if zero-logs enabled
cron:
name: "Clean logs"
minute: "0"
hour: "*/6"
job: "/root/Tools/clean-logs.sh > /dev/null 2>&1"
when: zero_logs | bool