Chrome 33 Beta的Cookie问题

时间:2014-02-01 09:13:24

标签: google-chrome cookies

是否有其他人在Chrome 33 Beta中阅读Cookie值时遇到问题?我们使用了SQLite数据库浏览器,并查看了我们删除的cookie的空值。我们对IE,Firefox和所有以前版本的Chrome都没有这个问题。

2 个答案:

答案 0 :(得分:2)

正如eneuron所述,Chrome v33 +现在可以加密cookie。

仍然可以使用SQLite获取值(尽管不支持使用SQLite访问cookie)。您可以通过在Windows计算机上调用CryptUnprotectData来解密基于this discussion的数据。我相信您必须以创建cookie的同一用户身份登录。

这是一个基于python 3中编写的previously asked question代码的示例脚本:

# Used information from:
# https://stackoverflow.com/questions/463832/using-dpapi-with-python
# http://www.linkedin.com/groups/Google-Chrome-encrypt-Stored-Cookies-36874.S.5826955428000456708

from ctypes import *
from ctypes.wintypes import DWORD
import sqlite3;

cookieFile="C:/Users/your_user_name/AppData/Local/Google/Chrome/User Data/Default/Cookies";
hostKey="my_host_key";

LocalFree = windll.kernel32.LocalFree;
memcpy = cdll.msvcrt.memcpy;
CryptProtectData = windll.crypt32.CryptProtectData;
CryptUnprotectData = windll.crypt32.CryptUnprotectData;
CRYPTPROTECT_UI_FORBIDDEN = 0x01;

class DATA_BLOB(Structure):
    _fields_ = [("cbData", DWORD), ("pbData", POINTER(c_char))];

def getData(blobOut):
    cbData = int(blobOut.cbData);
    pbData = blobOut.pbData;
    buffer = c_buffer(cbData);
    memcpy(buffer, pbData, cbData);
    LocalFree(pbData);
    return buffer.raw;

def encrypt(plainText):
    bufferIn = c_buffer(plainText, len(plainText));
    blobIn = DATA_BLOB(len(plainText), bufferIn);   
    blobOut = DATA_BLOB();

    if CryptProtectData(byref(blobIn), u"python_data", None,
                       None, None, CRYPTPROTECT_UI_FORBIDDEN, byref(blobOut)):
        return getData(blobOut);
    else:
        raise Exception("Failed to encrypt data");

def decrypt(cipherText):
    bufferIn = c_buffer(cipherText, len(cipherText));
    blobIn = DATA_BLOB(len(cipherText), bufferIn);
    blobOut = DATA_BLOB();

    if CryptUnprotectData(byref(blobIn), None, None, None, None,
                              CRYPTPROTECT_UI_FORBIDDEN, byref(blobOut)):
        return getData(blobOut);
    else:
        raise Exception("Failed to decrypt data");

conn = sqlite3.connect(cookieFile);
c = conn.cursor();
c.execute("""\
SELECT 
    host_key,
    name,
    path,
    value,
    encrypted_value
FROM cookies
WHERE host_key = '{0}'
;
""".format(hostKey));

cookies = c.fetchmany(10);
c.close();

for row in cookies:
    dc = decrypt(row[4]);
    print( \
"""
host_key: {0}
name: {1}
path: {2}
value: {3}
encrpyted_value: {4}
""".format(row[0], row[1], row[2], row[3], dc));

答案 1 :(得分:1)

从版本33开始,Chrome正在加密Cookie,这就是您无法检索它们的原因。在SQlite DB中有一个名为“encrypted_value”的新字段;使用时,旧字段“value”保持为空 - 这就是为什么你得到空字符串。