Advertisement
FlyFar

crack_enmicromsg_db_(python_version).py

Oct 28th, 2023
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.43 KB | Cybersecurity | 0 0
  1. #!/usr/bin/env python2
  2.  
  3.  
  4. '''15fbee0 '''
  5. # ======================== Edit checkpoint and process_no==================
  6. checkpoint = '995'  # first three chars to start from
  7. process_no = 16
  8. # ========================================================================
  9.  
  10.  
  11. import os, sys
  12. import threading
  13. import multiprocessing
  14. import itertools
  15. from argparse import ArgumentParser
  16. from pysqlcipher import dbapi2 as sqlite
  17.  
  18. from hashlib import md5
  19.  
  20.  
  21.  
  22. TOTAL_KEY_LENGTH = 7
  23. PROCESS_KEY_LENGTH = 3
  24.  
  25. db = 'EnMicroMsg.db'
  26. output = 'output_db.db'
  27.  
  28. def worker(id, prefix):
  29.     import itertools, time
  30.     print ('-------------id: %d  ===== prefix: %s' % (id, prefix))
  31.     if os.path.exists(output):
  32.         return  'Alread Done.'
  33.  
  34.     a = time.time()
  35.     str_list = '0123456789abcdef'
  36.     key_length = TOTAL_KEY_LENGTH - PROCESS_KEY_LENGTH
  37.     count = 0
  38.     for i in itertools.product(str_list, repeat=key_length):
  39.         count += 1
  40.         key = prefix + ''.join(i)
  41.         try:
  42.             conn = sqlite.connect(db)
  43.             c = conn.cursor()
  44.  
  45.             c.execute("PRAGMA key = '" + key + "';")
  46.             c.execute("PRAGMA cipher_use_hmac = OFF;")
  47.             c.execute("PRAGMA cipher_page_size = 1024;")
  48.             c.execute("PRAGMA kdf_iter = 4000;")
  49.             c.execute("SELECT name FROM sqlite_master WHERE type='table'")
  50.  
  51.             c.execute("ATTACH DATABASE '" + output + "' AS db KEY '';")
  52.             c.execute("SELECT sqlcipher_export('db');")
  53.             c.execute("DETACH DATABASE db;")
  54.             print "Decrypt and dump database to {} ... ".format(output)
  55.             print key
  56.             print('OK!!!!!!!!!')
  57.             with open('CRACKED_PASS.txt', 'a') as f:
  58.                 f.write(key)
  59.                 f.write('\n')
  60.             break
  61.         except Exception as e:
  62.             # print(str(e))
  63.             pass
  64.         finally:
  65.             conn.close()
  66.  
  67.         # if count > count_limit:
  68.         #     break
  69.         if count % 100000 == 0:
  70.             p = 1.0 * count / 16 ** key_length
  71.             b = time.time() - a
  72.             rt = b / (p + 0.0000001) * (1 - p)
  73.             print('%d: %f %%, time: %f s, end time: %f s' % (id, p * 100,
  74.                                                              b,
  75.                                                              rt)
  76.                   )
  77.             print(key)
  78.  
  79.     b = time.time() - a
  80.     print('%d: Total time: %f s, per loop: %f s, speed: %f 1/s' % (id, b, b / count, count / b))
  81.     return '%d Done' % (id)
  82.  
  83. DEFAULT_OUTPUT_DB_NAME = 'decrypted.db'
  84.  
  85. if __name__ == '__main__':
  86.  
  87.     str_list = '0123456789abcdef'
  88.     key_length1 = PROCESS_KEY_LENGTH
  89.  
  90.     # Multi-process
  91.     record = []
  92.     result = []
  93.     pool = multiprocessing.Pool(processes=process_no)
  94.     id_a = 0
  95.    
  96.     RECOVERED_FLAG = True if checkpoint=='' else False
  97.    
  98.     for i in itertools.product(str_list, repeat=key_length1):
  99.         prefix = ''.join(i)
  100.        
  101.         if not RECOVERED_FLAG:
  102.             if prefix != checkpoint:
  103.                 continue
  104.             else:
  105.                 print("Continue from "+checkpoint)
  106.                 RECOVERED_FLAG = True
  107.        
  108.         result.append(pool.apply_async(worker, (id_a, prefix)))
  109.         id_a += 1
  110.         if os.path.exists(output):
  111.             print  'Already Done.'
  112.             break
  113.  
  114.     pool.close()
  115.     pool.join()
  116.     for res in result:
  117.         print res.get()
  118.     print "Sub-process(es) done."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement