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

some netlogon structs for NetrServerPasswordSet2 #951

Merged
merged 1 commit into from
Sep 14, 2020

Conversation

dirkjanm
Copy link
Contributor

still needs helpers and tests but the structs may be useful to some people ;)

@mohemiv
Copy link
Contributor

mohemiv commented Sep 14, 2020

Interestingly, I have a different code. For example, I changed the Length variable in the NL_TRUST_PASSWORD structure to ULONG, it's not LPWSTR.

@mohemiv
Copy link
Contributor

mohemiv commented Sep 14, 2020

It's likely that ClearNewPassword is NL_TRUST_PASSWORD, and not a PNL_TRUST_PASSWORD.

@dirkjanm
Copy link
Contributor Author

ULONG would probably be better, I used 4 null bytes for the LPWSTR, probably has the same effect. [MS-NRPC] mentions it should be a pointer to the NL_TRUST_PASSWORD struct, but i'm not familiar enough with RPC to know if/how that would make a difference.

@mohemiv
Copy link
Contributor

mohemiv commented Sep 14, 2020

According to C706 14.3.11.2 (https://pubs.opengroup.org/onlinepubs/009629399/toc.pdf), NDR represents a top-level reference pointer simply as the representation of its referent. But, if the pointer is marked as unique, it's an ordinary pointer (https://docs.microsoft.com/en-us/windows/win32/rpc/default-pointer-types).

Yep, it can be tricky to implement MSRPC methods. They could work even if the implementation is not fully-compliant, but you will face NDR errors in corner cases, or when you nest the structures/arrays, and so on.

@asolino
Copy link
Collaborator

asolino commented Sep 14, 2020

Thanks for the PR @dirkjanm .. indeed interesting for a couple of folks ;). Love to see you guys talking about NDR :P. I'll be playing with this hopefully today.

@bb00
Copy link

bb00 commented Sep 14, 2020

It doesn't make a difference. We're giving it an NL_TRUST_PASSWORD struct. It sees it as a pointer. 516 null bytes is 516 null bytes.

By the way, the struct is

 typedef struct _NL_TRUST_PASSWORD {
   WCHAR Buffer[256]; // 512 bytes (a wordchar is 2 bytes)
   ULONG Length; // 4 bytes
 } NL_TRUST_PASSWORD,
  *PNL_TRUST_PASSWORD;

@asolino asolino merged commit 052a849 into fortra:master Sep 14, 2020
@asolino
Copy link
Collaborator

asolino commented Sep 14, 2020

Minor changes and cosmetics, merged.. Game on guys. Thanks @dirkjanm

@dirkjanm
Copy link
Contributor Author

Right, it works for the exploit but not for legitimate password changing. The reason for this is that the entire NL_TRUST_PASSWORD buffer is passed in encrypted with the session key. @asolino would it make sense to simply change it to a buffer instead? Like that we can accommodate both options (and for the exploit its just null bytes so differentiating between data and length wouldn't really matter).

@dirkjanm dirkjanm deleted the NetrServerPasswordSet2 branch September 14, 2020 18:12
@dirkjanm
Copy link
Contributor Author

I've put some dirty fixes with a buffer in https://github.com/dirkjanm/CVE-2020-1472/blob/master/restorepassword.py. Also fixed function for AES and py3 where the IV should be bytes.

@asolino
Copy link
Collaborator

asolino commented Sep 14, 2020

512 + 4 = 514? @dirkjanm

@dirkjanm
Copy link
Contributor Author

Good catch, fixed it. Did work with 514 too in my tests though... :p

@asolino
Copy link
Collaborator

asolino commented Sep 14, 2020

Hang in there a few mins and I'll commit a similar change

asolino added a commit that referenced this pull request Sep 14, 2020
- So you can encrypt the NL_TRUST_PASSWORD struct yourself and put the result in there.
- Related to #951
@asolino
Copy link
Collaborator

asolino commented Sep 14, 2020

Give it a try now @dirkjanm

@dirkjanm
Copy link
Contributor Author

works, just missing the b prefix on AES IV here

asolino added a commit that referenced this pull request Sep 14, 2020
@asolino
Copy link
Collaborator

asolino commented Sep 14, 2020

There you go.. thanks @dirkjanm !

@dirkjanm
Copy link
Contributor Author

awesome! thanks for the quick fixes and all you do for this project ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants