From: "cron2 (Code Review)" Date: Wed, 17 Jan 2024 13:32:18 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="eojHkZn5XPU="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[release/2.6]: NTLM: increase size of phase 2 response we can handle List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos Cc: openvpn-devel --eojHkZn5XPU= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#2) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/494?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: NTLM: increase size of phase 2 response we can handle ...................................................................... NTLM: increase size of phase 2 response we can handle With NTLMv2 the target information buffer can be rather large even with normal domain setups. In my test setup it was 152 bytes starting at offset 71. Overall the base64 encode phase 2 response was 300 byte long. The linked documentation has 98 bytes at offset 60. 128 byte is clearly too low. While here improve the error messaging, so that if the buffer is too small at least one can determine that in the log. Change-Id: Iefa4930cb1e8c4135056a17ceb4283fc13cc75c8 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Message-Id: <20240117094952.25938-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg28= 052.html Signed-off-by: Gert Doering --- M src/openvpn/ntlm.c M src/openvpn/proxy.c 2 files changed, 11 insertions(+), 12 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/94/494/2 diff --git a/src/openvpn/ntlm.c b/src/openvpn/ntlm.c index 2b735ec..698abfb 100644 --- a/src/openvpn/ntlm.c +++ b/src/openvpn/ntlm.c @@ -218,7 +218,7 @@ uint8_t challenge[8], ntlm_response[24]; int i, ret_val; - uint8_t ntlmv2_response[144]; + uint8_t ntlmv2_response[256]; char userdomain_u[256]; /* for uppercase unicode username and doma= in */ char userdomain[128]; /* the same as previous but ascii */ uint8_t ntlmv2_hash[MD5_DIGEST_LENGTH]; @@ -270,17 +270,15 @@ * the missing bytes will be NULL, as buf2 is known to be zeroed * when this decode happens. */ - uint8_t buf2[128]; /* decoded reply from proxy */ + uint8_t buf2[512]; /* decoded reply from proxy */ CLEAR(buf2); ret_val =3D openvpn_base64_decode(phase_2, buf2, -1); if (ret_val < 0) { + msg(M_WARN, "NTLM: base64 decoding of phase 2 response failed"); return NULL; } - /* we can be sure that phase_2 is less than 128 - * therefore buf2 needs to be (3/4 * 128) */ - /* extract the challenge from bytes 24-31 */ for (i =3D 0; i<8; i++) { @@ -300,7 +298,7 @@ } else { - msg(M_INFO, "Warning: Username or domain too long"); + msg(M_WARN, "NTLM: Username or domain too long"); } unicodize(userdomain_u, userdomain); gen_hmac_md5((uint8_t *)userdomain_u, 2 * strlen(userdomain), md4_= hash, @@ -335,9 +333,10 @@ if ((flags & 0x00800000) =3D=3D 0x00800000) { tib_len =3D buf2[0x28]; /* Get Target Information b= lock size */ - if (tib_len > 96) + if (tib_len + 0x1c + 16 > sizeof(ntlmv2_response)) { - tib_len =3D 96; + msg(M_WARN, "NTLM: target information buffer too long for = response (len=3D%d)", tib_len); + return NULL; } { @@ -345,6 +344,7 @@ uint8_t tib_pos =3D buf2[0x2c]; if (tib_pos + tib_len > sizeof(buf2)) { + msg(M_ERR, "NTLM: phase 2 response from server too lon= g (need %d bytes at offset %u)", tib_len, tib_pos); return NULL; } /* Get Target Information block pointer */ diff --git a/src/openvpn/proxy.c b/src/openvpn/proxy.c index 76e27cb..b2e8b3d 100644 --- a/src/openvpn/proxy.c +++ b/src/openvpn/proxy.c @@ -638,7 +638,6 @@ { struct gc_arena gc =3D gc_new(); char buf[512]; - char buf2[129]; char get[80]; int status; int nparms; @@ -758,7 +757,7 @@ { #if NTLM /* look for the phase 2 response */ - + char buf2[512]; while (true) { if (!recv_line(sd, buf, sizeof(buf), get_server_poll_remai= ning_time(server_poll_timeout), true, NULL, signal_received)) @@ -768,9 +767,9 @@ chomp(buf); msg(D_PROXY, "HTTP proxy returned: '%s'", buf); - openvpn_snprintf(get, sizeof get, "%%*s NTLM %%%ds", (int)= sizeof(buf2) - 1); + CLEAR(buf2); + openvpn_snprintf(get, sizeof(get), "%%*s NTLM %%%zus", siz= eof(buf2) - 1); nparms =3D sscanf(buf, get, buf2); - buf2[128] =3D 0; /* we only need the beginning - ensure it= 's null terminated. */ /* check for "Proxy-Authenticate: NTLM TlRM..." */ if (nparms =3D=3D 1) -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/494?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: release/2.6 Gerrit-Change-Id: Iefa4930cb1e8c4135056a17ceb4283fc13cc75c8 Gerrit-Change-Number: 494 Gerrit-PatchSet: 2 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --eojHkZn5XPU= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #2 to the change originally cr= eated by flichtenheld.

View Change

The following approvals got outda= ted and were removed: Code-Review+2 by cron2

NTLM: increase size of phase 2 response we can handl=
e

With NTLMv2 the target information buffer can be rather large
e= ven with normal domain setups.

