skym龙 2022-10-15 22:24 采纳率: 0%
浏览 47
已结题

Cryptography解密谷歌浏览器的登录密码

用Cryptography解密谷歌浏览器的登录密码(login data)失败

自己电脑因为重装系统,但是谷歌浏览器记录的密码已经不能导出了,所以就尝试从备份文件里面导出已经记录的密码。使用C#对login data文件进行解密时,报错提示“该项不适于在指定状态下使用。”。
电脑系统是win7,谷歌浏览器版本是104.0.5112.102 (正式版本) (64 位)
电脑重装后的系统版本、用户名、密码与原系统一致。

代码如下
public static void QueryDB()
        {
            connection.Open();

            // query the rows
            SQLiteCommand command = connection.CreateCommand();
            command.CommandText = "select * from logins";

            SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);
            DataTable table = new DataTable();
            adapter.Fill(table);

            foreach (DataRow row in table.Rows)
            {
                byte[] password = (byte[])row["password_value"];
                String password_d = Decrypt(password);
                Console.WriteLine(password_d);
                Console.WriteLine($"url: {row["origin_url"]} username: {row["username_value"]}");
            }
            connection.Close();
        }
        public static string Decrypt(byte[] EncryptedData)
        {
            if (EncryptedData == null || EncryptedData.Length == 0)
            {
                return null;
            }
            byte[] decryptedData = ProtectedData.Unprotect(EncryptedData, null, DataProtectionScope.CurrentUser);
            return Encoding.UTF8.GetString(decryptedData);
        }

报错如下

未处理System.Security.Cryptography.CryptographicException
HResult=-2146893813
Message=该项不适于在指定状态下使用。

Source=System.Security
StackTrace:
在 System.Security.Cryptography.ProtectedData.Unprotect(Byte[] encryptedData, Byte[] optionalEntropy, DataProtectionScope scope)
在 ChromePasswords.Chrome2.Decrypt(Byte[] EncryptedData) 位置 G:\chrome-password-decrypt-main\ChromePasswords\Chrome2.cs:行号 48
在 ChromePasswords.Chrome2.QueryDB() 位置 G:\chrome-password-decrypt-main\ChromePasswords\Chrome2.cs:行号 36
在 ChromePasswords.Program.Main(String[] args) 位置 G:\chrome-password-decrypt-main\ChromePasswords\Program.cs:行号 14
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:

我的解答思路和尝试过的方法

根据网上查到的都是让删除“C:\Documents and Settings\skymid\Application Data\Microsoft\Crypto”、“C:\Users\skymid\Application Data\Microsoft\Crypto”、“C:\Users\skymid\AppData\Roaming\Microsoft\Crypto”或者“C:\ProgramData\Microsoft\Crypto”目录下的所有文件,也试过了不行。

请问此问题何解?
  • 写回答

2条回答 默认 最新

  • Jackyin0720 2022-10-15 23:01
    关注

    你试着借鉴python的解密方法,如下

    import os, json, base64, sqlite3
    from win32crypt import CryptUnprotectData
    from cryptography.hazmat.primitives.ciphers.aead import AESGCM
    
    
    class Chrome:
        def __init__(self):
            self.local_state = os.environ['LOCALAPPDATA'] + r'\Google\Chrome\User Data\Local State'
            self.cookie_path = os.environ['LOCALAPPDATA'] + r"\Google\Chrome\User Data\Default\Login Data"
    
        @property
        def get_key(self):
            with open(self.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:]
            key_ = CryptUnprotectData(encrypted_key, None, None, None, 0)[1]
            return key_@staticmethod
        def decrypt_string(key, secret, salt=None):
            nonce, cipher_bytes = secret[3:15], secret[15:]
            aes_gcm = AESGCM(key)
            return aes_gcm.decrypt(nonce, cipher_bytes, salt).decode('utf-8')
    
        def get_password(self):
            sql = "select username_value,password_value,signon_realm from logins"
            with sqlite3.connect(self.cookie_path) as conn:
                cu = conn.cursor()
                res = cu.execute(sql).fetchall()
                cu.close()
                result = []
                key = self.get_key()
    
                for name, encrypted_value, website in res:
                    if encrypted_value[0:3] == b'v10' or encrypted_value[0:3] == b'v11':
                        passwd = self.decrypt_string(key, encrypted_value)
                    else:
                        passwd = CryptUnprotectData(encrypted_value)[1].decode()
                    print('网站:{},用户名:{},密码:{}'.format(website, name, passwd))
    
    
    if __name__ == '__main__':
        c = Chrome()
        c.get_password()
    
    
    
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月20日
  • 创建了问题 10月15日

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助