python 구글 브라우저에 저장된 비밀번호 얻기
# -*- 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)
이상은python이 구글 브라우저에 저장된 비밀번호를 얻는 상세한 내용입니다. 더 많은python이 브라우저 비밀번호를 얻는 것에 대한 자료는 저희 다른 관련 글에 주목하세요!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
로마 숫자를 정수로 또는 그 반대로 변환그 중 하나는 로마 숫자를 정수로 변환하는 함수를 만드는 것이었고 두 번째는 그 반대를 수행하는 함수를 만드는 것이었습니다. 문자만 포함합니다'I', 'V', 'X', 'L', 'C', 'D', 'M' ; 문자열이 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.