Beispiel #1
0
        private SMB2Command ProcessSMB2Command(SMB2Command command, SMB2ConnectionState state)
        {
            if (command is SessionSetupRequest)
            {
                return(SessionSetupHelper.GetSessionSetupResponse((SessionSetupRequest)command, m_securityProvider, state));
            }
            else if (command is EchoRequest)
            {
                return(new EchoResponse());
            }
            else
            {
                SMB2Session session = state.GetSession(command.Header.SessionID);
                if (session == null)
                {
                    return(new ErrorResponse(command.CommandName, NTStatus.STATUS_USER_SESSION_DELETED));
                }

                if (command is TreeConnectRequest)
                {
                    return(TreeConnectHelper.GetTreeConnectResponse((TreeConnectRequest)command, state, m_services, m_shares));
                }
                else if (command is LogoffRequest)
                {
                    state.LogToServer(Severity.Information, "Logoff: User '{0}' logged off. (SessionID: {1})", session.UserName, command.Header.SessionID);
                    m_securityProvider.DeleteSecurityContext(ref session.SecurityContext.AuthenticationContext);
                    state.RemoveSession(command.Header.SessionID);
                    return(new LogoffResponse());
                }
                else if (command.Header.IsAsync)
                {
                    // TreeID will not be present in an ASYNC header
                    if (command is CancelRequest)
                    {
                        return(CancelHelper.GetCancelResponse((CancelRequest)command, state));
                    }
                }
                else
                {
                    ISMBShare share = session.GetConnectedTree(command.Header.TreeID);
                    if (share == null)
                    {
                        state.LogToServer(Severity.Verbose, "{0} failed. Invalid TreeID (SessionID: {1}, TreeID: {2}).", command.CommandName, command.Header.SessionID, command.Header.TreeID);
                        return(new ErrorResponse(command.CommandName, NTStatus.STATUS_NETWORK_NAME_DELETED));
                    }

                    if (command is TreeDisconnectRequest)
                    {
                        return(TreeConnectHelper.GetTreeDisconnectResponse((TreeDisconnectRequest)command, share, state));
                    }
                    else if (command is CreateRequest)
                    {
                        return(CreateHelper.GetCreateResponse((CreateRequest)command, share, state));
                    }
                    else if (command is QueryInfoRequest)
                    {
                        return(QueryInfoHelper.GetQueryInfoResponse((QueryInfoRequest)command, share, state));
                    }
                    else if (command is SetInfoRequest)
                    {
                        return(SetInfoHelper.GetSetInfoResponse((SetInfoRequest)command, share, state));
                    }
                    else if (command is QueryDirectoryRequest)
                    {
                        return(QueryDirectoryHelper.GetQueryDirectoryResponse((QueryDirectoryRequest)command, share, state));
                    }
                    else if (command is ReadRequest)
                    {
                        return(ReadWriteResponseHelper.GetReadResponse((ReadRequest)command, share, state));
                    }
                    else if (command is WriteRequest)
                    {
                        return(ReadWriteResponseHelper.GetWriteResponse((WriteRequest)command, share, state));
                    }
                    else if (command is LockRequest)
                    {
                        return(LockHelper.GetLockResponse((LockRequest)command, share, state));
                    }
                    else if (command is FlushRequest)
                    {
                        return(ReadWriteResponseHelper.GetFlushResponse((FlushRequest)command, share, state));
                    }
                    else if (command is CloseRequest)
                    {
                        return(CloseHelper.GetCloseResponse((CloseRequest)command, share, state));
                    }
                    else if (command is IOCtlRequest)
                    {
                        return(IOCtlHelper.GetIOCtlResponse((IOCtlRequest)command, share, state));
                    }
                    else if (command is CancelRequest)
                    {
                        return(CancelHelper.GetCancelResponse((CancelRequest)command, state));
                    }
                    else if (command is ChangeNotifyRequest)
                    {
                        return(ChangeNotifyHelper.GetChangeNotifyInterimResponse((ChangeNotifyRequest)command, share, state));
                    }
                }
            }

            return(new ErrorResponse(command.CommandName, NTStatus.STATUS_NOT_SUPPORTED));
        }
