Codebase list pysmb / ff739da
Backport changes to RC4-encrypted session key generation from python3 to python2. Michael Teo 3 years ago
2 changed file(s) with 14 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
401401
402402 if self.is_signing_active:
403403 self.log.info("SMB signing activated. All SMB messages will be signed.")
404 self.signing_session_key = (session_key + '\0'*16)[:16]
404 self.signing_session_key = session_key
405 if self.log.isEnabledFor(logging.DEBUG):
406 self.log.info("SMB signing key is %s", binascii.hexlify(self.signing_session_key))
407
405408 if self.capabilities & CAP_EXTENDED_SECURITY:
406409 self.signing_challenge_response = None
407410 else:
00
1 import types, hmac, binascii, struct, random
1 import types, hmac, binascii, struct, random, string
2 from Crypto.Cipher import ARC4
23 from utils.pyDes import des
34
45 try:
8081 return s
8182
8283
83 def generateAuthenticateMessage(challenge_flags, nt_response, lm_response, session_key, user, domain = 'WORKGROUP', workstation = 'LOCALHOST'):
84 def generateAuthenticateMessage(challenge_flags, nt_response, lm_response, request_session_key, user, domain = 'WORKGROUP', workstation = 'LOCALHOST'):
8485 """
8586 References:
8687 ===========
8889 """
8990 FORMAT = '<8sIHHIHHIHHIHHIHHIHHII'
9091 FORMAT_SIZE = struct.calcsize(FORMAT)
92
93 # [MS-NLMP]: 3.1.5.1.2
94 # http://grutz.jingojango.net/exploits/davenport-ntlm.html
95 session_key = request_session_key
96 if challenge_flags & NTLM_NegotiateKeyExchange:
97 cipher = ARC4.new(request_session_key)
98 session_key = cipher.encrypt("".join([ random.choice(string.digits+string.ascii_letters) for _ in range(16) ]).encode('ascii'))
9199
92100 lm_response_length = len(lm_response)
93101 lm_response_offset = FORMAT_SIZE