python 获取谷歌浏览器保存的密码
作者:rm-rf* 发布时间:2022-05-21 21:39:49
标签: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)
# 去掉开头的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)
来源:https://www.cnblogs.com/lyalong/tag/python/default.html?page=2
0
投稿
猜你喜欢
- 4款JavaScript放大镜特效脚本。准确的说,Anythingzoomer和Bezoom才是正宗的放大镜特效,当鼠标悬浮在图片上时,能放
- 今天写了一个java项目连接数据库,之后写了一个执行入库操作的模块。此时暴露出一个问题就是项目的中文插入到数据库时会是乱码:项目输出的中文:
- 导读演示了使用PyTorch最近发布的新工具torchserve来进行PyTorch模型的部署。最近,PyTorch推出了名为torchse
- 昨天公司的网络更换,然后在使用git操作代码的时候,遇见了标题所述问题。仅以此文,记录该问题的解决过程。首先第一步: 得到本机的I
- 有时候想同时(同级)展示多个视图,而不是嵌套展示,例如创建一个布局,有 sidebar(侧导航) 和 main(主内容) 两个视图,这个时候
- 需求细化:1.身份证必须能够通过身份证校验程序。2.通过查询,发现身份证号码是有国家标准的,标准号为 GB 11643-1999 可以从百度
- 今天从网上看到这个功能,不错啊,以后就可以在文章中,增加这个功能了var re = /<a h
- 利用python进行求解,求解的要求是不能使用python内部封装好的函数例如:maxway1:def findmax(data,n): i
- 变量的存储在高级语言中,变量是对内存及其地址的抽象。对于python而言,python的一切变量都是对象,变量的存储,采用了引用语义的方式,
- 1. 引入messages模块from django.contrib import messages2. 把messages写入view中@
- 本文实例为大家分享了python实现单链表反转的具体代码,供大家参考,具体内容如下代码如下:class Node(object): 
- 前言前段时间因为需要处理一大堆验收单,都是一些简单的复制粘贴替换工作,于是就想到用python进行处理。接下来进入正题~实现需求我是用的开发
- 设置某个字段的值自增由于某个业务需要手动操作数据库,并设置主键ID不重复。做个记录set @rownum=0;select a.id, @r
- 先看效果,实现一个图片左右摇动,在一般的H5宣传页,商家活动页面我们会看到这样的动画,小程序的动画效果不同于css3动画效果,是通过js来完
- 项目需求:用户注册页面注册之后,系统会发送一封邮件到用户邮箱,用户点击链接以激活账户,其中链接中的用户信息需要加密处理一下其中激活自己邮箱的
- 用yum更新PHP,只需用一条命令就可以搞定: #yum update php 但问题来了,使用此命令后,系统告诉我,没有发现可更新的包。而
- 我想大家都有一些开了80端口的肉 * ,如果是国内的出于安全就不要往下看了,如果不不妨往下看一下,小弟献丑了,以求抛砖引玉。在肉鸡上放网站最麻
- 前言 本篇章主要介绍二叉树的应用之一------二叉排序树,包括二叉排序树的定义、查找、插入、构造、删除及查找效率分析。1. 二叉排序树的
- 本文实例讲述了python计算方程式根的方法。分享给大家供大家参考。具体实现方法如下:''' roots = pol
- 上次我们已经搞定了逻辑层的单元测试,这次我们来康康接口层的单元测试。接口层主要负责的就是请求的处理,最常见的就是 HTTP 请求的处理。但针