Beispiel #2
0
        private List <SMB1Command> ProcessSMB1Command(SMB1Header header, SMB1Command command, SMB1ConnectionState state)
        {
            if (command is SessionSetupAndXRequest)
            {
                SessionSetupAndXRequest request = (SessionSetupAndXRequest)command;
                state.MaxBufferSize = request.MaxBufferSize;
                return(SessionSetupHelper.GetSessionSetupResponse(header, request, m_securityProvider, state));
            }
            else if (command is SessionSetupAndXRequestExtended)
            {
                SessionSetupAndXRequestExtended request = (SessionSetupAndXRequestExtended)command;
                state.MaxBufferSize = request.MaxBufferSize;
                return(SessionSetupHelper.GetSessionSetupResponseExtended(header, request, m_securityProvider, state));
            }
            else if (command is EchoRequest)
            {
                return(EchoHelper.GetEchoResponse((EchoRequest)command));
            }
            else
            {
                SMB1Session session = state.GetSession(header.UID);
                if (session == null)
                {
                    header.Status = NTStatus.STATUS_USER_SESSION_DELETED;
                    return(new ErrorResponse(command.CommandName));
                }

                if (command is TreeConnectAndXRequest)
                {
                    return(TreeConnectHelper.GetTreeConnectResponse(header, (TreeConnectAndXRequest)command, state, m_services, m_shares));
                }
                else if (command is LogoffAndXRequest)
                {
                    state.LogToServer(Severity.Information, "Logoff: User '{0}' logged off. (UID: {1})", session.UserName, header.UID);
                    m_securityProvider.DeleteSecurityContext(ref session.SecurityContext.AuthenticationContext);
                    state.RemoveSession(header.UID);
                    return(new LogoffAndXResponse());
                }
                else
                {
                    ISMBShare share = session.GetConnectedTree(header.TID);
                    if (share == null)
                    {
                        state.LogToServer(Severity.Verbose, "{0} failed. Invalid TID (UID: {1}, TID: {2}).", command.CommandName, header.UID, header.TID);
                        header.Status = NTStatus.STATUS_SMB_BAD_TID;
                        return(new ErrorResponse(command.CommandName));
                    }

                    if (command is CreateDirectoryRequest)
                    {
                        return(FileStoreResponseHelper.GetCreateDirectoryResponse(header, (CreateDirectoryRequest)command, share, state));
                    }
                    else if (command is DeleteDirectoryRequest)
                    {
                        return(FileStoreResponseHelper.GetDeleteDirectoryResponse(header, (DeleteDirectoryRequest)command, share, state));
                    }
                    else if (command is CloseRequest)
                    {
                        return(CloseHelper.GetCloseResponse(header, (CloseRequest)command, share, state));
                    }
                    else if (command is FlushRequest)
                    {
                        return(ReadWriteResponseHelper.GetFlushResponse(header, (FlushRequest)command, share, state));
                    }
                    else if (command is DeleteRequest)
                    {
                        return(FileStoreResponseHelper.GetDeleteResponse(header, (DeleteRequest)command, share, state));
                    }
                    else if (command is RenameRequest)
                    {
                        return(FileStoreResponseHelper.GetRenameResponse(header, (RenameRequest)command, share, state));
                    }
                    else if (command is QueryInformationRequest)
                    {
                        return(FileStoreResponseHelper.GetQueryInformationResponse(header, (QueryInformationRequest)command, share, state));
                    }
                    else if (command is SetInformationRequest)
                    {
                        return(FileStoreResponseHelper.GetSetInformationResponse(header, (SetInformationRequest)command, share, state));
                    }
                    else if (command is ReadRequest)
                    {
                        return(ReadWriteResponseHelper.GetReadResponse(header, (ReadRequest)command, share, state));
                    }
                    else if (command is WriteRequest)
                    {
                        return(ReadWriteResponseHelper.GetWriteResponse(header, (WriteRequest)command, share, state));
                    }
                    else if (command is CheckDirectoryRequest)
                    {
                        return(FileStoreResponseHelper.GetCheckDirectoryResponse(header, (CheckDirectoryRequest)command, share, state));
                    }
                    else if (command is WriteRawRequest)
                    {
                        // [MS-CIFS] 3.3.5.26 - Receiving an SMB_COM_WRITE_RAW Request:
                        // the server MUST verify that the Server.Capabilities include CAP_RAW_MODE,
                        // If an error is detected [..] the Write Raw operation MUST fail and
                        // the server MUST return a Final Server Response [..] with the Count field set to zero.
                        return(new WriteRawFinalResponse());
                    }
                    else if (command is SetInformation2Request)
                    {
                        return(FileStoreResponseHelper.GetSetInformation2Response(header, (SetInformation2Request)command, share, state));
                    }
                    else if (command is LockingAndXRequest)
                    {
                        return(LockingHelper.GetLockingAndXResponse(header, (LockingAndXRequest)command, share, state));
                    }
                    else if (command is OpenAndXRequest)
                    {
                        return(OpenAndXHelper.GetOpenAndXResponse(header, (OpenAndXRequest)command, share, state));
                    }
                    else if (command is ReadAndXRequest)
                    {
                        return(ReadWriteResponseHelper.GetReadResponse(header, (ReadAndXRequest)command, share, state));
                    }
                    else if (command is WriteAndXRequest)
                    {
                        return(ReadWriteResponseHelper.GetWriteResponse(header, (WriteAndXRequest)command, share, state));
                    }
                    else if (command is FindClose2Request)
                    {
                        return(CloseHelper.GetFindClose2Response(header, (FindClose2Request)command, state));
                    }
                    else if (command is TreeDisconnectRequest)
                    {
                        return(TreeConnectHelper.GetTreeDisconnectResponse(header, (TreeDisconnectRequest)command, share, state));
                    }
                    else if (command is TransactionRequest) // Both TransactionRequest and Transaction2Request
                    {
                        return(TransactionHelper.GetTransactionResponse(header, (TransactionRequest)command, share, state));
                    }
                    else if (command is TransactionSecondaryRequest) // Both TransactionSecondaryRequest and Transaction2SecondaryRequest
                    {
                        return(TransactionHelper.GetTransactionResponse(header, (TransactionSecondaryRequest)command, share, state));
                    }
                    else if (command is NTTransactRequest)
                    {
                        return(NTTransactHelper.GetNTTransactResponse(header, (NTTransactRequest)command, share, state));
                    }
                    else if (command is NTTransactSecondaryRequest)
                    {
                        return(NTTransactHelper.GetNTTransactResponse(header, (NTTransactSecondaryRequest)command, share, state));
                    }
                    else if (command is NTCreateAndXRequest)
                    {
                        return(NTCreateHelper.GetNTCreateResponse(header, (NTCreateAndXRequest)command, share, state));
                    }
                    else if (command is NTCancelRequest)
                    {
                        CancelHelper.ProcessNTCancelRequest(header, (NTCancelRequest)command, share, state);
                        // [MS-CIFS] The SMB_COM_NT_CANCEL command MUST NOT send a response.
                        return(new List <SMB1Command>());
                    }
                }
            }

            header.Status = NTStatus.STATUS_SMB_BAD_COMMAND;
            return(new ErrorResponse(command.CommandName));
        }