Chrome 浏览器 Cookies 提取和解密
发表于 : 2021年10月15日 10:44
StackOverflow - Chrome 80 how to decode cookies
以下内容翻译自 Topaco 的答案,
从 Local State 文件获取钥匙并解密钥匙,得到decrypted_key。
加密过的 cookie 值通常以 "v10" 开头(字面值为\x76\x31\x30),剩下部分是二进制密文。
使用 AES-256 GCM 模式加解密
相关工具:
Cookies查看工具(转明文)NirSoft - ChromeCookiesView
DB Browser for SQLite
以下内容翻译自 Topaco 的答案,
从 Local State 文件获取钥匙并解密钥匙,得到decrypted_key。
代码: 全选
import os
import json
import base64
import win32crypt
from Crypto.Cipher import AES
path = r'%LocalAppData%\Google\Chrome\User Data\Local State'
path = os.path.expandvars(path)
with open(path, 'r') as file:
encrypted_key = json.loads(file.read())['os_crypt']['encrypted_key']
encrypted_key = base64.b64decode(encrypted_key) # Base64 decoding
encrypted_key = encrypted_key[5:] # Remove DPAPI
decrypted_key = win32crypt.CryptUnprotectData(encrypted_key, None, None, None, 0)[1] # Decrypt key
代码: 全选
data = bytes.fromhex('763130...') # the encrypted cookie
nonce = data[3:3+12]
ciphertext = data[3+12:-16]
tag = data[-16:]
代码: 全选
cipher = AES.new(decrypted_key, AES.MODE_GCM, nonce=nonce)
plaintext = cipher.decrypt_and_verify(ciphertext, tag) # the decrypted cookie
Cookies查看工具(转明文)NirSoft - ChromeCookiesView
DB Browser for SQLite