In my test setup it was 152 bytes sta= rting at offset 71.
Overall the base64 encode phase 2 response was 300 b= yte long.
The linked documentation has 98 bytes at offset 60. 128 byteis clearly too low.

While here improve the error messaging, so tha= t if the buffer
is too small at least one can determine that in the log.=

Change-Id: Iefa4930cb1e8c4135056a17ceb4283fc13cc75c8
Signed-off-= by: Frank Lichtenheld <frank@...2641...>
Acked-by: Gert Doering &l= t;gert@...1296...>
Message-Id: <20240117094952.25938-1-gert@...1826...= 6...>
URL: https://www.mail-archive.com/openvpn-devel@...1768...= ge.net/msg28052.html
Signed-off-by: Gert Doering <gert@...1296...>=
---
M src/openvpn/ntlm.c
M src/openvpn/proxy.c
2 files changed= , 11 insertions(+), 12 deletions(-)

git pull ssh://gerrit.openvpn=
.net:29418/openvpn refs/changes/94/494/2
diff --git a/src/openvpn/n=
tlm.c b/src/openvpn/ntlm.c
index 2b735ec..698abfb 100644
--- a/src/openvpn/ntlm.c
+++ b/src/openvpn/nt= lm.c
@@ -218,7 +218,7 @@
uint8_t chall= enge[8], ntlm_response[24];
int i, ret_val;
=
- uint8_t nt= lmv2_response[144];
+= uint8_t ntlmv2_response[256];
char userdomain_u[25= 6]; /* for uppercase unicode username and domain */
= char userdomain[128]; /* the same as previous but ascii */ uint8_t ntlmv2_hash[MD5_DIGEST_LENGTH];
@@ -27= 0,17 +270,15 @@
* the missing bytes will be NULL, as = buf2 is known to be zeroed
* when this decode happens= .
*/
- uint8_t buf2[128]; /* decoded reply from proxy */
+ uint8_t buf2[512]; /* decoded re= ply from proxy */
CLEAR(buf2);
re= t_val =3D openvpn_base64_decode(phase_2, buf2, -1);
if= (ret_val < 0)
{
+ msg(M_WARN, "NTLM: base64 decoding of pha= se 2 response failed");
return NULL; }

- /* we can be sure that phase_2 is less than 128
- * therefore buf2 needs to be = (3/4 * 128) */

-=
/* extract the challenge from bytes 24-31 */
for (i =3D 0; i<8; i++)
{
@@ = -300,7 +298,7 @@
}
else
{
- msg(M_INFO, "Warning: Username or domain too long"= ;);
+ msg(= M_WARN, "NTLM: Username or domain too long");
= }
unicodize(userdomain_u, userdomain);

gen_hmac_md5((uint8_t *)userdomain_u, 2 * strlen(userdo= main), md4_hash,
@@ -335,9 +333,10 @@
= if ((flags & 0x00800000) =3D=3D 0x00800000)
= {
tib_len =3D buf2[0x28]; /* Get = Target Information block size */
- if (tib_len > 96)
+ if (tib_len + 0x1c + 16 > sizeof(ntl= mv2_response))
{
- tib_len =3D 96;
+ msg(M_WARN, "NTLM:= target information buffer too long for response (len=3D%d)", tib_len)= ;
+ re= turn NULL;
}

{
@@ -345,6 +344,7 @@
= uint8_t tib_pos =3D buf2[0x2c];
= if (tib_pos + tib_len > sizeof(buf2))
{=
+ = msg(M_ERR, "NTLM: phase 2 response from server too long (need %d byte= s at offset %u)", tib_len, tib_pos);
= return NULL;
}
= /* Get Target Information block pointer */
diff -= -git a/src/openvpn/proxy.c b/src/openvpn/proxy.c
index 76e2= 7cb..b2e8b3d 100644
--- a/src/openvpn/proxy.c
+++ b/src/openvpn/proxy.c
@@ -638,7 +638,6 @@
= {
struct gc_arena gc =3D gc_new();
char buf[512];
- char buf2[129];
char get[80];
= int status;
int nparms;
@@ -758,7 += 757,7 @@
{
#if NTLM
/* look for the phase 2 response */
-
+ char buf2[512];
while= (true)
{
if = (!recv_line(sd, buf, sizeof(buf), get_server_poll_remaining_time(server_pol= l_timeout), true, NULL, signal_received))
@@ -768,9 +767,9 = @@
chomp(buf);
= msg(D_PROXY, "HTTP proxy returned: '%s'", buf);


- = openvpn_snprintf(get, sizeof get, "%%*s NTLM %%%ds", (in= t) sizeof(buf2) - 1);
+ CLEAR(buf2);
+ openvpn_snprintf(get, sizeof(get), "%%*s NT= LM %%%zus", sizeof(buf2) - 1);
nparms= =3D sscanf(buf, get, buf2);
- buf2[128] =3D 0; /* we only need the beginning - ens= ure it's null terminated. */

= /* check for "Proxy-Authenticate: NTLM TlRM..." */

if (nparms =3D=3D 1)

To view, visit change 494. To unsubscribe, or for help writing mail fi= lters, visit settings.

=
Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: Iefa4930cb1e8c4135056a17ceb4= 283fc13cc75c8
Gerrit-Change-Number: 494
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--eojHkZn5XPU=--