Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update selection of type 3 response in ntlm.c #3287

Closed
wants to merge 50 commits into from
Closed

Conversation

huaraz
Copy link

@huaraz huaraz commented Nov 18, 2018

NTLM2 did not work i.e. no NTLMv2 response was created. Changing the check seems to work.

https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-NLMP/[MS-NLMP].pdf

Fixes #3286

NTLM2 did not work i.e. no NTLMv2 response was created. Changing the check seems to work. 

https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-NLMP/[MS-NLMP].pdf
remove space
@huaraz huaraz changed the title Update ntlm.c Update selection of type 3 response in ntlm.c Nov 18, 2018
@huaraz
Copy link
Author

huaraz commented Nov 18, 2018

Does the Travis-CI log indicate NTLM failures ? It is hard to read/understand the result in the log.

Markus

@bagder
Copy link
Member

bagder commented Nov 19, 2018

These test cases failed: 2025 2028 2029 2030 2031

Yes, those tests seem to fail now and they all involve NTLM...

@huaraz
Copy link
Author

huaraz commented Nov 19, 2018

I feared that be the case. Would it be possible to get the capture of the NTLM exchange i.e. what were the flags in type 1,2 and 3 for the successful and failed auth attempts ?

Is there an option to test against an AD server which has NTLMv1 / LM disabled ?

@bagder
Copy link
Member

bagder commented Nov 19, 2018

Is there an option to test against an AD server which has NTLMv1 / LM disabled ?

All curl tests are run either without a test server or with a "synthetic" test server that we build ourselves. This way everyone can build and run the tests and they can run in the CI etc without having to connect anywhere or need any magic accounts. (Also, most curl developers are on non-windows platforms.)

For this particular failure, you've updated bits that curl sends in its NTLM headers without updating the corresponding tests so this is not a surprise. The tests will verify that curl sends exactly what is expected of it!

@huaraz
Copy link
Author

huaraz commented Nov 19, 2018

The change shouldn't break anything for a "old" "insecure" AD server, but add additional functionality to support AD server which have LM and NTLMv1 disabled.

So if the tests fail I need to understand what the synthetic setup looks like to adjust as I have a limited test environment. Is that possible ?

Thank you
Markus

@bagder
Copy link
Member

bagder commented Nov 20, 2018

Starting with the first test fail, test2025, I think the critical diff is this:

-Authorization: NTLM TlRMTVNTUAADAAAAGAAYAEAAAAAYABgAWAAAAAAAAABwAAAACAAIAHAAAAAIAAgAeAAAAAAAAAAAAAAABoIBAI+/Fp9IERAQ74OsdNPbBpg7o8CVwLSO4DtFyIcZHUMKVktWIu92s2892OVpd2JzqnRlc3R1c2VyY3VybGhvc3Q=[CR][LF]
+Authorization: NTLM TlRMTVNTUAADAAAAGAAYAEAAAAAYABgAWAAAAAAAAABwAAAACAAIAHAAAAAIAAgAeAAAAAAAAAAAAAAABoIBACSb60vUMLShAAAAAAAAAAAAAAAAAAAAAHSb9yQXjz3gIcUWePywK8aoyXJ4KokJ13Rlc3R1c2VyY3VybGhvc3Q=[CR][LF]

If you paste them into a text editor you can see how the headers start differ at position 105. Which isn't a surprise since the code has changed how the Authorization: header is created without updating the tests...

@huaraz
Copy link
Author

huaraz commented Nov 20, 2018

I am sorry I may not have understood correctly before. Are you saying some tests are just string comparisons not functional ?

Markus

@bagder
Copy link
Member

bagder commented Nov 20, 2018

They do both, but yes I'm saying these five tests all report the string differences as failures. Since they get a different string than they expect!

@huaraz
Copy link
Author

huaraz commented Nov 20, 2018

So that means basically the change works. The tests need to be only adjusted ?

@bagder
Copy link
Member

bagder commented Nov 21, 2018

If you say so. The custom test server we run really doesn't "know" NTLM, it just plays back whatever we tell it to.

If you want to verify that your code really works and speaks NTLMv2 I trust that you use it against a real server that implements and supports that protocol. Once you know your code works against such a server, then simply updating the strings in the corresponding curl tests should be fine and will make sure we don't regress this going forward.

