diff --git a/SMBLibrary/Authentication/GSSAPI/GSSAPIHelper.cs b/SMBLibrary/Authentication/GSSAPI/GSSAPIHelper.cs index 58716e0..06a6ade 100644 --- a/SMBLibrary/Authentication/GSSAPI/GSSAPIHelper.cs +++ b/SMBLibrary/Authentication/GSSAPI/GSSAPIHelper.cs @@ -48,6 +48,16 @@ namespace SMBLibrary.Authentication return null; } + public static byte[] GetGSSTokenInitNTLMSSPBytes() + { + SimpleProtectedNegotiationTokenInit token = new SimpleProtectedNegotiationTokenInit(); + TokenInitEntry entry = new TokenInitEntry(); + entry.MechanismTypeList = new List(); + entry.MechanismTypeList.Add(NTLMSSPIdentifier); + token.Tokens.Add(entry); + return SimpleProtectedNegotiationToken.GetTokenBytes(token); + } + public static byte[] GetGSSTokenResponseBytesFromNTLMSSPMessage(byte[] messageBytes) { SimpleProtectedNegotiationTokenResponse token = new SimpleProtectedNegotiationTokenResponse(); diff --git a/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationToken.cs b/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationToken.cs index 6b4193e..50eb2ad 100644 --- a/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationToken.cs +++ b/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationToken.cs @@ -51,5 +51,33 @@ namespace SMBLibrary.Authentication } return null; } + + /// + /// Will append the generic GSSAPI header. + /// + public static byte[] GetTokenBytes(SimpleProtectedNegotiationToken token) + { + if (token is SimpleProtectedNegotiationTokenInit) + { + byte[] tokenBytes = token.GetBytes(); + int objectIdentifierFieldSize = DerEncodingHelper.GetLengthFieldSize(SPNEGOIdentifier.Length); + int tokenLength = 1 + objectIdentifierFieldSize + SPNEGOIdentifier.Length + tokenBytes.Length; + int tokenLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(tokenLength); + int headerLength = 1 + tokenLengthFieldSize + 1 + objectIdentifierFieldSize + SPNEGOIdentifier.Length; + byte[] buffer = new byte[headerLength + tokenBytes.Length]; + int offset = 0; + ByteWriter.WriteByte(buffer, ref offset, ApplicationTag); + DerEncodingHelper.WriteLength(buffer, ref offset, tokenLength); + ByteWriter.WriteByte(buffer, ref offset, (byte)DerEncodingTag.ObjectIdentifier); + DerEncodingHelper.WriteLength(buffer, ref offset, SPNEGOIdentifier.Length); + ByteWriter.WriteBytes(buffer, ref offset, SPNEGOIdentifier); + ByteWriter.WriteBytes(buffer, ref offset, tokenBytes); + return buffer; + } + else + { + return token.GetBytes(); + } + } } } diff --git a/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationTokenInit.cs b/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationTokenInit.cs index 31d7219..fd2acea 100644 --- a/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationTokenInit.cs +++ b/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationTokenInit.cs @@ -13,9 +13,9 @@ namespace SMBLibrary.Authentication { public class TokenInitEntry { - public List MechanismTypeList = new List(); // Optional + public List MechanismTypeList; // Optional // reqFlags - Optional, RECOMMENDED to be left out - public byte[] MechanismToken = new byte[0]; // Optional + public byte[] MechanismToken; // Optional public byte[] MechanismListMIC; // Optional } @@ -32,6 +32,10 @@ namespace SMBLibrary.Authentication public List Tokens = new List(); + public SimpleProtectedNegotiationTokenInit() + { + } + /// The offset following the NegTokenInit tag public SimpleProtectedNegotiationTokenInit(byte[] buffer, int offset) { diff --git a/SMBLibrary/Server/SMB2/NegotiateHelper.cs b/SMBLibrary/Server/SMB2/NegotiateHelper.cs index d79a218..a091e21 100644 --- a/SMBLibrary/Server/SMB2/NegotiateHelper.cs +++ b/SMBLibrary/Server/SMB2/NegotiateHelper.cs @@ -45,6 +45,7 @@ namespace SMBLibrary.Server.SMB2 response.MaxWriteSize = 65536; response.SystemTime = DateTime.Now; response.ServerStartTime = DateTime.Today; + response.SecurityBuffer = GSSAPIHelper.GetGSSTokenInitNTLMSSPBytes(); return response; } @@ -71,6 +72,7 @@ namespace SMBLibrary.Server.SMB2 response.MaxWriteSize = 65536; response.SystemTime = DateTime.Now; response.ServerStartTime = DateTime.Today; + response.SecurityBuffer = GSSAPIHelper.GetGSSTokenInitNTLMSSPBytes(); return response; }