Chrome 43+浏览器 Cookies encrypted_value解密脚本
python 3.3.5
1 # -*- coding: utf-8 -*- 2 3 # Used information from: 4 # http://stackoverflow.com/questions/463832/using-dpapi-with-python 5 # http://www.linkedin.com/groups/Google-Chrome-encrypt-Stored-Cookies-36874.S.5826955428000456708 6 7 from ctypes import * 8 from ctypes.wintypes import DWORD 9 import sqlite3; 10 11 cookieFile=r'C:\Users\username\AppData\Local\Google\Chrome\User Data\Default\Cookies'; 12 hostKey="court.gov.cn"; 13 14 LocalFree = windll.kernel32.LocalFree; 15 memcpy = cdll.msvcrt.memcpy; 16 CryptProtectData = windll.crypt32.CryptProtectData; 17 CryptUnprotectData = windll.crypt32.CryptUnprotectData; 18 CRYPTPROTECT_UI_FORBIDDEN = 0x01; 19 20 class DATA_BLOB(Structure): 21 _fields_ = [("cbData", DWORD), ("pbData", POINTER(c_char))]; 22 23 def getData(blobOut): 24 cbData = int(blobOut.cbData); 25 pbData = blobOut.pbData; 26 buffer = c_buffer(cbData); 27 memcpy(buffer, pbData, cbData); 28 LocalFree(pbData); 29 return buffer.raw; 30 31 def encrypt(plainText): 32 bufferIn = c_buffer(plainText, len(plainText)); 33 blobIn = DATA_BLOB(len(plainText), bufferIn); 34 blobOut = DATA_BLOB(); 35 36 if CryptProtectData(byref(blobIn), u"python_data", None, 37 None, None, CRYPTPROTECT_UI_FORBIDDEN, byref(blobOut)): 38 return getData(blobOut); 39 else: 40 raise Exception("Failed to encrypt data"); 41 42 def decrypt(cipherText): 43 bufferIn = c_buffer(cipherText, len(cipherText)); 44 blobIn = DATA_BLOB(len(cipherText), bufferIn); 45 blobOut = DATA_BLOB(); 46 47 if CryptUnprotectData(byref(blobIn), None, None, None, None, 48 CRYPTPROTECT_UI_FORBIDDEN, byref(blobOut)): 49 return getData(blobOut); 50 else: 51 raise Exception("Failed to decrypt data"); 52 53 conn = sqlite3.connect(cookieFile); 54 c = conn.cursor(); 55 sql = "select host_key, name, value, path,encrypted_value from cookies where host_key like \'%" + hostKey+"%\'"; 56 c.execute(sql); 57 58 cookies = c.fetchmany(10); 59 c.close(); 60 61 for row in cookies: 62 dc = decrypt(row[4]); 63 print( \ 64 """ 65 host_key: {0} 66 name: {1} 67 path: {2} 68 value: {3} 69 encrpyted_value: {4} 70 """.format(row[0], row[1], row[2], row[3], dc));