aesencrypt.py 752 B

1234567891011121314151617181920212223242526
  1. # Red Team Operator course code template
  2. # payload encryption with AES
  3. #
  4. # author: reenz0h (twitter: @SEKTOR7net)
  5. import sys
  6. from base64 import b64encode
  7. from Crypto.Cipher import AES
  8. from Crypto.Util.Padding import pad
  9. from Crypto.Random import get_random_bytes
  10. import hashlib
  11. KEY = get_random_bytes(16)
  12. iv = 16 * b'\x00'
  13. cipher = AES.new(hashlib.sha256(KEY).digest(), AES.MODE_CBC, iv)
  14. try:
  15. plaintext = open(sys.argv[1], "rb").read()
  16. except:
  17. print("File argument needed! %s <raw payload file>" % sys.argv[0])
  18. sys.exit()
  19. ciphertext = cipher.encrypt(pad(plaintext, AES.block_size))
  20. print('AESkey[] = { 0x' + ', 0x'.join(hex(x)[2:] for x in KEY) + ' };')
  21. print('payload[] = { 0x' + ', 0x'.join(hex(x)[2:] for x in ciphertext) + ' };')