118 lines
5.4 KiB
Plaintext
118 lines
5.4 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"ename": "ModuleNotFoundError",
|
|
"evalue": "No module named 'Cryptodome'",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
|
"\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
|
|
"Cell \u001b[1;32mIn[1], line 8\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mpandas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mpd\u001b[39;00m\n\u001b[0;32m 7\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mwin32crypt\u001b[39;00m \u001b[38;5;66;03m# Solo en Windows\u001b[39;00m\n\u001b[1;32m----> 8\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01mCryptodome\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mCipher\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m AES\n\u001b[0;32m 10\u001b[0m \u001b[38;5;66;03m# 📌 Rutas de Chrome en Windows\u001b[39;00m\n\u001b[0;32m 11\u001b[0m LOCAL_STATE_PATH \u001b[38;5;241m=\u001b[39m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mexpanduser(\n\u001b[0;32m 12\u001b[0m \u001b[38;5;124mr\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m~\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124mAppData\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124mLocal\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124mGoogle\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124mChrome\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124mUser Data\u001b[39m\u001b[38;5;124m\\\u001b[39m\u001b[38;5;124mLocal State\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 13\u001b[0m )\n",
|
|
"\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'Cryptodome'"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import os\n",
|
|
"import json\n",
|
|
"import base64\n",
|
|
"import sqlite3\n",
|
|
"import shutil\n",
|
|
"import pandas as pd\n",
|
|
"import win32crypt # Solo en Windows\n",
|
|
"from Cryptodome.Cipher import AES\n",
|
|
"\n",
|
|
"# 📌 Rutas de Chrome en Windows\n",
|
|
"LOCAL_STATE_PATH = os.path.expanduser(\n",
|
|
" r\"~\\AppData\\Local\\Google\\Chrome\\User Data\\Local State\"\n",
|
|
")\n",
|
|
"COOKIES_DB_PATH = os.path.expanduser(\n",
|
|
" r\"~\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Cookies\"\n",
|
|
")\n",
|
|
"\n",
|
|
"# 📌 Función para obtener la clave de cifrado de Chrome\n",
|
|
"def get_encryption_key():\n",
|
|
" with open(LOCAL_STATE_PATH, \"r\", encoding=\"utf-8\") as f:\n",
|
|
" local_state = json.load(f)\n",
|
|
"\n",
|
|
" encrypted_key = base64.b64decode(local_state[\"os_crypt\"][\"encrypted_key\"])\n",
|
|
" encrypted_key = encrypted_key[5:] # Eliminar el prefijo 'DPAPI'\n",
|
|
"\n",
|
|
" # Desencriptar clave usando Windows API\n",
|
|
" return win32crypt.CryptUnprotectData(encrypted_key, None, None, None, 0)[1]\n",
|
|
"\n",
|
|
"# 📌 Función para descifrar cookies\n",
|
|
"def decrypt_cookie(encrypted_value, key):\n",
|
|
" try:\n",
|
|
" iv = encrypted_value[3:15] # Extraer IV (Initialization Vector)\n",
|
|
" encrypted_value = encrypted_value[15:] # Extraer la parte cifrada\n",
|
|
" cipher = AES.new(key, AES.MODE_GCM, iv)\n",
|
|
" decrypted_value = cipher.decrypt(encrypted_value).decode(\"utf-8\")\n",
|
|
" return decrypted_value\n",
|
|
" except:\n",
|
|
" return None\n",
|
|
"\n",
|
|
"# 📌 Extraer cookies de la base de datos SQLite y exportarlas en un DataFrame\n",
|
|
"def get_cookies():\n",
|
|
" key = get_encryption_key()\n",
|
|
" \n",
|
|
" # Copiar la BBDD para evitar bloqueos si Chrome está abierto\n",
|
|
" temp_db = \"temp_cookies.db\"\n",
|
|
" shutil.copy2(COOKIES_DB_PATH, temp_db)\n",
|
|
"\n",
|
|
" conn = sqlite3.connect(temp_db)\n",
|
|
" cursor = conn.cursor()\n",
|
|
"\n",
|
|
" # Extraer cookies de la base de datos\n",
|
|
" cursor.execute(\"SELECT host_key, name, path, expires_utc, encrypted_value FROM cookies\")\n",
|
|
" cookies_data = []\n",
|
|
"\n",
|
|
" for host, name, path, expires, encrypted_value in cursor.fetchall():\n",
|
|
" decrypted_value = decrypt_cookie(encrypted_value, key)\n",
|
|
" if decrypted_value:\n",
|
|
" cookies_data.append([host, name, path, expires, decrypted_value])\n",
|
|
"\n",
|
|
" conn.close()\n",
|
|
" os.remove(temp_db) # Eliminar la copia temporal de la BBDD\n",
|
|
"\n",
|
|
" # Convertir a DataFrame\n",
|
|
" df_cookies = pd.DataFrame(\n",
|
|
" cookies_data, columns=[\"Host\", \"Name\", \"Path\", \"Expires\", \"Value\"]\n",
|
|
" )\n",
|
|
"\n",
|
|
" return df_cookies\n",
|
|
"\n",
|
|
"# 📌 Ejecutar el script y mostrar el DataFrame\n",
|
|
"df = get_cookies()\n",
|
|
"display(df)\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "data",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.16"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|