一,历史变迁
80之前,解密:win32crypt.CryptUnprotectData(encrypted_value_bytes,None,None,None,0)[1],老文N多,自行搜索。
80开始,改了:https://github.com/chromium/chromium/blob/master/components/os_crypt/os_crypt_win.cc
AESGCM加密cookie明文
def EncryptString(key,plaintext):
plainbytes=plaintext.encode('utf-8')
nonce=os.urandom(12)
aesgcm=AESGCM(key)
cipherbytes=aesgcm.encrypt(nonce,plainbytes,None)
data=b'v10'+nonce+cipherbytes
#也有v11的,反正就前3字节,无影响
return data
AESGCM的key是这么生成的:(1)随机32字节DPAPI加密(2)5字节b’DPAPI’头(3)base64编码
def generate_a_new_key():
key=os.urandom(32)
encrypted_key=win32crypt.CryptProtectData(key,None,None,None,None,0)
encrypted_key_with_header=b'DPAPI'+encrypted_key
base64_encrypted_key=base64.b64encode(encrypted_key_with_header)
return base64_encrypted_key
二,读取解密
因此,解密就是:(1)读取数据库里的密文(字节)(2)AESGCM解密。两个路径:
Cookies文件(sqlite3 db,储存网站的cookies)
Local State文件(json,储存各种,key也在其中)
python读取解密
# -*- coding=utf-8 -*-
import os
import json
import base64
import sqlite3
import</