-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAES_encryption.py
More file actions
36 lines (29 loc) · 1.07 KB
/
Copy pathAES_encryption.py
File metadata and controls
36 lines (29 loc) · 1.07 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
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
import pyperclip
# Load binary shellcode from file
with open("shellcode.bin", "rb") as f:
raw_shellcode = f.read()
# Generate AES-256 key and IV
key = get_random_bytes(32)
iv = get_random_bytes(16)
# Apply PKCS7 padding to the shellcode
pad_len = 16 - (len(raw_shellcode) % 16)
padded_shellcode = raw_shellcode + bytes([pad_len] * pad_len)
# Encrypt the shellcode using AES CBC mode
cipher = AES.new(key, AES.MODE_CBC, iv)
encrypted_shellcode = cipher.encrypt(padded_shellcode)
# Format byte arrays for C# output
def format_csharp_array(name, byte_data):
return f"byte[] {name} = new byte[] {{ {', '.join(f'0x{b:02x}' for b in byte_data)} }};"
# Generate the final C#-formatted output
output = (
format_csharp_array("encryptedShellcode", encrypted_shellcode)
+ "\n\n"
+ format_csharp_array("aesKey", key)
+ "\n\n"
+ format_csharp_array("aesIV", iv)
)
# Copy the output to the clipboard for easy pasting into C#
pyperclip.copy(output)
print("[+] C# arrays generated and copied to clipboard.")