Skip to content

Commit 9cc84c2

Browse files
committed
ntml encoding vuln fixes
1 parent 2d7330f commit 9cc84c2

8 files changed

Lines changed: 57 additions & 1 deletion

File tree

CHANGES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Changelog for hydra
22
-------------------
33

44
Release 9.8-dev
5-
* security fixes:
5+
* security fixes (some reported by Elpe Pinillo and TristanInSec):
66
- hydra.restore deserialization: validate ownership, clamp length/count/
77
offset fields before driving malloc and loop bounds
88
- parent IPC: NUL-terminate after read_safe to stop strcpy past the stack
@@ -46,6 +46,7 @@ Release 9.8-dev
4646
rather than literal interpolation (/630)
4747
- hydra-wizard.sh: build a properly-quoted argv array
4848
- xhydra: refuse SMB2 workgroup containing '}'
49+
- NTLM encoding vulnerabilties
4950
- SVN URLBRANCH NUL-termination + 255-byte miscptr cap;
5051
CVS encryption-table OOB-read clamp; IMAP DIGEST-MD5
5152
prefix + capability accumulator; SIP external_ip_addr

hydra-http-proxy-urlenum.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ int32_t start_http_proxy_urlenum(int32_t s, char *ip, int32_t port, unsigned cha
158158
// Send response
159159
buildAuthResponse((tSmbNtlmAuthChallenge *)buf1, (tSmbNtlmAuthResponse *)buf2, 0, mlogin, mpass, NULL, NULL);
160160
to64frombits(buf1, buf2, SmbLength((tSmbNtlmAuthResponse *)buf2));
161+
/* The Type-3 base64 response embeds a server-controlled domain string
162+
* and can exceed `buffer` for a malicious server. Refuse rather than
163+
* overflow. */
164+
if (strlen((char *)buf1) + strlen(url) + strlen(host) + strlen(header) + 128 >= sizeof(buffer)) {
165+
hydra_report(stderr, "[ERROR] HTTP-PROXY-URLENUM NTLM AUTH: oversized response\n");
166+
return 3;
167+
}
161168
sprintf(buffer,
162169
"GET %s HTTP/1.0\r\n%sProxy-Authorization: NTLM %s\r\nUser-Agent: "
163170
"Mozilla/4.0 (Hydra)\r\nProxy-Connection: keep-alive\r\n%s\r\n",

hydra-http-proxy.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ int32_t start_http_proxy(int32_t s, char *ip, int32_t port, unsigned char option
166166
// Send response
167167
buildAuthResponse((tSmbNtlmAuthChallenge *)buf1, (tSmbNtlmAuthResponse *)buf2, 0, login, pass, NULL, NULL);
168168
to64frombits(buf1, buf2, SmbLength((tSmbNtlmAuthResponse *)buf2));
169+
/* The Type-3 base64 response embeds a server-controlled domain string
170+
* and could exceed `buffer` for a malicious server. Refuse rather than
171+
* overflow. */
172+
if (strlen((char *)buf1) + strlen(url) + strlen(host) + strlen(header) + 128 >= sizeof(buffer)) {
173+
hydra_report(stderr, "[ERROR] HTTP-PROXY NTLM AUTH: oversized response\n");
174+
return 3;
175+
}
169176
sprintf(buffer,
170177
"GET %s HTTP/1.0\r\n%sProxy-Authorization: NTLM %s\r\nUser-Agent: "
171178
"Mozilla/4.0 (Hydra)\r\nProxy-Connection: keep-alive\r\n%s\r\n",

hydra-http.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,23 @@ int32_t start_http(int32_t s, char *ip, int32_t port, unsigned char options, cha
185185
buildAuthResponse((tSmbNtlmAuthChallenge *)buf1, (tSmbNtlmAuthResponse *)buf2, 0, login, pass, NULL, NULL);
186186
to64frombits(buf1, buf2, SmbLength((tSmbNtlmAuthResponse *)buf2));
187187

188+
/* The Type-3 base64 response embeds a server-controlled domain string and
189+
* can grow well past the initial buffer_size for a malicious server. Grow
190+
* the buffer to hold it (plus operator-supplied bits) before sprintf. */
191+
{
192+
size_t needed = strlen((char *)buf1) + strlen(header) + 1024;
193+
if (needed > (size_t)buffer_size) {
194+
char *new_buffer = realloc(buffer, needed);
195+
if (new_buffer == NULL) {
196+
free(buffer);
197+
free(header);
198+
return 3;
199+
}
200+
buffer = new_buffer;
201+
buffer_size = needed;
202+
}
203+
}
204+
188205
// create the auth response
189206
if (use_proxy == 1 && proxy_authentication[selected_proxy] != NULL)
190207
sprintf(buffer,

hydra-imap.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ int32_t start_imap(int32_t s, char *ip, int32_t port, unsigned char options, cha
368368
buildAuthResponse((tSmbNtlmAuthChallenge *)buf1, (tSmbNtlmAuthResponse *)buf2, 0, login, pass, NULL, NULL);
369369
to64frombits(buf1, buf2, SmbLength((tSmbNtlmAuthResponse *)buf2));
370370

371+
/* The Type-3 base64 response embeds a server-controlled domain string and
372+
* can exceed `buffer` for a malicious server. Refuse rather than overflow. */
373+
if (strlen((char *)buf1) + 2 >= sizeof(buffer)) {
374+
hydra_report(stderr, "[ERROR] IMAP NTLM AUTH: oversized response\n");
375+
return 3;
376+
}
371377
sprintf(buffer, "%s\r\n", buf1);
372378
} break;
373379
default:

hydra-nntp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ int32_t start_nntp(int32_t s, char *ip, int32_t port, unsigned char options, cha
230230

231231
buildAuthResponse((tSmbNtlmAuthChallenge *)buf1, (tSmbNtlmAuthResponse *)buf2, 0, login, pass, NULL, NULL);
232232
to64frombits(buf1, buf2, SmbLength((tSmbNtlmAuthResponse *)buf2));
233+
/* The Type-3 base64 response embeds a server-controlled domain string and
234+
* can exceed `buffer` for a malicious server. Refuse rather than overflow. */
235+
if (strlen((char *)buf1) + 2 >= sizeof(buffer)) {
236+
hydra_report(stderr, "[ERROR] NNTP NTLM AUTH: oversized response\n");
237+
return 3;
238+
}
233239
sprintf(buffer, "%s\r\n", (char *)buf1);
234240
} break;
235241

hydra-pop3.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,12 @@ int32_t start_pop3(int32_t s, char *ip, int32_t port, unsigned char options, cha
375375
buildAuthResponse((tSmbNtlmAuthChallenge *)buf1, (tSmbNtlmAuthResponse *)buf2, 0, login, pass, NULL, NULL);
376376
to64frombits(buf1, buf2, SmbLength((tSmbNtlmAuthResponse *)buf2));
377377

378+
/* The Type-3 base64 response embeds a server-controlled domain string and
379+
* can exceed `buffer` for a malicious server. Refuse rather than overflow. */
380+
if (strlen((char *)buf1) + 2 >= sizeof(buffer)) {
381+
hydra_report(stderr, "[ERROR] POP3 NTLM AUTH: oversized response\n");
382+
return 3;
383+
}
378384
sprintf(buffer, "%s\r\n", buf1);
379385
} break;
380386
default:

hydra-smtp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ int32_t start_smtp(int32_t s, char *ip, int32_t port, unsigned char options, cha
190190

191191
buildAuthResponse((tSmbNtlmAuthChallenge *)buf1, (tSmbNtlmAuthResponse *)buf2, 0, login, pass, NULL, NULL);
192192
to64frombits(buf1, buf2, SmbLength((tSmbNtlmAuthResponse *)buf2));
193+
/* The Type-3 base64 response embeds a server-controlled domain string and
194+
* can exceed `buffer` for a malicious server. Refuse rather than overflow. */
195+
if (strlen((char *)buf1) + 2 >= sizeof(buffer)) {
196+
hydra_report(stderr, "[ERROR] SMTP NTLM AUTH: oversized response\n");
197+
return 3;
198+
}
193199
sprintf(buffer, "%s\r\n", buf1);
194200
} break;
195201

0 commit comments

Comments
 (0)