Guest User

TeslaCrack - decrypt your files after TeslaCrypt infections!

a guest
Dec 13th, 2015
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.22 KB | None | 0 0
  1. # TeslaCrypt cracker
  2. #
  3. # by Googulator
  4. #
  5. # To use, factor the 2nd hex string found in the headers of affected files using msieve.
  6. # The AES-256 key will be one of the factors, typically not a prime - experiment to see which one works.
  7. # Insert the hex string & AES key below, under known_keys, then run on affected directory.
  8. # If an unknown key is reported, crack that one using msieve, then add to known_keys and re-run.
  9. #
  10. # This script requires pycrypto to be installed.
  11. #
  12. # Enjoy! ;)
  13.  
  14. import sys
  15. import os
  16. from Crypto.Cipher import AES
  17. import struct
  18.  
  19. known_keys = {
  20.     'D4E0010A8EDA7AAAE8462FFE9562B29871B9DA186D98B5B15EC9F77803B60EAB12ADDF78CBD4D9314A0C31270CC8822DCC071D10193D1E612360B26582DAF124': b'\xEA\x68\x5A\x3C\xDB\x78\x0D\xF2\x12\xEB\xAA\x50\x03\xAD\xC3\xE1\x04\x06\x3E\xBC\x25\x93\x52\xC5\x09\x88\xB7\x56\x1A\xD1\x34\xA5',
  21.     '9F2874FB536C0A6EF7B296416A262A8A722A38C82EBD637DB3B11232AE0102153C18837EFB4558E9E2DBFC1BB4BE799AE624ED717A234AFC5E2F8E2668C76B6C': b'\xCD\x0D\x0D\x54\xC4\xFD\xB7\x64\x7C\x4D\xB0\x95\x6A\x30\x46\xC3\x4E\x38\x5B\x51\xD7\x35\xD1\x7C\x00\x9D\x47\x3E\x02\x84\x27\x95',
  22.     '115DF08B0956AEDF0293EBA00CCD6793344D6590D234FE0DF2E679B7159E8DB05F960455F17CDDCE094420182484E73D4041C39531B5B8E753E562910561DE52': b'\x1A\xDC\x91\x33\x3E\x8F\x6B\x59\xBB\xCF\xB3\x34\x51\xD8\xA3\xA9\x4D\x14\xB3\x84\x15\xFA\x33\xC0\xF7\xFB\x69\x59\x20\xD3\x61\x8F',
  23. }
  24.  
  25. extension = '.vvv'
  26. magic = b'\xDE\xAD\xBE\xEF'
  27.  
  28. delete = False
  29.  
  30. unknown_keys = {}
  31.  
  32. def decrypt_file(path):
  33.     try:
  34.         do_unlink = False
  35.         with open(path, "rb") as fin:
  36.             header = fin.read(414)
  37.            
  38.             if header[:4] != magic:
  39.                 print path + " doesn't appear to be TeslaCrypted"
  40.                 return
  41.            
  42.             if header[0x108:0x188] not in known_keys:
  43.                 unknown_keys[header[0x108:0x188]] = path
  44.                 print "Cannot decrypt {}, unknown key".format(path)
  45.                 return
  46.            
  47.             decryptor = AES.new(known_keys[header[0x108:0x188]], AES.MODE_CBC, header[0x18a:0x19a])
  48.             size = struct.unpack('<I', header[0x19a:0x19e])[0]
  49.            
  50.             if not os.path.exists(os.path.splitext(path)[0]):
  51.                 print "Decrypting {}".format(path)
  52.                 fout = open(os.path.splitext(path)[0], 'wb')
  53.                 data = fin.read()
  54.                 fout.write(decryptor.decrypt(data)[:size])
  55.                 if delete:
  56.                     do_unlink = True
  57.             else:
  58.                 print "Not decrypting {}, decrypted copy already exists".format(path)
  59.         if do_unlink:
  60.             os.unlink(path)
  61.     except Exception:
  62.         raise
  63.         print "Error decrypting {}, please try again".format(path)
  64.        
  65. def traverse_directory(path):
  66.     try:
  67.         for entry in os.listdir(path):
  68.             if os.path.isdir(os.path.join(path, entry)):
  69.                 traverse_directory(os.path.join(path, entry))
  70.             # TODO add other known extensions
  71.             elif entry.endswith(extension) and os.path.isfile(os.path.join(path, entry)):
  72.                 decrypt_file(os.path.join(path, entry))
  73.     except Exception as e:
  74.         print "Cannot access " + path
  75.    
  76. def main(args):
  77.     path = '.'
  78.     global delete
  79.    
  80.     for arg in args:
  81.         if arg == "--delete":
  82.             delete = True
  83.         else:
  84.             path = arg
  85.  
  86.     traverse_directory(path)
  87.     if unknown_keys:
  88.         print "Software has encountered the following unknown keys, please crack them first using msieve:"
  89.         for key in unknown_keys:
  90.             print key + " found in " + unknown_keys[key]
  91.    
  92. if __name__=='__main__':
  93.     main(sys.argv[1:])
Add Comment
Please, Sign In to add comment