@@ -150,7 +150,6 @@ def vnc_from_registry(self, remote_ops):
150150 value = self .reg_query_value (remote_ops , path , password ).encode ().rstrip (b"\x00 " ).decode ()
151151 value = unhexlify (value )
152152 except Exception as e :
153- print (e )
154153 if "ERROR_FILE_NOT_FOUND" not in str (e ):
155154 self .context .log .debug (f"Error while RegQueryValue { path } \\ { user } : { e } " )
156155 continue
@@ -169,7 +168,7 @@ def vnc_from_registry(self, remote_ops):
169168 def split_len (self , seq , length ):
170169 return [seq [i :i + length ] for i in range (0 , len (seq ), length )]
171170
172- def recover_vncpassword (self , cipher ):
171+ def recover_vncpassword (self , cipher : bytes ):
173172 encpasswd = cipher .hex ()
174173 pwd = None
175174 if encpasswd :
@@ -189,11 +188,13 @@ def recover_vncpassword(self, cipher):
189188 pwd = self .decrypt_password (cipher )
190189 return pwd
191190
192- def decrypt_password (self , password ):
191+ def decrypt_password (self , password : bytes ):
192+ length = len (password )
193193 try :
194- password = (password + b"\x00 " * 8 )[:8 ]
194+ if length <= 16 :
195+ password += b"\x00 " * (16 - length )
195196 cipher = DES .new (key = self .vnc_decryption_key , mode = DES .MODE_ECB )
196- return cipher .decrypt (password )
197+ return cipher .decrypt (password )[: length ]
197198 except Exception as ex :
198199 self .context .log .debug (f"Error while decrypting VNC password { password } : { ex } " )
199200
@@ -213,5 +214,5 @@ def vnc_from_filesystem(self, dploot_conn):
213214 passwds_encrypted = re .findall (regex , file_content )
214215 for passwd_encrypted in passwds_encrypted :
215216 passwd_encrypted = passwd_encrypted .split (b"=" )[- 1 ]
216- password = self .decrypt_password (unhexlify (passwd_encrypted ))
217+ password = self .recover_vncpassword (unhexlify (passwd_encrypted ))[: 8 ]
217218 self .context .log .highlight (f"[{ vnc_name } ] Password: { password .decode ('latin-1' )} " )
0 commit comments