最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

如何使用Python提取Chrome瀏覽器保存的密碼

 更新時(shí)間:2021年06月09日 08:43:48   作者:劉潤(rùn)森!  
今天小編教大家怎么用Python提取Chrome瀏覽器保存的密碼,在這需要導(dǎo)入一些必要模塊定義一些有用的函數(shù)來(lái)幫助我們?cè)谥骱瘮?shù)中調(diào)用,具體實(shí)例代碼跟隨小編一起學(xué)習(xí)下吧

由于Chrome會(huì)將大量瀏覽數(shù)據(jù)本地保存磁盤中,在本教程中,我們將編寫 Python 代碼來(lái)提取 Windows 計(jì)算機(jī)上 Chrome 中保存的密碼。

首先,讓我們安裝所需的庫(kù):

pip install pycryptodome pypiwin32

打開(kāi)一個(gè)新的 Python 文件,并導(dǎo)入必要的模塊:

import os
import json
import base64
import sqlite3
import win32crypt
from Crypto.Cipher import AES
import shutil
from datetime import timezone, datetime, timedelta

在直接進(jìn)入提取 chrome密碼之前,我們需要定義一些有用的函數(shù)來(lái)幫助我們?cè)谥骱瘮?shù)中。

def get_chrome_datetime(chromedate):
    """從chrome格式的datetime返回一個(gè)`datetime.datetime`對(duì)象
因?yàn)?chromedate'的格式是1601年1月以來(lái)的微秒數(shù)"""
    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)

    # 從Base64解碼加密密鑰
    key = base64.b64decode(local_state["os_crypt"]["encrypted_key"])
    # 刪除 DPAPI str
    key = key[5:]
    # 返回最初加密的解密密鑰
    # 使用從當(dāng)前用戶的登錄憑據(jù)派生的會(huì)話密鑰
    # 官方文檔doc: http://timgolden.me.uk/pywin32-docs/win32crypt.html
    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 ""
  • get_chrome_datetime()函數(shù)負(fù)責(zé)將 chrome 日期格式轉(zhuǎn)換為人類可讀的日期時(shí)間格式。
  • get_encryption_key()函數(shù)提取并解碼用于加密密碼的AES密鑰,這"%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Local State"作為 JSON 文件存儲(chǔ)在路徑中
  • decrypt_password() 將加密密碼和 AES 密鑰作為參數(shù),并返回密碼的解密版本。

下面是main主要功能:

def main():
    # 獲取AES密鑰
    key = get_encryption_key()
    # 本地sqlite Chrome數(shù)據(jù)庫(kù)路徑
    db_path = os.path.join(os.environ["USERPROFILE"], "AppData", "Local","Google", "Chrome", "User Data", "default", "Login Data")
    # 將文件復(fù)制到其他位置
    # 因?yàn)槿绻鹀hrome當(dāng)前正在運(yùn)行,數(shù)據(jù)庫(kù)將被鎖定
    filename = "ChromeData.db"
    shutil.copyfile(db_path, filename)
    # 連接數(shù)據(jù)庫(kù)
    db = sqlite3.connect(filename)
    cursor = db.cursor()
    # 登錄表中有我們需要的數(shù)據(jù)
    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:
        # 嘗試刪除復(fù)制的db文件
        os.remove(filename)
    except:
        pass

首先,我們使用之前定義的get_encryption_key()函數(shù)獲取加密密鑰,然后我們將 sqlite 數(shù)據(jù)庫(kù)(位于"%USERPROFILE%\AppData\Local\Google\Chrome\User Data\default\Login Data"保存密碼的位置)復(fù)制到當(dāng)前目錄并連接到它,這是因?yàn)樵紨?shù)據(jù)庫(kù)文件將被鎖定Chrome 當(dāng)前正在運(yùn)行。

之后,我們對(duì)登錄表進(jìn)行選擇查詢并遍歷所有登錄行,我們還解密每個(gè)密碼date_created并將date_last_used日期時(shí)間重新格式化為更易于閱讀的格式。

最后,我們打印憑據(jù)并從當(dāng)前目錄中刪除數(shù)據(jù)庫(kù)副本。

讓我們調(diào)用主函數(shù),完美提取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返回一個(gè)`datetime.datetime`對(duì)象
因?yàn)?chromedate'的格式是1601年1月以來(lái)的微秒數(shù)"""
    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)

    cursor.close()
    db.close()
    try:
        # try to remove the copied db file
        os.remove(filename)
    except:
        pass


