xor.py 657 B

1234567891011121314151617181920212223242526272829303132
  1. # Red Team Operator course code template
  2. # payload encryption with XOR
  3. #
  4. # author: reenz0h (twitter: @sektor7net)
  5. import sys
  6. KEY = "VqeaEoOtEhVmRBg"
  7. def xor(data, key):
  8. l = len(key)
  9. output_str = ""
  10. for i in range(len(data)):
  11. current = data[i]
  12. current_key = key[i%len(key)]
  13. output_str += chr(ord(current) ^ ord(current_key))
  14. return output_str
  15. def printC(ciphertext):
  16. print('{ 0x' + ', 0x'.join(hex(ord(x))[2:] for x in ciphertext) + ' };')
  17. try:
  18. plaintext = open(sys.argv[1], "r").read()
  19. except:
  20. print("File argument needed! %s <raw payload file>" % sys.argv[0])
  21. sys.exit()
  22. ciphertext = xor(plaintext, KEY)
  23. printC(ciphertext)