This commit is contained in:
n0mad1k
2025-04-11 14:29:28 -04:00
parent d8b980da07
commit 15677f3f91
3 changed files with 26 additions and 17 deletions
+5 -5
View File
@@ -11,7 +11,8 @@
# Default values for required variables # Default values for required variables
linode_region: "{{ linode_region | default(region_choices | random) }}" linode_region: "{{ linode_region | default(region_choices | random) }}"
plan: "{{ plan | default('g6-standard-2') }}" plan: "{{ plan | default('g6-standard-2') }}"
image: "{{ image | default('linode/kali') }}" # Use static value to avoid recursive templating
c2_image_static: "linode/kali"
# Generate random instance name if not provided # Generate random instance name if not provided
c2_name: "{{ c2_name | default('node-' + 9999999999 | random | to_uuid | hash('md5') | truncate(8, True, '')) }}" c2_name: "{{ c2_name | default('node-' + 9999999999 | random | to_uuid | hash('md5') | truncate(8, True, '')) }}"
@@ -29,13 +30,13 @@
label: "{{ c2_name }}" label: "{{ c2_name }}"
type: "{{ plan }}" type: "{{ plan }}"
region: "{{ selected_region }}" region: "{{ selected_region }}"
# Use Kali for C2 by default # Use static value to avoid recursive templating
image: "{{ c2_image | default('linode/kali') }}" image: "{{ c2_image_static }}"
root_pass: "{{ lookup('password', '/dev/null length=16') }}" root_pass: "{{ lookup('password', '/dev/null length=16') }}"
authorized_keys: authorized_keys:
- "{{ lookup('file', ssh_key_path) }}" - "{{ lookup('file', ssh_key_path) }}"
state: present state: present
register: linode_instance register: c2_instance
- name: Set c2_ip for later use - name: Set c2_ip for later use
set_fact: set_fact:
@@ -72,7 +73,6 @@
msg: "Could not connect to C2 server via SSH after multiple attempts" msg: "Could not connect to C2 server via SSH after multiple attempts"
when: ssh_test.rc != 0 when: ssh_test.rc != 0
# Fix: use hardcoded "root" instead of a nested templating expression
- name: Add C2 to inventory - name: Add C2 to inventory
add_host: add_host:
name: "c2" name: "c2"
+4 -4
View File
@@ -10,7 +10,8 @@
vars: vars:
# Handle both region and selected_region for backward compatibility # Handle both region and selected_region for backward compatibility
selected_region: "{{ selected_region | default(region) | default(linode_region) | default(region_choices | random) }}" selected_region: "{{ selected_region | default(region) | default(linode_region) | default(region_choices | random) }}"
redirector_image: "{{ redirector_image | default('linode/debian12') }}" # Use constant values directly to avoid recursive template resolution
redirector_image_static: "linode/debian12"
tasks: tasks:
- name: Validate required Linode token - name: Validate required Linode token
@@ -25,12 +26,12 @@
label: "{{ redirector_name }}" label: "{{ redirector_name }}"
type: "{{ plan }}" type: "{{ plan }}"
region: "{{ selected_region }}" region: "{{ selected_region }}"
image: "{{ redirector_image }}" image: "{{ redirector_image_static }}"
root_pass: "{{ lookup('password', '/dev/null length=16') }}" root_pass: "{{ lookup('password', '/dev/null length=16') }}"
authorized_keys: authorized_keys:
- "{{ lookup('file', ssh_key_path) }}" - "{{ lookup('file', ssh_key_path) }}"
state: present state: present
register: linode_instance register: redirector_instance
- name: Set redirector_ip for later use - name: Set redirector_ip for later use
set_fact: set_fact:
@@ -67,7 +68,6 @@
msg: "Could not connect to redirector via SSH after multiple attempts" msg: "Could not connect to redirector via SSH after multiple attempts"
when: ssh_test.rc != 0 when: ssh_test.rc != 0
# Fix: Use hardcoded "redirector" for the name and "root" for the user
- name: Add redirector to inventory - name: Add redirector to inventory
add_host: add_host:
name: "redirector" name: "redirector"
+17 -8
View File
@@ -485,11 +485,9 @@ def create_inventory_file(config, deployment_type):
if config.get('ssh_port'): if config.get('ssh_port'):
inventory_content.append(f"ansible_port={config['ssh_port']}") inventory_content.append(f"ansible_port={config['ssh_port']}")
# Make sure we DON'T use the local Python interpreter path for remote hosts # Always use the current Python interpreter
if deployment_type == "local": # This ensures any modules needed are available
# Only set Python interpreter for localhost inventory_content.append(f"ansible_python_interpreter={sys.executable}")
venv_python = sys.executable
inventory_content.append(f"ansible_python_interpreter={venv_python}")
# Add specific host sections based on deployment type # Add specific host sections based on deployment type
if deployment_type == "local": if deployment_type == "local":
@@ -537,11 +535,21 @@ def run_ansible_playbook(playbook, inventory, config, debug=False):
else: else:
extra_vars['ssh_user'] = 'kali' extra_vars['ssh_user'] = 'kali'
# Add ansible_python_interpreter for remote hosts correctly # Use the current Python interpreter for all Ansible operations
extra_vars['ansible_python_interpreter'] = '/usr/bin/python3' # This ensures any modules needed are available
current_python = sys.executable
extra_vars['ansible_python_interpreter'] = current_python
extra_vars_json = json.dumps(extra_vars) extra_vars_json = json.dumps(extra_vars)
# Set PYTHONPATH to include site-packages
env = os.environ.copy()
python_path = subprocess.check_output(
[current_python, "-c", "import sys; import site; print(':'.join(sys.path + site.getsitepackages()))"],
text=True
).strip()
env["PYTHONPATH"] = python_path
# Build command # Build command
cmd = [ cmd = [
"ansible-playbook", "ansible-playbook",
@@ -570,7 +578,8 @@ def run_ansible_playbook(playbook, inventory, config, debug=False):
check=True, check=True,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
text=True text=True,
env=env # Use the modified environment
) )
logging.info(f"Playbook {playbook} executed successfully") logging.info(f"Playbook {playbook} executed successfully")
return True, result.stdout, result.stderr return True, result.stdout, result.stderr