@@ -60,29 +60,29 @@ def uint_to_int(b):
6060def try_read_fp (fp , bytes_to_read ):
6161 out = fp .read (bytes_to_read )
6262 if len (out ) != bytes_to_read :
63- print ("Error reading out of bounds of file, exiting." )
63+ print ("Error reading out of bounds of file, exiting." , file = sys . stderr )
6464 sys .exit (1 )
6565
6666 return out
6767
6868def parse_FVEK (fvek_data ):
69- print ("\n Parsing FVEK..." )
69+ print ("\n Parsing FVEK..." , file = sys . stderr )
7070 nonce = fvek_data [:12 ]
7171 mac = fvek_data [12 :28 ]
7272 enc_data = fvek_data [28 :]
7373
74- print ("Mac:" , mac .hex ())
75- print ("Nonce:" , nonce .hex ())
76- print ("Encrypted data:" , enc_data .hex ())
74+ print ("Mac:" , mac .hex (), file = sys . stderr )
75+ print ("Nonce:" , nonce .hex (), file = sys . stderr )
76+ print ("Encrypted data:" , enc_data .hex (), file = sys . stderr )
7777
7878 return nonce , mac , enc_data
7979
8080def parse_stretch_key (data ):
81- print ("\n Parsing stretch key..." )
81+ print ("\n Parsing stretch key..." , file = sys . stderr )
8282 encryption_method = hex (uint_to_int (data [0 :4 ]))
8383 salt = data [4 :20 ]
84- print ("Encryption method:" , encryption_method )
85- print ("Salt:" , salt .hex ())
84+ print ("Encryption method:" , encryption_method , file = sys . stderr )
85+ print ("Salt:" , salt .hex (), file = sys . stderr )
8686 current_pos = 0
8787 aes_ccm_data = data [20 :]
8888 current_pos , data , value_type = parse_fve_metadata_entry (current_pos , aes_ccm_data )
@@ -91,7 +91,7 @@ def parse_stretch_key(data):
9191 return salt , nonce , mac , enc_data
9292
9393def generate_hash (salt , nonce , mac , enc_data , protection_type ):
94- print ("\n Found hash!" )
94+ print ("\n Found hash!" , file = sys . stderr )
9595 if protection_type == 0x2000 :
9696 versions = BITLOCKER_PASSWORD_HASH_VERSIONS
9797 if protection_type == 0x800 :
@@ -102,29 +102,29 @@ def generate_hash(salt, nonce, mac, enc_data, protection_type):
102102 HASHES .append (generated_hash )
103103
104104def parse_aes_ccm_encrypted_key (data ):
105- print ("Parsing AES CCM key..." )
105+ print ("Parsing AES CCM key..." , file = sys . stderr )
106106 nonce , mac , enc_data = parse_FVEK (data )
107107 return nonce , mac , enc_data
108108
109109def parse_description (data ):
110- print ("\n Parsing description..." )
111- print (f"Info: { data .decode ('utf-16' )} " )
110+ print ("\n Parsing description..." , file = sys . stderr )
111+ print (f"Info: { data .decode ('utf-16' )} " , file = sys . stderr )
112112 return
113113
114114def parse_volume_header_block (data ):
115- print ("\n Parsing volume header block..." )
115+ print ("\n Parsing volume header block..." , file = sys . stderr )
116116 block_offset = uint_to_int (data [0 :8 ])
117117 block_size = uint_to_int (data [8 :16 ])
118- print (f"Block offset: { hex (block_offset )} " )
119- print (f"Block size: { block_size } " )
118+ print (f"Block offset: { hex (block_offset )} " , file = sys . stderr )
119+ print (f"Block size: { block_size } " , file = sys . stderr )
120120
121121def parse_VMK (VMK_data ):
122- print ("\n Parsing VMK..." )
122+ print ("\n Parsing VMK..." , file = sys . stderr )
123123 guid = hex_to_guid (VMK_data [:16 ].hex ())
124124 protection_type = uint_to_int (VMK_data [26 :28 ])
125125 properties = VMK_data [28 :]
126- print ("GUID:" , guid )
127- print (f"Protection type: { hex (protection_type )} = { PROTECTION_TYPES .get (protection_type )} " )
126+ print ("GUID:" , guid , file = sys . stderr )
127+ print (f"Protection type: { hex (protection_type )} = { PROTECTION_TYPES .get (protection_type )} " , file = sys . stderr )
128128
129129 # only try parse properties if correct protection type
130130 protection_type_str = PROTECTION_TYPES .get (protection_type )
@@ -143,7 +143,7 @@ def parse_VMK(VMK_data):
143143 return
144144
145145def parse_fve_metadata_block (block ):
146- print ('\n Parsing FVE block...' )
146+ print ('\n Parsing FVE block...' , file = sys . stderr )
147147 metadata_size = len (block )
148148
149149 entry_size = uint_to_int (block [112 :114 ])
@@ -166,16 +166,16 @@ def parse_fve_metadata_block(block):
166166 return
167167
168168def parse_fve_metadata_entry (current_pos , block ):
169- print ("\n Parsing FVE metadata entry..." )
169+ print ("\n Parsing FVE metadata entry..." , file = sys . stderr )
170170 entry_size = uint_to_int (block [0 :2 ])
171171 entry_type = uint_to_int (block [2 :4 ])
172172 value_type = uint_to_int (block [4 :6 ])
173173 version = hex (uint_to_int (block [6 :8 ]))
174174 data = block [8 :entry_size ]
175175
176- print (f"Entry size: { entry_size } " )
177- print (f"Entry type: { hex (entry_type )} = { FVE_ENTRY_TYPES .get (entry_type )} " )
178- print (f"Value type: { hex (value_type )} = { FVE_VALUE_TYPES .get (value_type )} " )
176+ print (f"Entry size: { entry_size } " , file = sys . stderr )
177+ print (f"Entry type: { hex (entry_type )} = { FVE_ENTRY_TYPES .get (entry_type )} " , file = sys . stderr )
178+ print (f"Value type: { hex (value_type )} = { FVE_VALUE_TYPES .get (value_type )} " , file = sys . stderr )
179179
180180 current_pos = current_pos + entry_size
181181
@@ -189,15 +189,15 @@ def parse_fve_metadata_header_data(header_data):
189189 return metadata_size
190190
191191def parse_fve_metadata_header (block ):
192- print ("\n Parsing FVE metadata header..." )
192+ print ("\n Parsing FVE metadata header..." , file = sys . stderr )
193193 metadata_size = uint_to_int (block [0 :4 ])
194194 volume_guid = hex_to_guid (block [16 :32 ].hex ())
195195 nonce_counter = uint_to_int (block [32 :36 ])
196196 encryption_method = hex (uint_to_int (block [36 :40 ]))
197197
198- print ("Metadata size:" , metadata_size )
199- print ("Volume GUID:" , volume_guid )
200- print ("Encryption method:" , encryption_method )
198+ print ("Metadata size:" , metadata_size , file = sys . stderr )
199+ print ("Volume GUID:" , volume_guid , file = sys . stderr )
200+ print ("Encryption method:" , encryption_method , file = sys . stderr )
201201
202202 return metadata_size
203203
@@ -222,9 +222,9 @@ def main():
222222
223223 header = try_read_fp (fp , 8 )
224224 if header .decode ('latin-1' ) not in [BITLOCKER_SIGNATURE , BITLOCKER_TO_GO_SIGNATURE ]:
225- print ("[!] Supplied image path is not a BitLocker partition. Try specifiying the offset of the BitLocker partition with -o" )
225+ print ("[!] Supplied image path is not a BitLocker partition. Try specifiying the offset of the BitLocker partition with -o" , file = sys . stderr )
226226 exit ()
227- print (f'[+] BitLocker signature found: { header .decode ()} ' )
227+ print (f'[+] BitLocker signature found: { header .decode ()} ' , file = sys . stderr )
228228 sector_size = uint_to_int (try_read_fp (fp , 2 ))
229229
230230 if header .decode ('latin-1' ) == BITLOCKER_SIGNATURE :
@@ -237,13 +237,13 @@ def main():
237237 volume_guid = hex_to_guid (volume_guid .hex ())
238238 volume_guid_id = BITLOCKER_GUIDS .get (volume_guid )
239239 if volume_guid_id == None :
240- print ("[!] Volume GUID not recognised. Exiting." )
240+ print ("[!] Volume GUID not recognised. Exiting." , file = sys . stderr )
241241 sys .exit (1 )
242- print (f'[+] Identified volume GUID: { volume_guid } = { volume_guid_id } ' )
242+ print (f'[+] Identified volume GUID: { volume_guid } = { volume_guid_id } ' , file = sys . stderr )
243243
244244 # get FVE metadata block addresses
245245 FVE_metadata_offsets = [hex (uint_to_int (try_read_fp (fp , 8 )) + bitlocker_offset ) for _ in range (3 )]
246- print (f'[+] FVE metadata info found at offsets { FVE_metadata_offsets } ' )
246+ print (f'[+] FVE metadata info found at offsets { FVE_metadata_offsets } ' , file = sys . stderr )
247247
248248 # all metadata blocks should be the same
249249 for f in FVE_metadata_offsets :
@@ -259,9 +259,10 @@ def main():
259259 break
260260
261261 if HASHES == []:
262- print ("\n No hashes associated with the user password or recovery password found. Exiting..." )
262+ print ("\n No hashes associated with the user password or recovery password found. Exiting..." , file = sys . stderr )
263263 else :
264- print ("\n The following hashes were found:" )
264+ if sys .stdout .isatty ():
265+ print ("\n The following hashes were found:" )
265266 for bitlocker_hash in HASHES :
266267 print (bitlocker_hash )
267268
0 commit comments