lib/vauth/ntlm.c Outdated
@@ -451,6 +451,7 @@ CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data,
LONGQUARTET(NTLMFLAG_NEGOTIATE_OEM |
NTLMFLAG_REQUEST_TARGET |
NTLMFLAG_NEGOTIATE_NTLM_KEY |
NTLMFLAG_NEGOTIATE_NTLM2_KEY |
NTLM2FLAG |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NTLM2FLAG already contains NTLMFLAG_NEGOTIATE_NTLM2_KEY, see line ~408:

#if defined(USE_NTRESPONSES) && defined(USE_NTLM2SESSION)
#define NTLM2FLAG NTLMFLAG_NEGOTIATE_NTLM2_KEY
#else
#define NTLM2FLAG 0
#endif

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I overlooked that. Thank you

lib/vauth/ntlm.c Outdated
@@ -599,7 +600,7 @@ CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,

#if defined(USE_NTRESPONSES) && defined(USE_NTLM2SESSION)
/* We don't support NTLM2 if we don't have USE_NTRESPONSES */
if(ntlm->flags & NTLMFLAG_NEGOTIATE_NTLM2_KEY) {
if(ntlm->flags & NTLMFLAG_NEGOTIATE_NTLM_KEY) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this change. Does this mean that an NTLMv1 message is sent to servers that support NTLMv2 ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the part of the code I am not sure about. The comment is about NTLM2, but the previous section is really the NTLMv2 section i.e. where the correct response is created. This one seem to create only the LM response. ( At least the was the result from the wireshark captures)

Markus

remove unnecessary flag
typing error
@huaraz
Copy link
Author

huaraz commented Nov 22, 2018

Does anybody know which Negotiate flag combination reflects the 6 cases ?

There are six authentication levels.

Send LM & NTLM responses: Clients use LM and NTLM authentication, and never use NTLMv2 session security; DCs accept LM, NTLM, and NTLMv2 authentication.

Send LM & NTLM - use NTLMv2 session security if negotiated: Clients use LM and NTLM authentication, and use NTLMv2 session security if server supports it; DCs accept LM, NTLM, and NTLMv2 authentication.

Send NTLM response only: Clients use NTLM authentication only, and use NTLMv2 session security if server supports it; DCs accept LM, NTLM, and NTLMv2 authentication.

Send NTLMv2 response only: Clients use NTLMv2 authentication only, and use NTLMv2 session security if server supports it; DCs accept LM, NTLM, and NTLMv2 authentication.

Send NTLMv2 response only\refuse LM: Clients use NTLMv2 authentication only, and use NTLMv2 session security if server supports it; DCs refuse LM (accept only NTLM and NTLMv2 authentication).

Send NTLMv2 response only\refuse LM & NTLM: Clients use NTLMv2 authentication only, and use NTLMv2 session security if server supports it; DCs refuse LM and NTLM (accept only NTLMv2 authentication).

Markus

@huaraz
Copy link
Author

huaraz commented Dec 1, 2018

Who can verify that this is correct and can go into a release ?

@huaraz
Copy link
Author

huaraz commented Dec 16, 2018

How can I rerun the tests ? They don't seem to be related to my code changes

Thank you
Markus

@MarcelRaad
Copy link
Member

I've restarted the failed Travis tests.

@huaraz
Copy link
Author

huaraz commented Dec 17, 2018

It looks like the master branch is broken

make[2]: Entering directory /home/travis/build/curl/curl/tests/unit' CC unit1300-unit1300.o CC ../libtest/unit1300-first.o make[2]: *** No rule to make target ../../src/libcurltool.la', needed by unit1300'. Stop. make[2]: Leaving directory /home/travis/build/curl/curl/tests/unit'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/travis/build/curl/curl/tests'
make: *** [test-nonflaky] Error 2

@MarcelRaad
Copy link
Member

Actually, at least the first failure is because of:

./vauth/ntlm.c:634:73: warning: Trailing whitespace (TRAILINGSPACE)
     /* NTLM v2 session security is a misnomer because it is not NTLM v2. 
                                                                         ^
./vauth/ntlm.c:635:84: warning: Longer than 79 columns (LONGLINE)
        It is NTLM v1 using the extended session security that is also in NTLM v2 */

Building with --enable-debug (or running checksrc explicitly) will show you these.

@huaraz
Copy link
Author

huaraz commented Dec 18, 2018

Actually, at least the first failure is because of:

./vauth/ntlm.c:634:73: warning: Trailing whitespace (TRAILINGSPACE)
     /* NTLM v2 session security is a misnomer because it is not NTLM v2. 
                                                                         ^
./vauth/ntlm.c:635:84: warning: Longer than 79 columns (LONGLINE)
        It is NTLM v1 using the extended session security that is also in NTLM v2 */

Building with --enable-debug (or running checksrc explicitly) will show you these.

Thank you for the hint. I did not find this in the log.

@huaraz
Copy link
Author

huaraz commented Dec 18, 2018

Not sure what the cause is of the unit1300 error. Looks more like an issue with the testing environment.
I will update against git master branch.

Markus

@huaraz huaraz force-pushed the patch-1 branch 3 times, most recently from b6fc986 to cfc5958 Compare December 28, 2018 13:18
@huaraz huaraz closed this Dec 28, 2018
@huaraz huaraz deleted the patch-1 branch December 28, 2018 14:02
@huaraz
Copy link
Author

huaraz commented Dec 28, 2018

Sorry I am too new to git and it seems I misunderstood how "squashing" works. I deleted the patch and recreated a new pull

Markus

MarcelRaad pushed a commit that referenced this pull request Jan 1, 2019
NTLM2 did not work i.e. no NTLMv2 response was created. Changing the
check seems to work.

Ref: https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-NLMP/[MS-NLMP].pdf

Fixes #3286
Closes #3287
Closes #3415
@lock lock bot locked as resolved and limited conversation to collaborators Mar 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants