47 #define UINTEGER64 __int64
48 #define UINT64(c) c ## Ui64
51 #define UINTEGER64 unsigned long long
52 #define UINT64(c) c ## LL
63 md_full(
"MD4", data, data_len, md);
91 timestamp_ull = (timestamp_ull +
UINT64(11644473600)) *
UINT64(10000000);
94 timestamp[0] = timestamp_ull &
UINT64(0xFF);
95 timestamp[1] = (timestamp_ull >> 8) &
UINT64(0xFF);
96 timestamp[2] = (timestamp_ull >> 16) &
UINT64(0xFF);
97 timestamp[3] = (timestamp_ull >> 24) &
UINT64(0xFF);
98 timestamp[4] = (timestamp_ull >> 32) &
UINT64(0xFF);
99 timestamp[5] = (timestamp_ull >> 40) &
UINT64(0xFF);
100 timestamp[6] = (timestamp_ull >> 48) &
UINT64(0xFF);
101 timestamp[7] = (timestamp_ull >> 56) &
UINT64(0xFF);
110 for (i = 0; i<8; i++)
123 *str = toupper(*str);
157 unsigned char *msg_buf,
int *msg_bufpos,
size_t msg_bufsize)
159 if (*msg_bufpos + length > msg_bufsize)
161 msg(
M_WARN,
"NTLM: security buffer too big for message buffer");
166 msg_buf[sb_offset] = (
unsigned char)length;
167 msg_buf[sb_offset + 2] = msg_buf[sb_offset];
168 msg_buf[sb_offset + 4] = (
unsigned char)(*msg_bufpos & 0xff);
169 msg_buf[sb_offset + 5] = (
unsigned char)((*msg_bufpos >> 8) & 0xff);
170 memcpy(&msg_buf[*msg_bufpos], data, msg_buf[sb_offset]);
171 *msg_bufpos += length;
187 buf_printf(&out,
"%s",
"TlRMTVNTUAABAAAAAgIAAA==");
205 uint8_t challenge[8];
208 uint8_t ntlmv2_response[256];
209 char userdomain_u[256];
210 char userdomain[128];
212 uint8_t ntlmv2_hmacmd5[16];
213 uint8_t *ntlmv2_blob = ntlmv2_response + 16;
214 int ntlmv2_blob_size = 0;
215 int phase3_bufpos = 0x40;
227 if (separator == NULL)
229 strncpy(username, p->
up.
username,
sizeof(username)-1);
230 username[
sizeof(username)-1] = 0;
235 strncpy(username, separator+1,
sizeof(username)-1);
236 username[
sizeof(username)-1] = 0;
238 if (
len >
sizeof(domain) - 1)
240 len =
sizeof(domain) - 1;
263 msg(
M_WARN,
"NTLM: base64 decoding of phase 2 response failed");
268 for (i = 0; i<8; i++)
270 challenge[i] = buf2[i+24];
277 strcpy(userdomain, username);
279 if (strlen(username) + strlen(domain) <
sizeof(userdomain))
281 strcat(userdomain, domain);
285 msg(
M_INFO,
"NTLM: Username or domain too long");
288 gen_hmac_md5((uint8_t *)userdomain_u, 2 * strlen(userdomain), md4_hash,
292 memset(ntlmv2_blob, 0, 128);
293 ntlmv2_blob[0x00] = 1;
294 ntlmv2_blob[0x01] = 1;
295 ntlmv2_blob[0x04] = 0;
298 ntlmv2_blob[0x18] = 0;
314 const size_t hoff = 0x14;
315 unsigned long flags = buf2[hoff] | (buf2[hoff + 1] << 8)
316 |(buf2[hoff + 2] << 16) | (buf2[hoff + 3] << 24);
317 if ((flags & 0x00800000) == 0x00800000)
319 tib_len = buf2[0x28];
320 if (tib_len + 0x1c + 16 >
sizeof(ntlmv2_response))
322 msg(
M_WARN,
"NTLM: target information buffer too long for response (len=%d)", tib_len);
328 uint8_t tib_pos = buf2[0x2c];
329 if (tib_pos + tib_len >
sizeof(buf2))
331 msg(
M_ERR,
"NTLM: phase 2 response from server too long (need %d bytes at offset %u)", tib_len, tib_pos);
335 tib_ptr = buf2 + tib_pos;
337 memcpy(&ntlmv2_blob[0x1c], tib_ptr, tib_len);
346 ntlmv2_blob[0x1c + tib_len] = 0;
349 ntlmv2_blob_size = 0x20 + tib_len;
352 memcpy(&ntlmv2_response[8], challenge, 8);
355 gen_hmac_md5(&ntlmv2_response[8], ntlmv2_blob_size + 8, ntlmv2_hash,
363 memset(phase3, 0,
sizeof(phase3));
365 strcpy((
char *)phase3,
"NTLMSSP\0");
370 phase3, &phase3_bufpos,
sizeof(phase3));
374 &phase3_bufpos,
sizeof(phase3));
381 phase3[0x10] = phase3_bufpos;
382 phase3[0x30] = phase3_bufpos;
383 phase3[0x38] = phase3_bufpos;