if __name__ == "__main__":
    main()

以上就是教你用Python提取Chrome瀏覽器保存的密碼的詳細(xì)內(nèi)容,更多關(guān)于Python提取Chrome瀏覽器保存的密碼的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • python中多個(gè)裝飾器的調(diào)用順序詳解

    python中多個(gè)裝飾器的調(diào)用順序詳解

    這篇文章主要給大家介紹了關(guān)于python中多個(gè)裝飾器的調(diào)用順序,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Python具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • Python3導(dǎo)入自定義模塊的三種方法詳解

    Python3導(dǎo)入自定義模塊的三種方法詳解

    這篇文章主要給大家介紹了關(guān)于Python3導(dǎo)入自定義模塊的三種方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2018-04-04
  • Python學(xué)習(xí)筆記之解析json的方法分析

    Python學(xué)習(xí)筆記之解析json的方法分析

    這篇文章主要介紹了Python解析json的方法,結(jié)合實(shí)例形式分析了常見(jiàn)的Python解析與轉(zhuǎn)換json格式數(shù)據(jù)相關(guān)操作技巧,需要的朋友可以參考下
    2017-04-04
  • 基于Python預(yù)測(cè)一下世界杯最后贏家

    基于Python預(yù)測(cè)一下世界杯最后贏家

    四年一度的世界杯已經(jīng)開(kāi)始了,對(duì)于不少熱愛(ài)足球運(yùn)動(dòng)的球迷來(lái)說(shuō),這可是十分難得的盛宴。今天小編就通過(guò)Python數(shù)據(jù)分析以及機(jī)器學(xué)習(xí)等方式來(lái)預(yù)測(cè)一下誰(shuí)能獲得最后的冠軍,感興趣的可以了解一下
    2022-11-11
  • Anaconda2下實(shí)現(xiàn)Python2.7和Python3.5的共存方法

    Anaconda2下實(shí)現(xiàn)Python2.7和Python3.5的共存方法

    今天小編就為大家分享一篇Anaconda2下實(shí)現(xiàn)Python2.7和Python3.5的共存方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-06-06
  • 對(duì)Python中l(wèi)ist的倒序索引和切片實(shí)例講解

    對(duì)Python中l(wèi)ist的倒序索引和切片實(shí)例講解

    今天小編就為大家分享一篇對(duì)Python中l(wèi)ist的倒序索引和切片實(shí)例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-11-11
  • Python如何實(shí)現(xiàn)macOS系統(tǒng)代理的設(shè)置

    Python如何實(shí)現(xiàn)macOS系統(tǒng)代理的設(shè)置

    這篇文章主要為大家詳細(xì)介紹了Python如何實(shí)現(xiàn)macOS系統(tǒng)代理的設(shè)置,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2025-01-01
  • Matlab求解數(shù)組中的最大值及它所在的具體位置

    Matlab求解數(shù)組中的最大值及它所在的具體位置

    這篇文章主要介紹了Matlab求解數(shù)組中的最大值及它所在的具體位置,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-04-04
  • 淺談Python數(shù)據(jù)類型之間的轉(zhuǎn)換

    淺談Python數(shù)據(jù)類型之間的轉(zhuǎn)換

    下面小編就為大家?guī)?lái)一篇淺談Python數(shù)據(jù)類型之間的轉(zhuǎn)換。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-06-06
  • python抓取京東商城手機(jī)列表url實(shí)例代碼

    python抓取京東商城手機(jī)列表url實(shí)例代碼

    python抓取京東商城手機(jī)列表url實(shí)例分享,大家參考使用吧
    2013-12-12

最新評(píng)論

崇明县| 泽库县| 丽江市| 廉江市| 富平县| 万年县| 大冶市| 扶沟县| 涟源市| 漯河市| 新巴尔虎右旗| 隆子县| 理塘县| 集贤县| 东乡| 钦州市| 屏南县| 隆昌县| 铁岭县| 云梦县| 广宗县| 茂名市| 越西县| 农安县| 会理县| 玉门市| 玉田县| 萍乡市| 霞浦县| 扶沟县| 东安县| 利辛县| 繁昌县| 沁阳市| 胶州市| 蓝田县| 富民县| 济南市| 赤城县| 隆尧县| 泾川县|