激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - python 獲取谷歌瀏覽器保存的密碼

python 獲取谷歌瀏覽器保存的密碼

2021-08-22 00:36rm-rf* Python

這篇文章主要介紹了python 獲取谷歌瀏覽器保存的密碼的示例代碼,幫助大家更好的理解和使用python,感興趣的朋友可以了解下

由于谷歌瀏覽器80以后版本采用了新的加密方式,所以記錄在這里

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# -*- coding:utf-8 -*-
import os
import json
import base64
import sqlite3
from win32crypt import CryptUnprotectData
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
 
#  pip install pywin32
#  pip install cryptography
#  文檔:https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_win.cc?q=OSCrypt&ss=chromium
 
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"
 
  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)
    # 去掉開頭的DPAPI
    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):
    """
    解密
    """
    # 去掉'v10'
    nonce, cipher_bytes = secret[3:15], secret[15:]
    aes_gcm = AESGCM(key)
    return aes_gcm.decrypt(nonce, cipher_bytes, salt).decode('utf-8')
 
  @staticmethod
  def encrypt_string(key, data, salt=None):
    """
    加密
    """
    aes_gcm = AESGCM(key)
    prefix = "v10".encode("utf-8")
    # 隨機生成12位字符串,拼接"v10" 共15位
    nonce = os.urandom(12)
    cipher_bytes = data.encode("utf-8")
    return prefix + nonce + aes_gcm.encrypt(nonce, cipher_bytes, salt)
 
  def get_password(self, host):
    sql = f"select username_value,password_value from logins where signon_realm ='{host}';"
    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 in res:
 
        if encrypted_value[0:3] == b'v10' or encrypted_value[0:3] == b'v11':
          password = self.decrypt_string(key, encrypted_value)
        else:
          password = CryptUnprotectData(encrypted_value)[1].decode()
        result.append({'user_name': name, 'password': password})
      return result
 
  def set_password(self, host, username, password):
    key = self.get_key()
    encrypt_secret = self.encrypt_string(key, password)
    sq = f"""update logins set password_value=x'{encrypt_secret.hex()}' where signon_realm ='{host}' and username_value='{username}';"""
    with sqlite3.connect(self.cookie_path) as conn:
      cu = conn.cursor()
      cu.execute(sq)
      conn.commit()
 
 
if __name__ == '__main__':
  a = Chrome()
  aa = a.get_password("https://baidu.com")
  print(aa)

以上就是python 獲取谷歌瀏覽器保存的密碼的詳細內容,更多關于python 獲取瀏覽器密碼的資料請關注服務器之家其它相關文章!

原文鏈接:https://www.cnblogs.com/lyalong/tag/python/default.html?page=2

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 天天黄色片 | 手机视频在线播放 | 毛片在线免费 | 亚洲成人欧美 | 日本视频在线免费观看 | 在线亚洲播放 | 欧美视频首页 | 狠狠干五月天 | 欧美性生活网站 | 免费观看视频网站 | 蜜桃一本色道久久综合亚洲精品冫 | 欧美在线 | 亚洲 | 久久久三级免费电影 | 把娇妻调教成暴露狂 | 日本一区二区视频在线观看 | 精品国产视频一区二区三区 | 精品国产99久久久久久宅男i | 精品无吗乱吗av国产爱色 | 亚洲第一激情网 | 欧美成人精品一区 | 国产做爰全免费的视频黑人 | aaaaaaa毛片| 免费在线观看国产 | 91高清完整版 | 中文字幕亚洲一区二区三区 | 国产成人精品区一区二区不卡 | 少妇的肉体的满足毛片 | 欧美成人国产va精品日本一级 | 成人在线免费视频观看 | 国产一区二区三区欧美 | 在线观看中文字幕国产 | 国产91影院 | 欧美日韩中文字幕在线视频 | 欧美久久一区二区 | 日本欧美一区二区三区视频麻豆 | 亚州精品在线视频 | 色骚综合| 高清国产午夜精品久久久久久 | 成人免费网站在线观看 | 黄视频网站免费观看 | 欧美人与牲禽动交精品一区 |