【问题标题】:Cookie issue with Chrome 33 BetaChrome 33 Beta 的 Cookie 问题
【发布时间】:2014-02-01 09:13:24
【问题描述】:

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

【问题讨论】:

    标签: google-chrome cookies


    【解决方案1】:

    如 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));
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-06
        • 1970-01-01
        • 2020-05-19
        • 2020-11-20
        • 1970-01-01
        • 1970-01-01
        • 2020-07-13
        • 2020-08-23
        相关资源
        最近更新 更多