Advertisement
MalwareQuinn

XorBruteforce.py

Jun 9th, 2020
11,247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. import sys
  2. from loguru import logger
  3.  
  4.  
  5. def Decrypt(key,data):
  6.     dataList = []
  7.     for x in data:
  8.         #
  9.         dataList.append((x) ^ int(key,0))
  10.     dataL = (''.join('{:02x}'.format(x) for x in dataList))
  11.     #print(dataL[521849])
  12.     return bytearray.fromhex(dataL)
  13.  
  14.  
  15. listOfVals = {}
  16.  
  17.  
  18. with open(sys.argv[1],"rb") as f:
  19.     counter = 0
  20.     file1 = f.read()
  21.     while counter < 0x100:
  22.         count = file1.count(counter)
  23.         try:
  24.             if sys.argv[2] == "logging":
  25.                 print(f"{count} occurrences found of {hex(counter)}")
  26.         except:
  27.             a = 0
  28.         listOfVals[hex(counter)] = count
  29.         counter += 1
  30. output = max(listOfVals,key=listOfVals.get)
  31. print(output)
  32.  
  33.  
  34.  
  35. logger.info(f"Possible Hex Key: {output}")
  36.  
  37. inp = input("Decrypt with hex key? (Y/N) ")
  38. if inp == "Y":
  39.     outData = Decrypt(output,file1)
  40.     file2 = open("{0}_decrypted".format(sys.argv[1]),"w+b")
  41.     file2.write(outData)
  42.     file2.close()
  43. elif inp == "N":
  44.     logger.error("Ok. Exiting.")
  45.     sys.exit()
  46. else:
  47.     logger.error("Incorrect arg supplied.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement