From 97326c311a485ed84911f10a398ce0cbec38dedf Mon Sep 17 00:00:00 2001 From: Tal Aloni Date: Mon, 13 Mar 2017 19:48:28 +0200 Subject: [PATCH] Independent / Integrated NTLMAuthenticationProvider: GetContextAttribute can now return OS version --- .../Authentication/GSSAPI/Enums/GSSAttributeName.cs | 1 + .../NTLM/IndependentNTLMAuthenticationProvider.cs | 8 ++++++++ SMBLibrary/Authentication/NTLM/Structures/NTLMVersion.cs | 5 +++++ SMBLibrary/Win32/IntegratedNTLMAuthenticationProvider.cs | 8 ++++++++ 4 files changed, 22 insertions(+) diff --git a/SMBLibrary/Authentication/GSSAPI/Enums/GSSAttributeName.cs b/SMBLibrary/Authentication/GSSAPI/Enums/GSSAttributeName.cs index b9eb720..60baad2 100644 --- a/SMBLibrary/Authentication/GSSAPI/Enums/GSSAttributeName.cs +++ b/SMBLibrary/Authentication/GSSAPI/Enums/GSSAttributeName.cs @@ -13,6 +13,7 @@ namespace SMBLibrary.Authentication.GSSAPI /// IsGuest, MachineName, + OSVersion, SessionKey, UserName, } diff --git a/SMBLibrary/Authentication/NTLM/IndependentNTLMAuthenticationProvider.cs b/SMBLibrary/Authentication/NTLM/IndependentNTLMAuthenticationProvider.cs index a9dc129..62fd319 100644 --- a/SMBLibrary/Authentication/NTLM/IndependentNTLMAuthenticationProvider.cs +++ b/SMBLibrary/Authentication/NTLM/IndependentNTLMAuthenticationProvider.cs @@ -22,6 +22,7 @@ namespace SMBLibrary.Authentication.NTLM public string DomainName; public string UserName; public string WorkStation; + public string OSVersion; public byte[] SessionKey; public bool IsGuest; @@ -134,6 +135,11 @@ namespace SMBLibrary.Authentication.NTLM authContext.DomainName = message.DomainName; authContext.UserName = message.UserName; authContext.WorkStation = message.WorkStation; + if (message.Version != null) + { + authContext.OSVersion = message.Version.ToString(); + } + if ((message.NegotiateFlags & NegotiateFlags.Anonymous) > 0) { if (this.EnableGuestLogin) @@ -244,6 +250,8 @@ namespace SMBLibrary.Authentication.NTLM return authContext.IsGuest; case GSSAttributeName.MachineName: return authContext.WorkStation; + case GSSAttributeName.OSVersion: + return authContext.OSVersion; case GSSAttributeName.SessionKey: return authContext.SessionKey; case GSSAttributeName.UserName: diff --git a/SMBLibrary/Authentication/NTLM/Structures/NTLMVersion.cs b/SMBLibrary/Authentication/NTLM/Structures/NTLMVersion.cs index 5c4e123..6162e2c 100644 --- a/SMBLibrary/Authentication/NTLM/Structures/NTLMVersion.cs +++ b/SMBLibrary/Authentication/NTLM/Structures/NTLMVersion.cs @@ -48,6 +48,11 @@ namespace SMBLibrary.Authentication.NTLM ByteWriter.WriteByte(buffer, offset + 7, NTLMRevisionCurrent); } + public override string ToString() + { + return String.Format("{0}.{1}.{2}", ProductMajorVersion, ProductMinorVersion, ProductBuild); + } + public static NTLMVersion WindowsXP { get diff --git a/SMBLibrary/Win32/IntegratedNTLMAuthenticationProvider.cs b/SMBLibrary/Win32/IntegratedNTLMAuthenticationProvider.cs index f406932..7da1a9f 100644 --- a/SMBLibrary/Win32/IntegratedNTLMAuthenticationProvider.cs +++ b/SMBLibrary/Win32/IntegratedNTLMAuthenticationProvider.cs @@ -24,6 +24,7 @@ namespace SMBLibrary.Win32.Security public string DomainName; public string UserName; public string WorkStation; + public string OSVersion; public bool IsGuest; public AuthContext(SecHandle serverContext) @@ -75,6 +76,11 @@ namespace SMBLibrary.Win32.Security authContext.DomainName = message.DomainName; authContext.UserName = message.UserName; authContext.WorkStation = message.WorkStation; + if (message.Version != null) + { + authContext.OSVersion = message.Version.ToString(); + } + if ((message.NegotiateFlags & NegotiateFlags.Anonymous) > 0 || !IsUserExists(message.UserName)) { @@ -160,6 +166,8 @@ namespace SMBLibrary.Win32.Security return authContext.IsGuest; case GSSAttributeName.MachineName: return authContext.WorkStation; + case GSSAttributeName.OSVersion: + return authContext.OSVersion; case GSSAttributeName.SessionKey: return SSPIHelper.GetSessionKey(authContext.ServerContext); case GSSAttributeName.UserName: