Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create Ntlm Type 1 and Type 3 messages in .Net

I need to create Type 1 message and Type 3 message for NTLM handshaking. Is there any .Net API for this?

Essentially, the application is WPF based, but Socket is used in order to stream data from the server. Use of socket is a technical requirement, but the problem is when user needs to connect to the server using a proxy server. Further, if the proxy authorization is based on Ntlm, the client application needs to create Type 1 and Type 3 messages in order to handshake with the proxy server.

My question is: Is there any API already available in .NET libraries that can be consumed in order to create these different types of NTLM messages? Any help or alternatives will be greatly appreciated. Thanks in advance.

like image 863
brj011 Avatar asked Mar 14 '11 00:03

brj011


1 Answers

If you are restricted to sockets, you will have to manually implement entire NTLM authentication protocol. Microsoft has a Security Support Provider Interface (SSPI) in secur32.dll to implement various security protocols, you can probably reuse some of API functions from there, through PInvoke (also there is some sort of .net wrapper is available here).

Here is the description of NTLM auth protocol, with API samples in NTLMSSP and SSPI section. Basically, entire authentication scheme is evolving around calling AcquireCredentialsHandle / InitializeSecurityContext with different parameters. This would provide you with type1/type3 ntlm messages in raw byte format, which you would have to send/receive through sockets.

like image 141
Alexander Avatar answered Oct 13 '22 01:10

Alexander