redirector working
This commit is contained in:
@@ -70,6 +70,10 @@
|
||||
group: root
|
||||
when: zero_logs | bool
|
||||
|
||||
- name: Set subdomain value explicitly
|
||||
set_fact:
|
||||
redirector_subdomain: "cdn"
|
||||
|
||||
- name: Configure NGINX for C2 redirection
|
||||
template:
|
||||
src: "../templates/redirector-site.conf.j2"
|
||||
@@ -108,7 +112,76 @@
|
||||
creates: /etc/letsencrypt/live/{{ redirector_subdomain }}.{{ domain }}/fullchain.pem
|
||||
when: domain != "example.com"
|
||||
|
||||
- name: Test NGINX configuration
|
||||
command: nginx -t
|
||||
register: nginx_config_test
|
||||
ignore_errors: true
|
||||
|
||||
- name: Debug NGINX configuration test results if failed
|
||||
debug:
|
||||
var: nginx_config_test.stderr_lines
|
||||
when: nginx_config_test.rc != 0
|
||||
|
||||
- name: Ensure NGINX configurations are valid
|
||||
block:
|
||||
- name: Fix NGINX configuration if test failed
|
||||
copy:
|
||||
content: |
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name cdn.{{ domain }};
|
||||
|
||||
# Root directory
|
||||
root /var/www/html;
|
||||
index index.html;
|
||||
|
||||
# Primary location for legitimate traffic
|
||||
location / {
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
|
||||
# Special URI patterns for C2 traffic
|
||||
location /ajax/ {
|
||||
proxy_pass http://{{ c2_ip }}:8888;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
|
||||
# Static resources
|
||||
location ~ ^/static/(css|js|images)/.*\.(css|js|png|jpg|jpeg|gif|ico)$ {
|
||||
proxy_pass http://{{ c2_ip }}:8888;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
}
|
||||
|
||||
# Catch-all server block
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
|
||||
# Redirect unknown traffic
|
||||
return 301 https://www.google.com;
|
||||
}
|
||||
dest: /etc/nginx/sites-available/default
|
||||
mode: '0644'
|
||||
owner: root
|
||||
group: root
|
||||
when: nginx_config_test.rc != 0
|
||||
when: nginx_config_test.rc != 0
|
||||
|
||||
- name: Restart NGINX
|
||||
systemd:
|
||||
name: nginx
|
||||
state: restarted
|
||||
state: restarted
|
||||
register: nginx_restart
|
||||
ignore_errors: true
|
||||
|
||||
- name: Verify NGINX is running
|
||||
service:
|
||||
name: nginx
|
||||
state: started
|
||||
when: nginx_restart is failed
|
||||
Reference in New Issue
Block a user