-
Notifications
You must be signed in to change notification settings - Fork 4
/
aes.py
31 lines (25 loc) · 901 Bytes
/
aes.py
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
# Red Team Operator course code template
# payload encryption with AES
#
# author: reenz0h (twitter: @SEKTOR7net)
import sys
from base64 import b64encode
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
from Crypto.Random import get_random_bytes
import hashlib
KEY = get_random_bytes(16)
iv = 16 * b'\x00'
cipher = AES.new(hashlib.sha256(KEY).digest(), AES.MODE_CBC, iv)
try:
plaintext = open(sys.argv[1], "rb").read()
except:
print("File argument needed! %s <raw payload file>" % sys.argv[0])
sys.exit()
ciphertext = cipher.encrypt(pad(plaintext, AES.block_size))
# Encode the key and ciphertext with base64 for easy handling in C#
encoded_key = b64encode(KEY).decode('utf-8')
encoded_cipher = b64encode(ciphertext).decode('utf-8')
# Print the encoded key and ciphertext
print("Base64 Encoded Key:", encoded_key)
print("Base64 Encoded Ciphertext:", encoded_cipher)