File size: 3,696 Bytes
2f3c093 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | import sys
import json
import logging
import os
import subprocess
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
if __name__ == "__main__":
if len(sys.argv) != 4:
logger.error("Usage: deploy.py <payload_path> <spyware_config_json> <deployment_config_json>")
sys.exit(1)
payload_path = sys.argv[1]
spyware_config_json = sys.argv[2]
deployment_config_json = sys.argv[3]
try:
spyware_config = json.loads(spyware_config_json)
deployment_config = json.loads(deployment_config_json)
except json.JSONDecodeError as e:
logger.error(f"Error decoding JSON: {e}")
sys.exit(1)
logger.info(f"Payload Path: {payload_path}")
logger.info(f"Spyware Config: {spyware_config}")
logger.info(f"Deployment Config: {deployment_config}")
logger.info("Starting deployment process...")
try:
if deployment_config and 'command' in deployment_config:
command = deployment_config['command']
logger.info(f"Executing command: {command}")
result = subprocess.run(command, shell=True, capture_output=True, text=True)
if result.returncode == 0:
logger.info(f"Command executed successfully. Output:\n{result.stdout}")
else:
logger.error(f"Command failed with error:\n{result.stderr}")
elif deployment_config and 'remote_host' in deployment_config and 'remote_user' in deployment_config:
remote_host = deployment_config['remote_host']
remote_user = deployment_config['remote_user']
remote_path = deployment_config.get('remote_path', '/tmp')
if payload_path:
file_name = os.path.basename(payload_path)
remote_file_path = f"{remote_user}@{remote_host}:{remote_path}/{file_name}"
logger.info(f"Copying payload to remote host: {remote_file_path}")
scp_command = ['scp', payload_path, remote_file_path]
result = subprocess.run(scp_command, capture_output=True, text=True)
if result.returncode == 0:
logger.info(f"File copied successfully to {remote_file_path}")
ssh_command = ['ssh', f"{remote_user}@{remote_host}", f"echo 'File deployed to {remote_path}/{file_name}'"]
ssh_result = subprocess.run(ssh_command, capture_output=True, text=True)
if ssh_result.returncode == 0:
logger.info(f"Remote command executed successfully: {ssh_result.stdout}")
else:
logger.error(f"Remote command failed: {ssh_result.stderr}")
else:
logger.error(f"Error copying file with scp: {result.stderr}")
else:
logger.warning("No payload path provided, skipping file transfer.")
elif payload_path:
file_name = os.path.basename(payload_path)
output_file_path = os.path.join(os.getcwd(), file_name)
with open(output_file_path, 'w') as f:
f.write(f"This is a dummy payload file created by deploy.py.\nSpyware Config: {spyware_config}\nDeployment Config: {deployment_config}")
logger.info(f"Created dummy payload file at: {output_file_path}")
else:
logger.warning("No payload path or command provided, skipping deployment.")
except Exception as e:
logger.error(f"Error during deployment: {e}")
logger.info("Deployment process completed.")
|