Beispiel #1
0
        internal static NegotiateResponseExtended GetNegotiateResponseExtended(NegotiateRequest request, Guid serverGuid)
        {
            NegotiateResponseExtended response = new NegotiateResponseExtended();

            response.DialectIndex  = (ushort)request.Dialects.IndexOf(SMBServer.NTLanManagerDialect);
            response.SecurityMode  = SecurityMode.UserSecurityMode | SecurityMode.EncryptPasswords;
            response.MaxMpxCount   = ServerMaxMpxCount;
            response.MaxNumberVcs  = ServerNumberVcs;
            response.MaxBufferSize = ServerMaxBufferSize;
            response.MaxRawSize    = ServerMaxRawSize;
            response.Capabilities  = Capabilities.Unicode |
                                     Capabilities.LargeFiles |
                                     Capabilities.NTSMB |
                                     Capabilities.RpcRemoteApi |
                                     Capabilities.NTStatusCode |
                                     Capabilities.NTFind |
                                     Capabilities.InfoLevelPassthrough |
                                     Capabilities.LargeRead |
                                     Capabilities.LargeWrite |
                                     Capabilities.ExtendedSecurity;
            response.SystemTime     = DateTime.UtcNow;
            response.ServerTimeZone = (short)-TimeZoneInfo.Local.GetUtcOffset(DateTime.Now).TotalMinutes;
            response.ServerGuid     = serverGuid;

            return(response);
        }
