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
投稿
猜你喜欢
- 看了不少朋友的个人网站,有一个小问题,似乎很多朋友都忽略了,那就是版权声明的写法。虽然那只是一小行字,不过作为设计师也好,作为个人的爱好也好
- 在使用python爬虫技术采集数据信息时,经常会遇到在返回的网页信息中,无法抓取动态加载的可用数据。例如,获取某网页中,商品价格时就会出现此
- 命令行进入python打开cmd——>直接输入python即可,如下退出python方法一:先按Ctrl+z,再按Enter(回车键)
- 这篇文章利用的是matplotlib.pyplot.plot的工具来绘制折线图,这里先给出一个段代码和结果图:# -*- coding: U
- Tkinter实现UI分页标签显示:Input页,红色部分为当前Frame的位置,下半部分为第一页的子标签;三页标签的显示内容各不相同。实现
- 我们知道,关系型数据一般以规范化的形式保存,也就是说你应该尽可能少地重复数据;在正常情况下,表与表之间仅通过各种键值实现关联。进一步地讲,规
- 1、环境1、python 3.72、pyinstaller2、下载方式:2.1 python安装(略)2.2 安装pyinstaller打开
- 类:定义一件事物的抽象特点。对象:类的 实例。成员变量 − 定义在类内部的变量。该变量的值对外是不可见的,但是可以通过成
- #!/usr/bin/env pythonimport sockets = socket.socket(socket.AF_PACKET,
- 前言python类与实例的方法的调用中觉得云里雾里,思考之后将自己的想法记录下,一来加深自己理解,巩固自己记忆,而来帮助一些想要学习pyth
- 前言你可能不需要经常处理分数,但当你需要时,Python的Fraction类会给你很大的帮助。本文将给大家详细介绍关于利用标准库fracti
- 引言阿刁是一个自动化测试用例,从一出生他就被赋予终生使命,去测试一个叫登录的过程是否合理。他一直就被关在一个小黑屋里面,从来也没有出去过,小
- 1. python中数字组成的列表转化为字符串或者一串数字f=[1,2,3,4]num=len(f)m='' #
- 配置好virtualenv 和virtualenvwrapper后,使用pycharm创建新项目。之后要面临的问题就来了,之前一直使用的是s
- Pygame是跨平台Python模块,专为电子游戏设计,包含图像、声音。建立在SDL基础上,允许实时电子游戏研发而无需被低级语言(如机器语言
- <script type="text/javascript">/*<![CDAT
- 一、生成随机的测验试卷文件假如你是一位地理老师, 班上有 35 名学生, 你希望进行美国各州首府的一个小测验。不妙的是,班里有几个坏蛋, 你
- 最近忙成了狗,五六个项目堆在一起,头疼的是测试还失惊无神的给我丢来一个几十甚至上百M的日志文件,动不动就几十上百万行,就算是搜索也看得头昏眼
- 首先说明,Supervisor 只能安装在 Python 2.x 环境中!但是基本上所有的 Linux 都同时预装了 Python 2.x
- 兼容主流浏览器,独立样式表,可以很方便的进行视觉效果自定义截图:模拟下拉菜单演示代码:<!DOCTYPE html PUBLIC &q