Skip to content

Instantly share code, notes, and snippets.

@andreycizov
Last active July 10, 2020 14:06
Show Gist options
  • Save andreycizov/9566ab117e732b5e67fd782d9e9357e6 to your computer and use it in GitHub Desktop.
Save andreycizov/9566ab117e732b5e67fd782d9e9357e6 to your computer and use it in GitHub Desktop.
Extract Chrome Cookies on Linux using Python
import hashlib
import os
import sqlite3
import yaml
from Crypto.Cipher import AES
def extract_cookie(domain_name) -> bytes:
with sqlite3.connect(os.path.expanduser('~/.config/google-chrome/Default/Cookies')) as conn:
cursor = conn.cursor()
cursor.execute(
"""
select encrypted_value from cookies where host_key = ? and name = "cookiename";
""",
(domain_name,),
)
rtn, = cursor.fetchone()
return rtn
def extract_chrome_encryption_decrypt(body: bytes):
if body[:3] != b'v10':
raise AssertionError(body[:3])
body = body[3:]
key = hashlib.pbkdf2_hmac(
'sha1',
b'peanuts',
b'saltysalt',
1, # 1003 on Mac
dklen=16,
)
IV = b" "
cipher = AES.new(key, AES.MODE_CBC, IV)
rtn = cipher.decrypt(body)
padding_size = rtn[-1]
rtn = rtn[:-padding_size]
return rtn.decode('utf-8')
def main():
cookie_uk = extract_chrome_encryption_decrypt(extract_cookie("www.google.com"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment