getting better
This commit is contained in:
@@ -329,7 +329,7 @@ def interactive_setup():
|
||||
# Generate random tracker name
|
||||
rand_suffix = generate_random_string()
|
||||
timestamp = int(time.time()) % 10000
|
||||
config['tracker_name'] = f"track-{rand_suffix}-{timestamp}"
|
||||
config['tracker_name'] = f"t-{rand_suffix}-{timestamp}" # Changed from track- to t-
|
||||
|
||||
# SSH key if not already set
|
||||
if 'ssh_key' not in config or not config['ssh_key']:
|
||||
@@ -340,11 +340,11 @@ def interactive_setup():
|
||||
# Generate SSH key
|
||||
config['ssh_key'] = generate_ssh_key()
|
||||
|
||||
# Generate random instance names if not set
|
||||
# Generate random instance names with new format
|
||||
rand_suffix = generate_random_string()
|
||||
timestamp = int(time.time()) % 10000
|
||||
config['redirector_name'] = f"srv-{rand_suffix}-{timestamp}"
|
||||
config['c2_name'] = f"node-{rand_suffix}-{timestamp}"
|
||||
config['redirector_name'] = f"r-{rand_suffix}-{timestamp}" # Changed from srv- to r-
|
||||
config['c2_name'] = f"s-{rand_suffix}-{timestamp}" # Changed from node- to s-
|
||||
|
||||
# Additional settings from vars_data
|
||||
config['gophish_admin_port'] = vars_data.get('gophish_admin_port', str(random.randint(2000, 9000)))
|
||||
@@ -485,9 +485,13 @@ def create_inventory_file(config, deployment_type):
|
||||
if config.get('ssh_port'):
|
||||
inventory_content.append(f"ansible_port={config['ssh_port']}")
|
||||
|
||||
# Always use the current Python interpreter
|
||||
# This ensures any modules needed are available
|
||||
# Set Python interpreter appropriately based on deployment type
|
||||
if deployment_type == "local":
|
||||
# For local execution, use the current Python interpreter
|
||||
inventory_content.append(f"ansible_python_interpreter={sys.executable}")
|
||||
else:
|
||||
# For remote hosts, let Ansible auto-detect the Python interpreter
|
||||
inventory_content.append("ansible_python_interpreter=auto")
|
||||
|
||||
# Add specific host sections based on deployment type
|
||||
if deployment_type == "local":
|
||||
@@ -513,6 +517,84 @@ def create_inventory_file(config, deployment_type):
|
||||
|
||||
return inventory_path
|
||||
|
||||
def run_ansible_playbook(playbook, inventory, config, debug=False):
|
||||
"""Run an Ansible playbook with the given inventory and config"""
|
||||
# Convert config dict to JSON for extra-vars
|
||||
# Filter out None values and complex objects
|
||||
extra_vars = {k: v for k, v in config.items() if v is not None and not isinstance(v, (dict, list, tuple))}
|
||||
|
||||
# Handle the region parameter correctly
|
||||
if 'region' in extra_vars:
|
||||
# Set selected_region to match what the playbook expects
|
||||
extra_vars['selected_region'] = extra_vars['region']
|
||||
elif 'linode_region' in extra_vars:
|
||||
# Map linode_region to selected_region for compatibility
|
||||
extra_vars['selected_region'] = extra_vars['linode_region']
|
||||
|
||||
# Explicitly set hard-coded user values rather than using templated defaults
|
||||
if 'ssh_user' in extra_vars:
|
||||
extra_vars.pop('ssh_user')
|
||||
if config['provider'] == 'linode':
|
||||
extra_vars['ssh_user'] = 'root'
|
||||
else:
|
||||
extra_vars['ssh_user'] = 'kali'
|
||||
|
||||
# Remove the Python interpreter setting from extra_vars
|
||||
# It should be set properly in the inventory file instead
|
||||
if 'ansible_python_interpreter' in extra_vars:
|
||||
extra_vars.pop('ansible_python_interpreter')
|
||||
|
||||
extra_vars_json = json.dumps(extra_vars)
|
||||
|
||||
# Set PYTHONPATH to include site-packages
|
||||
env = os.environ.copy()
|
||||
current_python = sys.executable
|
||||
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
|
||||
cmd = [
|
||||
"ansible-playbook",
|
||||
"-i", inventory,
|
||||
playbook,
|
||||
"-e", extra_vars_json
|
||||
]
|
||||
|
||||
# Add verbosity if debug mode is enabled
|
||||
if debug:
|
||||
cmd.append("-vvv")
|
||||
else:
|
||||
# Always add some verbosity for basic output
|
||||
cmd.append("-v")
|
||||
|
||||
# Log the command
|
||||
if debug:
|
||||
logging.debug(f"Running Ansible command: {' '.join(cmd)}")
|
||||
else:
|
||||
logging.info(f"Running Ansible playbook: {playbook}")
|
||||
|
||||
# Run the command
|
||||
try:
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
check=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
env=env # Use the modified environment
|
||||
)
|
||||
logging.info(f"Playbook {playbook} executed successfully")
|
||||
return True, result.stdout, result.stderr
|
||||
except subprocess.CalledProcessError as e:
|
||||
logging.error(f"Playbook {playbook} failed with exit code {e.returncode}")
|
||||
if debug:
|
||||
logging.error(f"Command stdout: {e.stdout}")
|
||||
logging.error(f"Command stderr: {e.stderr}")
|
||||
return False, e.stdout, e.stderr
|
||||
|
||||
def run_ansible_playbook(playbook, inventory, config, debug=False):
|
||||
"""Run an Ansible playbook with the given inventory and config"""
|
||||
# Convert config dict to JSON for extra-vars
|
||||
@@ -613,6 +695,14 @@ def deploy_infrastructure(config):
|
||||
|
||||
# Select random region if not specified
|
||||
if not config.get('region'):
|
||||
if provider == "linode" and config.get('linode_region'):
|
||||
# Use the specified linode_region
|
||||
config['region'] = config['linode_region']
|
||||
elif provider == "aws" and config.get('aws_region'):
|
||||
# Use the specified aws_region
|
||||
config['region'] = config['aws_region']
|
||||
else:
|
||||
# If no specific region provided, select random
|
||||
config['region'] = select_random_region(config)
|
||||
|
||||
# Set different instance sizes for redirector vs. C2
|
||||
@@ -1217,12 +1307,12 @@ C2itAll - Red Team Infrastructure Setup
|
||||
if not args.teardown:
|
||||
config['ssh_key'] = generate_ssh_key()
|
||||
|
||||
# Generate random instance names
|
||||
# Generate random instance names with new format
|
||||
rand_suffix = generate_random_string()
|
||||
timestamp = int(time.time()) % 10000
|
||||
config['redirector_name'] = args.redirector_name or f"srv-{rand_suffix}-{timestamp}"
|
||||
config['c2_name'] = args.c2_name or f"node-{rand_suffix}-{timestamp}"
|
||||
config['tracker_name'] = args.tracker_name or f"track-{rand_suffix}-{timestamp}"
|
||||
config['redirector_name'] = args.redirector_name or f"r-{rand_suffix}-{timestamp}" # Changed from srv- to r-
|
||||
config['c2_name'] = args.c2_name or f"s-{rand_suffix}-{timestamp}" # Changed from node- to s-
|
||||
config['tracker_name'] = args.tracker_name or f"t-{rand_suffix}-{timestamp}" # Changed from track- to t-
|
||||
|
||||
# Deployment options
|
||||
config['redirector_only'] = args.redirector_only
|
||||
|
||||
Reference in New Issue
Block a user