您的位置:首页 > 产品设计 > UI/UE

Chrome 43+浏览器 Cookies encrypted_value解密脚本

2015-12-23 13:48 239 查看
python 3.3.5

# -*- coding: utf-8 -*-

# Used information from:
# http://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=r'C:\Users\username\AppData\Local\Google\Chrome\User Data\Default\Cookies';
hostKey="court.gov.cn";

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();
sql = "select host_key, name, value, path,encrypted_value from cookies where host_key like \'%" + hostKey+"%\'";
c.execute(sql);

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));
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: