Advertisement
FlyFar

tools/encrypt_db_again.py

Oct 28th, 2023
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | Cybersecurity | 0 0
  1. #!/usr/bin/env python2
  2.  
  3.  
  4. from pysqlcipher import dbapi2 as sqlite
  5.  
  6. db = 'output_db.db'
  7. output = 'output_encrypted_db.db'
  8.  
  9. key = '0123456'
  10.  
  11. print "Please change the 'key', 'db', and 'output' first!"
  12. print "key='"+key+"'"
  13.  
  14.  
  15. try:
  16.     conn = sqlite.connect(db)
  17.     c = conn.cursor()
  18.  
  19.     # c.execute("PRAGMA key = '" + '' + "';")
  20.     # c.execute("PRAGMA cipher_use_hmac = OFF;")
  21.     # c.execute("PRAGMA cipher_page_size = 1024;")
  22.     # c.execute("PRAGMA kdf_iter = 4000;")
  23.     c.execute("SELECT name FROM sqlite_master WHERE type='table'")
  24.  
  25.     c.execute("ATTACH DATABASE '" + output + "' AS db KEY '" + key + "';")
  26.  
  27.     # https://www.zetetic.net/sqlcipher/sqlcipher-api/#sqlcipher_export
  28.     c.execute("PRAGMA db.cipher_use_hmac = OFF;")
  29.     c.execute("PRAGMA db.cipher_page_size = 1024;")
  30.     c.execute("PRAGMA db.kdf_iter = 4000;")
  31.  
  32.     c.execute("SELECT sqlcipher_export('db');")
  33.     c.execute("DETACH DATABASE db;")
  34.     print "Decrypt and dump database to {} ... ".format(output)
  35.     print key
  36.     print('OK!!!!!!!!!')
  37.     # with open('CRACKED_PASS.txt', 'a') as f:
  38.     #     f.write(key)
  39.     #     f.write('\n')
  40. except Exception as e:
  41.     print(str(e))
  42.     # pass
  43. finally:
  44.     conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement