@@ -58,10 +58,10 @@ def on_login(self, context, connection):
5858 for attr in xml_section :
5959 props = attr .attrib
6060
61- if props . has_key ( 'cpassword' ) :
61+ if 'cpassword' in props :
6262
6363 for user_tag in ['userName' , 'accountName' , 'runAs' , 'username' ]:
64- if props . has_key ( user_tag ) :
64+ if user_tag in props :
6565 username = props [user_tag ]
6666
6767 password = self .decrypt_cpassword (props ['cpassword' ])
@@ -77,16 +77,12 @@ def on_login(self, context, connection):
7777
7878 def decrypt_cpassword (self , cpassword ):
7979
80- #Stolen from https ://github.com/leonteale/pentestpackage/blob/master/Gpprefdecrypt.py
80+ #Stolen from hhttps ://gist. github.com/andreafortuna/4d32100ae03abead52e8f3f61ab70385
8181
8282 # From MSDN: http://msdn.microsoft.com/en-us/library/2c15cbf0-f086-4c74-8b70-1f2fa45dd4be%28v=PROT.13%29#endNote2
8383 key = unhexlify ('4e9906e8fcb66cc9faf49310620ffee8f496e806cc057990209b09a433b66c1b' )
84- try :
85- password = b64decode (cpassword )
86- except TypeError :
87- cpassword += "=" * ((4 - len (cpassword ) % 4 ) % 4 )
88- password = b64decode (cpassword )
89-
90- decypted = AES .new (key , AES .MODE_CBC , "\x00 " * 16 ).decrypt (password )
91-
92- return decypted [:- ord (decypted [- 1 ])].decode ('utf16' )
84+ cpassword += "=" * ((4 - len (cpassword ) % 4 ) % 4 )
85+ password = b64decode (cpassword )
86+ IV = "\x00 " * 16
87+ decypted = AES .new (key , AES .MODE_CBC , IV .encode ("utf8" )).decrypt (password )
88+ return decypted .decode ()
0 commit comments