Beispiel #2
0
        private bool NegotiateNTLanManagerDialect()
        {
            if (m_transport == SMBTransportType.NetBiosOverTCP)
            {
                SessionRequestPacket sessionRequest = new SessionRequestPacket();
                sessionRequest.CalledName  = NetBiosUtils.GetMSNetBiosName("*SMBSERVER", NetBiosSuffix.FileServiceService);;
                sessionRequest.CallingName = NetBiosUtils.GetMSNetBiosName(Environment.MachineName, NetBiosSuffix.WorkstationService);
                TrySendPacket(m_clientSocket, sessionRequest);
            }
            NegotiateRequest request = new NegotiateRequest();

            request.Dialects.Add(NTLanManagerDialect);
            TrySendMessage(m_clientSocket, request);
            SMB1Message reply = WaitForMessage(CommandName.SMB_COM_NEGOTIATE);

            if (reply == null)
            {
                return(false);
            }

            if (reply.Commands[0] is NegotiateResponse)
            {
                NegotiateResponse response = (NegotiateResponse)reply.Commands[0];
                return(true);
            }
            else if (reply.Commands[0] is NegotiateResponseExtended)
            {
                NegotiateResponseExtended response = (NegotiateResponseExtended)reply.Commands[0];
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #3
0
        private bool NegotiateDialect(bool forceExtendedSecurity)
        {
            if (m_transport == SMBTransportType.NetBiosOverTCP)
            {
                SessionRequestPacket sessionRequest = new SessionRequestPacket();
                sessionRequest.CalledName  = NetBiosUtils.GetMSNetBiosName("*SMBSERVER", NetBiosSuffix.FileServiceService);;
                sessionRequest.CallingName = NetBiosUtils.GetMSNetBiosName(Environment.MachineName, NetBiosSuffix.WorkstationService);
                TrySendPacket(m_clientSocket, sessionRequest);
            }
            NegotiateRequest request = new NegotiateRequest();

            request.Dialects.Add(NTLanManagerDialect);

            TrySendMessage(request);
            SMB1Message reply = WaitForMessage(CommandName.SMB_COM_NEGOTIATE);

            if (reply == null)
            {
                return(false);
            }

            if (reply.Commands[0] is NegotiateResponse && !forceExtendedSecurity)
            {
                NegotiateResponse response = (NegotiateResponse)reply.Commands[0];
                m_unicode    = ((response.Capabilities & Capabilities.Unicode) > 0);
                m_largeFiles = ((response.Capabilities & Capabilities.LargeFiles) > 0);
                bool ntSMB        = ((response.Capabilities & Capabilities.NTSMB) > 0);
                bool rpc          = ((response.Capabilities & Capabilities.RpcRemoteApi) > 0);
                bool ntStatusCode = ((response.Capabilities & Capabilities.NTStatusCode) > 0);
                m_infoLevelPassthrough = ((response.Capabilities & Capabilities.InfoLevelPassthrough) > 0);
                m_largeRead            = ((response.Capabilities & Capabilities.LargeRead) > 0);
                m_largeWrite           = ((response.Capabilities & Capabilities.LargeWrite) > 0);
                m_serverMaxBufferSize  = response.MaxBufferSize;
                m_maxMpxCount          = Math.Min(response.MaxMpxCount, ClientMaxMpxCount);
                m_serverChallenge      = response.Challenge;
                return(ntSMB && rpc && ntStatusCode);
            }
            else if (reply.Commands[0] is NegotiateResponseExtended)
            {
                NegotiateResponseExtended response = (NegotiateResponseExtended)reply.Commands[0];
                m_unicode    = ((response.Capabilities & Capabilities.Unicode) > 0);
                m_largeFiles = ((response.Capabilities & Capabilities.LargeFiles) > 0);
                bool ntSMB        = ((response.Capabilities & Capabilities.NTSMB) > 0);
                bool rpc          = ((response.Capabilities & Capabilities.RpcRemoteApi) > 0);
                bool ntStatusCode = ((response.Capabilities & Capabilities.NTStatusCode) > 0);
                m_infoLevelPassthrough = ((response.Capabilities & Capabilities.InfoLevelPassthrough) > 0);
                m_largeRead            = ((response.Capabilities & Capabilities.LargeRead) > 0);
                m_largeWrite           = ((response.Capabilities & Capabilities.LargeWrite) > 0);
                m_serverMaxBufferSize  = response.MaxBufferSize;
                m_maxMpxCount          = Math.Min(response.MaxMpxCount, ClientMaxMpxCount);
                m_securityBlob         = response.SecurityBlob;
                return(ntSMB && rpc && ntStatusCode);
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        private bool NegotiateDialect(bool forceExtendedSecurity)
        {
            NegotiateRequest request = new NegotiateRequest();

            request.Dialects.Add(NTLanManagerDialect);

            TrySendMessage(request);
            SMB1Message reply = WaitForMessage(CommandName.SMB_COM_NEGOTIATE);

            if (reply == null)
            {
                return(false);
            }

            if (reply.Commands[0] is NegotiateResponse && !forceExtendedSecurity)
            {
                NegotiateResponse response = (NegotiateResponse)reply.Commands[0];
                Domainname = response.DomainName;
                Hostname   = response.ServerName;

                m_unicode    = ((response.Capabilities & Capabilities.Unicode) > 0);
                m_largeFiles = ((response.Capabilities & Capabilities.LargeFiles) > 0);
                bool ntSMB        = ((response.Capabilities & Capabilities.NTSMB) > 0);
                bool rpc          = ((response.Capabilities & Capabilities.RpcRemoteApi) > 0);
                bool ntStatusCode = ((response.Capabilities & Capabilities.NTStatusCode) > 0);
                m_infoLevelPassthrough = ((response.Capabilities & Capabilities.InfoLevelPassthrough) > 0);
                m_largeRead            = ((response.Capabilities & Capabilities.LargeRead) > 0);
                m_largeWrite           = ((response.Capabilities & Capabilities.LargeWrite) > 0);
                m_serverMaxBufferSize  = response.MaxBufferSize;
                m_maxMpxCount          = Math.Min(response.MaxMpxCount, ClientMaxMpxCount);
                m_serverChallenge      = response.Challenge;
                return(ntSMB && rpc && ntStatusCode);
            }
            else if (reply.Commands[0] is NegotiateResponseExtended)
            {
                NegotiateResponseExtended response = (NegotiateResponseExtended)reply.Commands[0];
                m_unicode    = ((response.Capabilities & Capabilities.Unicode) > 0);
                m_largeFiles = ((response.Capabilities & Capabilities.LargeFiles) > 0);
                bool ntSMB        = ((response.Capabilities & Capabilities.NTSMB) > 0);
                bool rpc          = ((response.Capabilities & Capabilities.RpcRemoteApi) > 0);
                bool ntStatusCode = ((response.Capabilities & Capabilities.NTStatusCode) > 0);
                m_infoLevelPassthrough = ((response.Capabilities & Capabilities.InfoLevelPassthrough) > 0);
                m_largeRead            = ((response.Capabilities & Capabilities.LargeRead) > 0);
                m_largeWrite           = ((response.Capabilities & Capabilities.LargeWrite) > 0);
                m_serverMaxBufferSize  = response.MaxBufferSize;
                m_maxMpxCount          = Math.Min(response.MaxMpxCount, ClientMaxMpxCount);
                m_securityBlob         = response.SecurityBlob;
                return(ntSMB && rpc && ntStatusCode);
            }
            else
            {
                return(false);
            }
        }
Beispiel #5
0
        internal static NegotiateResponseExtended GetNegotiateResponseExtended(NegotiateRequest request, Guid serverGuid)
        {
            NegotiateResponseExtended response = new NegotiateResponseExtended();

            response.DialectIndex  = (ushort)request.Dialects.IndexOf(SMBServer.NTLanManagerDialect);
            response.SecurityMode  = SecurityMode.UserSecurityMode | SecurityMode.EncryptPasswords;
            response.MaxMpxCount   = 50;
            response.MaxNumberVcs  = 1;
            response.MaxBufferSize = 16644;
            response.MaxRawSize    = 65536;
            response.Capabilities  = ServerCapabilities.Unicode |
                                     ServerCapabilities.LargeFiles |
                                     ServerCapabilities.NTSMB |
                                     ServerCapabilities.NTStatusCode |
                                     ServerCapabilities.NTFind |
                                     ServerCapabilities.LargeRead |
                                     ServerCapabilities.LargeWrite |
                                     ServerCapabilities.ExtendedSecurity;
            response.SystemTime     = DateTime.UtcNow;
            response.ServerTimeZone = (short)-TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).TotalMinutes;
            response.ServerGuid     = serverGuid;

            return(response);
        }