python - Decrypting Chromium cookies -
i'm trying use chromium cookies in python, because chromium encrypts cookies using aes (with cbc) need reverse this.
i can recover aes key os x's keychain (it's stored in base 64):
security find-generic-password -w -a chrome -s chrome safe storage # python: python -c 'from subprocess import pipe, popen; print(popen(['security', 'find-generic-password', '-w', '-a', 'chrome', '-s', 'chrome safe storage'], stdout=pipe).stdout.read().strip())' here's code have, i'm missing decrypting cookies:
from subprocess import pipe, popen sqlite3 import dbapi2 def get_encryption_key(): cmd = ['security', 'find-generic-password', '-w', '-a', 'chrome', '-s', 'chrome safe storage'] return popen(cmd, stdout=pipe).stdout.read().strip().decode('base-64') def get_cookies(database): key = get_encryption_key() dbapi2.connect(database) conn: conn.rollback() rows = conn.cursor().execute('select name, encrypted_value cookies host_key ".example.com"') cookies = {} name, enc_val in rows: val = decrypt(enc_val, key) # magic missing cookies[name] = val return cookies i tried bunch of things pycrypto's aes module but:
- i have no initialization vector (iv)
enc_valnot multiple of 16 in length
here links seem useful:
- the commit started all
- components/encryptor/keychain_password_mac.mm
- aes key generation (not used in os x else)
- cookie insertion function
can me figure out?
you're on right track! i've been working on few days , figured out. (many op helpful links chromium source.)
i've put post little more detail , working script, here basic idea:
#! /usr/bin/env python3 crypto.cipher import aes crypto.protocol.kdf import pbkdf2 # function rid of padding def clean(x): return x[:-x[-1]].decode('utf8') # replace encrypted_value sqlite3 encrypted_value = encrypted_value # trim off 'v10' chrome/ium prepends encrypted_value = encrypted_value[3:] # default values used both chrome , chromium in osx , linux salt = b'saltysalt' iv = b' ' * 16 length = 16 # on mac, replace my_pass password keychain # on linux, replace my_pass 'peanuts' my_pass = my_pass my_pass = my_pass.encode('utf8') # 1003 on mac, 1 on linux iterations = 1003 key = pbkdf2(my_pass, salt, length, iterations) cipher = aes.new(key, aes.mode_cbc, iv=iv) decrypted = cipher.decrypt(encrypted_value) print(clean(decrypted))
Comments
Post a Comment