コード例 #1
0
ファイル: SMBServer.SMB1.cs プロジェクト: gonsovsky/dnSvc
 /// <summary>
 /// May return an empty list
 /// </summary>
 private List <SMB1Command> ProcessSMB1Command(SMB1Header header, SMB1Command command, ref ConnectionState state)
 {
     if (state.Dialect == SMBDialect.NotSet)
     {
         if (command is NegotiateRequest)
         {
             NegotiateRequest request = (NegotiateRequest)command;
             if (request.Dialects.Contains(SMBServer.NTLanManagerDialect))
             {
                 state         = new SMB1ConnectionState(state);
                 state.Dialect = SMBDialect.NTLM012;
                 m_connectionManager.AddConnection(state);
                 if (EnableExtendedSecurity && header.ExtendedSecurityFlag)
                 {
                     return(NegotiateHelper.GetNegotiateResponseExtended(request, m_serverGuid));
                 }
                 else
                 {
                     return(NegotiateHelper.GetNegotiateResponse(header, request, m_securityProvider, state));
                 }
             }
             else
             {
                 return(new NegotiateResponseNotSupported());
             }
         }
         else
         {
             // [MS-CIFS] An SMB_COM_NEGOTIATE exchange MUST be completed before any other SMB messages are sent to the server
             header.Status = NTStatus.STATUS_INVALID_SMB;
             return(new ErrorResponse(command.CommandName));
         }
     }
     else if (command is NegotiateRequest)
     {
         // There MUST be only one SMB_COM_NEGOTIATE exchange per SMB connection.
         // Subsequent SMB_COM_NEGOTIATE requests received by the server MUST be rejected with error responses.
         header.Status = NTStatus.STATUS_INVALID_SMB;
         return(new ErrorResponse(command.CommandName));
     }
     else
     {
         return(ProcessSMB1Command(header, command, (SMB1ConnectionState)state));
     }
 }
コード例 #2
0
ファイル: SMBServer.SMB2.cs プロジェクト: gonsovsky/dnSvc
 /// <summary>
 /// May return null
 /// </summary>
 private SMB2Command ProcessSMB2Command(SMB2Command command, ref ConnectionState state)
 {
     if (state.Dialect == SMBDialect.NotSet)
     {
         if (command is NegotiateRequest)
         {
             NegotiateRequest request  = (NegotiateRequest)command;
             SMB2Command      response = NegotiateHelper.GetNegotiateResponse(request, m_securityProvider, state, m_serverGuid, m_serverStartTime);
             if (state.Dialect != SMBDialect.NotSet)
             {
                 state = new SMB2ConnectionState(state);
                 m_connectionManager.AddConnection(state);
             }
             return(response);
         }
         else
         {
             // [MS-SMB2] If the request being received is not an SMB2 NEGOTIATE Request [..]
             // and Connection.NegotiateDialect is 0xFFFF or 0x02FF, the server MUST
             // disconnect the connection.
             state.LogToServer(Severity.Debug, "Invalid Connection State for command {0}", command.CommandName.ToString());
             state.ClientSocket.Close();
             return(null);
         }
     }
     else if (command is NegotiateRequest)
     {
         // [MS-SMB2] If Connection.NegotiateDialect is 0x0202, 0x0210, 0x0300, 0x0302, or 0x0311,
         // the server MUST disconnect the connection.
         state.LogToServer(Severity.Debug, "Rejecting NegotiateRequest. NegotiateDialect is already set");
         state.ClientSocket.Close();
         return(null);
     }
     else
     {
         return(ProcessSMB2Command(command, (SMB2ConnectionState)state));
     }
 }