当我尝试在 Windows 中解密 chrome 密码时,出现此错误 pywintypes.error: (87, 'CryptProtectData', 'Paramètre invalid.')

Ro *_* Ck 4 sqlite google-chrome pywin32 python-3.x

这是我的所有代码,我尝试用它来解密 Windows 中的 chrome 密码。

\n\n
import os\nimport sqlite3\nimport win32crypt\ndef get_chrome():\n    data_path = os.path.expanduser('~') + r'\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Login Data'\n    c = sqlite3.connect(data_path)\n    cursor = c.cursor()\n    select_statement = 'SELECT origin_url, username_value, password_value FROM logins'\n    cursor.execute(select_statement)\n    login_data = cursor.fetchall()\n\n    cred = {}\n\n    string = ''\n\n    for url, user_name, pwd in login_data:\n        pwd = win32crypt.CryptUnprotectData(pwd)\n        cred[url] = (user_name, pwd[1].decode('utf8'))\n        string += '\\n[+] URL:%s USERNAME:%s PASSWORD:%s\\n' % (url,user_name,pwd[1].decode('utf8'))\n        print(string)\n\n\nif __name__=='__main__':\n    get_chrome()\n
Run Code Online (Sandbox Code Playgroud)\n\n

它显示的错误是:

\n\n
pywintypes.error: (87, 'CryptProtectData', 'Param\xc3\xa8tre incorrect.') when i'm trying to decrypt chrome password in windows\n
Run Code Online (Sandbox Code Playgroud)\n

小智 5

我假设这是来自 w3w3w3 youtube 频道。我遇到了和你完全相同的问题,但是有人发布了解决方案:

 import os
 import json
 import base64
 import sqlite3
 import win32crypt
 from Cryptodome.Cipher import AES
 import shutil

 def get_master_key():
     with open(os.environ['USERPROFILE'] + os.sep + r'AppData\Local\Google\Chrome\User 
 Data\Local State', "r") as f:
         local_state = f.read()
         local_state = json.loads(local_state)
     master_key = base64.b64decode(local_state["os_crypt"]["encrypted_key"])
     master_key = master_key[5:]  # removing DPAPI
     master_key = win32crypt.CryptUnprotectData(master_key, None, None, None, 0)[1]
     return master_key

 def decrypt_payload(cipher, payload):
     return cipher.decrypt(payload)

 def generate_cipher(aes_key, iv):
     return AES.new(aes_key, AES.MODE_GCM, iv)

 def decrypt_password(buff, master_key):
     try:
         iv = buff[3:15]
         payload = buff[15:]
         cipher = generate_cipher(master_key, iv)
         decrypted_pass = decrypt_payload(cipher, payload)
         decrypted_pass = decrypted_pass[:-16].decode()  # remove suffix bytes
         return decrypted_pass
     except Exception as e:
         # print("Probably saved password from Chrome version older than v80\n")
         # print(str(e))
         return "Chrome < 80"
 

master_key = get_master_key()
login_db = os.environ['USERPROFILE'] + os.sep + r'AppData\Local\Google\Chrome\User Data\default\Login Data'
shutil.copy2(login_db, "Loginvault.db") #making a temp copy since Login Data DB is locked while Chrome is running
conn = sqlite3.connect("Loginvault.db")
cursor = conn.cursor()
try:
    cursor.execute("SELECT action_url, username_value, password_value FROM logins")
    for r in cursor.fetchall():
        url = r[0]
        username = r[1]
        encrypted_password = r[2]
        decrypted_password = decrypt_password(encrypted_password, master_key)
        if len(username) > 0:
            print("URL: " + url + "\nUser Name: " + username + "\nPassword: " + decrypted_password + "\n" + "*" * 50 + "\n")
except Exception as e:
    pass
cursor.close()
conn.close()
try:
    os.remove("Loginvault.db")
except Exception as e:
    pass
Run Code Online (Sandbox Code Playgroud)