浏览代码

NTLMAuthenticationProviderBase: Properly handle invalid NegotiateMessage / AuthenticateMessage

Tal Aloni 7 年之前
父节点
当前提交
477af8e690
共有 1 个文件被更改,包括 22 次插入6 次删除
  1. 22 6
      SMBLibrary/Authentication/NTLM/NTLMAuthenticationProviderBase.cs

+ 22 - 6
SMBLibrary/Authentication/NTLM/NTLMAuthenticationProviderBase.cs

@@ -25,16 +25,32 @@ namespace SMBLibrary.Authentication.NTLM
             MessageTypeName messageType = AuthenticationMessageUtils.GetMessageType(inputToken);
             if (messageType == MessageTypeName.Negotiate)
             {
-                NegotiateMessage input = new NegotiateMessage(inputToken);
-                ChallengeMessage output;
-                NTStatus status = GetChallengeMessage(out context, input, out output);
-                outputToken = output.GetBytes();
+                NegotiateMessage negotiateMessage;
+                try
+                {
+                    negotiateMessage = new NegotiateMessage(inputToken);
+                }
+                catch
+                {
+                    return NTStatus.SEC_E_INVALID_TOKEN;
+                }
+                ChallengeMessage challengeMessage;
+                NTStatus status = GetChallengeMessage(out context, negotiateMessage, out challengeMessage);
+                outputToken = challengeMessage.GetBytes();
                 return status;
             }
             else if (messageType == MessageTypeName.Authenticate)
             {
-                AuthenticateMessage message = new AuthenticateMessage(inputToken);
-                return Authenticate(context, message);
+                AuthenticateMessage authenticateMessage;
+                try
+                {
+                    authenticateMessage = new AuthenticateMessage(inputToken);
+                }
+                catch
+                {
+                    return NTStatus.SEC_E_INVALID_TOKEN;
+                }
+                return Authenticate(context, authenticateMessage);
             }
             else
             {