Skip to content

Instantly share code, notes, and snippets.

@GitHub30
Last active April 4, 2024 09:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save GitHub30/427b0474008234d449acefb216a4a833 to your computer and use it in GitHub Desktop.
Save GitHub30/427b0474008234d449acefb216a4a833 to your computer and use it in GitHub Desktop.
Simple Decrypt Chrome/Firefox Cookies File (Python 3) - Windows
import sqlite3
def get_chrome_cookies(db=None):
import json
from base64 import b64decode
from win32.win32crypt import CryptUnprotectData # pip install pywin32
# should use Cryptodome in windows instead of Crypto
# otherwise will raise an import error
from Cryptodome.Cipher.AES import new, MODE_GCM # pip install pycryptodomex
if db is None:
from os.path import expandvars
db = expandvars('%LOCALAPPDATA%/Google/Chrome/User Data/Default/Cookies')
with open(db + '/../../Local State') as f:
key = CryptUnprotectData(b64decode(json.load(f)['os_crypt']['encrypted_key'])[5:])[1]
conn = sqlite3.connect(db)
conn.create_function('decrypt', 1, lambda v: new(key, MODE_GCM, v[3:15]).decrypt(v[15:-16]).decode())
cookies = dict(conn.execute("SELECT name, decrypt(encrypted_value) FROM cookies"))
conn.close()
return cookies
def get_firefox_cookies(db=None):
if db is None:
from glob import glob
from os.path import expandvars
db = glob(expandvars('%APPDATA%/Mozilla/Firefox/Profiles/*.default*/cookies.sqlite'))[0]
conn = sqlite3.connect(db)
cookies = dict(conn.execute("SELECT name, value FROM moz_cookies"))
conn.close()
return cookies
print(get_chrome_cookies())
print(get_firefox_cookies())
def get_firefox_local_storage(db=None):
if db is None:
from glob import glob
from os.path import expandvars
db = glob(expandvars('%APPDATA%/Mozilla/Firefox/Profiles/*.default*/webappsstore.sqlite'))[0]
conn = sqlite3.connect(db)
cookies = dict(conn.execute("SELECT key, value FROM webappsstore2 where key = 'X-Chime-Auth-Token'"))
conn.close()
return cookies
print(get_firefox_local_storage())
@venaxyt
Copy link

venaxyt commented Sep 11, 2021

thanks bro it works perfectly !!

@mrx23dot
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment