python 獲取谷歌瀏覽器保存的密碼
由于谷歌瀏覽器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)
# 去掉開(kāi)頭的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")
# 隨機(jī)生成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 獲取谷歌瀏覽器保存的密碼的詳細(xì)內(nèi)容,更多關(guān)于python 獲取瀏覽器密碼的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- python自動(dòng)化測(cè)試無(wú)法啟動(dòng)谷歌瀏覽器問(wèn)題
- Python爬蟲(chóng)之Selenium實(shí)現(xiàn)關(guān)閉瀏覽器
- 使用Python解析Chrome瀏覽器書(shū)簽的示例
- 基于Python模擬瀏覽器發(fā)送http請(qǐng)求
- Python使用Selenium模擬瀏覽器自動(dòng)操作功能
- Python獲取瀏覽器窗口句柄過(guò)程解析
- python能在瀏覽器能運(yùn)行嗎
- Python flask框架實(shí)現(xiàn)瀏覽器點(diǎn)擊自定義跳轉(zhuǎn)頁(yè)面
- python GUI庫(kù)圖形界面開(kāi)發(fā)之PyQt5瀏覽器控件QWebEngineView詳細(xì)使用方法
- python爬蟲(chóng)模擬瀏覽器的兩種方法實(shí)例分析
相關(guān)文章
tensorflow ckpt模型和pb模型獲取節(jié)點(diǎn)名稱,及ckpt轉(zhuǎn)pb模型實(shí)例
今天小編就為大家分享一篇tensorflow ckpt模型和pb模型獲取節(jié)點(diǎn)名稱,及ckpt轉(zhuǎn)pb模型實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-01-01
PyTorch實(shí)現(xiàn)多維度特征輸入邏輯回歸
這篇文章主要介紹了PyTorch實(shí)現(xiàn)多維度特征輸入邏輯回歸,首先進(jìn)行數(shù)據(jù)采取數(shù)據(jù)集展開(kāi)詳細(xì)內(nèi)容,需要的小伙伴可以參考一下2022-03-03
Python數(shù)據(jù)結(jié)構(gòu)與算法之列表(鏈表,linked list)簡(jiǎn)單實(shí)現(xiàn)
這篇文章主要介紹了Python數(shù)據(jù)結(jié)構(gòu)與算法之列表(鏈表,linked list)簡(jiǎn)單實(shí)現(xiàn),具有一定參考價(jià)值,需要的朋友可以了解下。2017-10-10
Python實(shí)戰(zhàn)之實(shí)現(xiàn)簡(jiǎn)單的名片管理系統(tǒng)
這篇文章主要介紹了Python實(shí)戰(zhàn)之實(shí)現(xiàn)簡(jiǎn)單的名片管理系統(tǒng),文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)python的小伙伴們有非常好的幫助,需要的朋友可以參考下2021-04-04
舉例講解Python中metaclass元類(lèi)的創(chuàng)建與使用
在Python中我們用type函數(shù)可以動(dòng)態(tài)地創(chuàng)建一個(gè)元類(lèi),同樣也可以用__metaclass__屬性來(lái)指定一個(gè)元類(lèi),接下來(lái)我們就來(lái)具體舉例講解Python中metaclass元類(lèi)的創(chuàng)建與使用2016-06-06
Python的Bottle框架中返回靜態(tài)文件和JSON對(duì)象的方法
這篇文章主要介紹了Python的Bottle框架中返回靜態(tài)文件和JSON對(duì)象的方法,Bottle框架在Python開(kāi)發(fā)者中具有很高的人氣,需要的朋友可以參考下2015-04-04
Python?Pandas如何獲取和修改任意位置的值(at,iat,loc,iloc)
在我們對(duì)數(shù)據(jù)進(jìn)行選擇之后,需要對(duì)特定的數(shù)據(jù)進(jìn)行設(shè)置更改,設(shè)置,下面這篇文章主要給大家介紹了關(guān)于Python?Pandas如何獲取和修改任意位置的值(at,iat,loc,iloc)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-01-01
Pytorch框架實(shí)現(xiàn)mnist手寫(xiě)庫(kù)識(shí)別(與tensorflow對(duì)比)
這篇文章主要介紹了Pytorch框架實(shí)現(xiàn)mnist手寫(xiě)庫(kù)識(shí)別(與tensorflow對(duì)比),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
Django?logging日志模塊實(shí)例詳解(日志記錄模板配置)
Django使用python自帶的logging作為日志打印工具,下面這篇文章主要給大家介紹了Django?logging日志模塊(日志記錄模板配置)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08

