MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / generateAuthenticateMessage

Function generateAuthenticateMessage

pager_lib/smb/ntlm.py:85–136  ·  view source on GitHub ↗

References: =========== - [MS-NLMP]: 2.2.1.3

(challenge_flags, nt_response, lm_response, request_session_key, user, domain = 'WORKGROUP', workstation = 'LOCALHOST')

Source from the content-addressed store, hash-verified

83
84
85def generateAuthenticateMessage(challenge_flags, nt_response, lm_response, request_session_key, user, domain = 'WORKGROUP', workstation = 'LOCALHOST'):
86 """
87 References:
88 ===========
89 - [MS-NLMP]: 2.2.1.3
90 """
91 FORMAT = '<8sIHHIHHIHHIHHIHHIHHII'
92 FORMAT_SIZE = struct.calcsize(FORMAT)
93
94 # [MS-NLMP]: 3.1.5.1.2
95 # http://grutz.jingojango.net/exploits/davenport-ntlm.html
96 session_key = session_signing_key = request_session_key
97 if challenge_flags & NTLM_NegotiateKeyExchange:
98 session_signing_key = "".join([ random.choice(string.digits+string.ascii_letters) for _ in range(16) ]).encode('ascii')
99 session_key = RC4_encrypt(request_session_key, session_signing_key)
100
101 lm_response_length = len(lm_response)
102 lm_response_offset = FORMAT_SIZE
103 nt_response_length = len(nt_response)
104 nt_response_offset = lm_response_offset + lm_response_length
105 domain_unicode = domain.encode('UTF-16LE')
106 domain_length = len(domain_unicode)
107 domain_offset = nt_response_offset + nt_response_length
108
109 padding = b''
110 if domain_offset % 2 != 0:
111 padding = b'\0'
112 domain_offset += 1
113
114 user_unicode = user.encode('UTF-16LE')
115 user_length = len(user_unicode)
116 user_offset = domain_offset + domain_length
117 workstation_unicode = workstation.encode('UTF-16LE')
118 workstation_length = len(workstation_unicode)
119 workstation_offset = user_offset + user_length
120 session_key_length = len(session_key)
121 session_key_offset = workstation_offset + workstation_length
122
123 auth_flags = challenge_flags
124 auth_flags &= ~NTLM_NegotiateVersion
125
126 s = struct.pack(FORMAT,
127 b'NTLMSSP\0', 0x03,
128 lm_response_length, lm_response_length, lm_response_offset,
129 nt_response_length, nt_response_length, nt_response_offset,
130 domain_length, domain_length, domain_offset,
131 user_length, user_length, user_offset,
132 workstation_length, workstation_length, workstation_offset,
133 session_key_length, session_key_length, session_key_offset,
134 auth_flags)
135
136 return s + lm_response + nt_response + padding + domain_unicode + user_unicode + workstation_unicode + session_key, session_signing_key
137
138
139def decodeChallengeMessage(ntlm_data):

Callers

nothing calls this directly

Calls 3

rangeFunction · 0.85
RC4_encryptFunction · 0.85
encodeMethod · 0.45

Tested by

no test coverage detected