Ejemplo n.º 1
0
        private bool IsErrorPacket(Packet_Header header)
        {
            switch (header.Status)
            {
            case Smb2Status.STATUS_SUCCESS:
                return(false);

            case Smb2Status.STATUS_MORE_PROCESSING_REQUIRED:
                return((header.Command != Smb2Command.SESSION_SETUP) ? true : false);

            case Smb2Status.STATUS_BUFFER_OVERFLOW:
                // STATUS_BUFFER_OVERFLOW is not an error packet because:
                // (1) The Sev bit is STATUS_SEVERITY_WARNING, not error (According to [MS-ERREF] 2.3 NTSTATUS.)
                // (2) It contains response data in its payload data.
                return(false);

            case Smb2Status.STATUS_NOTIFY_ENUM_DIR:
            case Smb2Status.STATUS_NOTIFY_CLEANUP:
                return(header.Command != Smb2Command.CHANGE_NOTIFY);

            default:
                //other error response like STATUS_INVALID_PARAMETER
                return(true);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method will send ComNegotiate request before sending a Negotiate request to simulate windows client behaviour.
        /// If ComNegotiate failed, the Negotiate request will still be sent.
        /// </summary>
        public uint MultiProtocolNegotiate(
            Smb2Client client,
            ushort creditCharge,
            ushort creditRequest,
            Packet_Header_Flags_Values flags,
            ulong messageId,
            DialectRevision[] dialects,
            SecurityMode_Values securityMode,
            Capabilities_Values capabilities,
            Guid clientGuid,
            out DialectRevision selectedDialect,
            out byte[] gssToken,
            out Packet_Header responseHeader,
            out NEGOTIATE_Response responsePayload)
        {
            uint status = client.MultiProtocolNegotiate(
                new string[] { "SMB 2.002", "SMB 2.???" },
                out selectedDialect,
                out gssToken,
                out responseHeader,
                out responsePayload);

            if (responseHeader.Status != Smb2Status.STATUS_SUCCESS)
            {
                LogFailedStatus("ComNegotiate", responseHeader.Status);
            }


            PreauthIntegrityHashID[] preauthHashAlgs = null;
            EncryptionAlgorithm[]    encryptionAlgs  = null;

            // For back compatibility, if dialects contains SMB 3.11, preauthentication integrity context should be present.
            if (Array.IndexOf(dialects, DialectRevision.Smb311) >= 0)
            {
                preauthHashAlgs = new PreauthIntegrityHashID[] { PreauthIntegrityHashID.SHA_512 };
                encryptionAlgs  = new EncryptionAlgorithm[] {
                    EncryptionAlgorithm.ENCRYPTION_AES128_GCM,
                    EncryptionAlgorithm.ENCRYPTION_AES128_CCM
                };
            }

            status = client.Negotiate(
                creditCharge,
                creditRequest,
                flags,
                messageId,
                dialects,
                securityMode,
                capabilities,
                clientGuid,
                out selectedDialect,
                out gssToken,
                out responseHeader,
                out responsePayload,
                0,
                preauthHashAlgs,
                encryptionAlgs);

            return(status);
        }
Ejemplo n.º 3
0
        public void ComNegotiateRequest(Sequence <string> dialects)
        {
            Packet_Header      responseHeader  = new Packet_Header();
            DialectRevision    selectedDialect = DialectRevision.Smb2Unknown;
            NEGOTIATE_Response responsePayload = new NEGOTIATE_Response();

            byte[]          smb2ClientGssToken;
            ModelSmb2Status status = ModelSmb2Status.STATUS_SUCCESS;

            try
            {
                status = (ModelSmb2Status)smb2Client.MultiProtocolNegotiate(dialects.ToArray(), out selectedDialect, out smb2ClientGssToken, out responseHeader, out responsePayload);
                if (status != ModelSmb2Status.STATUS_SUCCESS)
                {
                    selectedDialect = DialectRevision.Smb2Unknown;
                }
                this.NegotiateResponse(status, selectedDialect);
                if (selectedDialect == DialectRevision.Smb2Wildcard)
                {
                    messageId = 1;
                }
            }
            catch
            {
            }
        }
        private void OnOplockBreakNotificationReceived(Packet_Header header, OPLOCK_BREAK_Notification_Packet packet)
        {
            Site.Log.Add(LogEntryKind.Debug, "OplockBreakNotification was received from server");

            Site.Assert.AreEqual(
                Smb2Command.OPLOCK_BREAK,
                header.Command,
                "The server MUST set the Command in the SMB2 header to SMB2 OPLOCK_BREAK");

            Site.Assert.AreEqual(
                0xFFFFFFFFFFFFFFFF,
                header.MessageId,
                "The server MUST set the MessageId to 0xFFFFFFFFFFFFFFFF");

            Site.Assert.AreEqual(
                (uint)0,
                header.TreeId,
                "The server MUST set the TreeId to 0");

            Site.Assert.AreEqual(
                fileId,
                packet.FileId,
                "The FileId field of the response structure MUST be set to the values from the Open structure, with the volatile part set to Open.FileId and the persistent part set to Open.DurableFileId");

            // Verify signature is set to 0 if it's not signed
            Site.Assert.AreEqual(
                true,
                BitConverter.ToUInt64(header.Signature, 0) == 0 && BitConverter.ToUInt64(header.Signature, 8) == 0,
                "The SMB2 Oplock Break Notification is sent to the client. The message MUST NOT be signed, as specified in section 3.3.4.1.1");

            OplockBreakNotification(packet.OplockLevel);
        }
        /// <summary>
        /// Handler when receive LeaseBreakNotification
        /// </summary>
        /// <param name="respHeader">Packet header in LeaseBreakNotification</param>
        /// <param name="leaseBreakNotify">Received LeaseBreakNotification</param>
        protected virtual void OnLeaseBreakNotificationReceived(Packet_Header respHeader, LEASE_BREAK_Notification_Packet leaseBreakNotify)
        {
            BaseTestSite.Log.Add(
                LogEntryKind.Debug,
                "LeaseBreakNotification was received from server");
            receivedLeaseBreakNotify = leaseBreakNotify;

            BaseTestSite.Assert.AreEqual <ulong>(
                0xFFFFFFFFFFFFFFFF,
                respHeader.MessageId,
                "Expect that the field MessageId is set to 0xFFFFFFFFFFFFFFFF.");
            BaseTestSite.Assert.AreEqual <ulong>(
                0,
                respHeader.SessionId,
                "Expect that the field SessionId is set to 0.");
            BaseTestSite.Assert.AreEqual <uint>(
                0,
                respHeader.TreeId,
                "Expect that the field TreeId is set to 0.");
            BaseTestSite.Assert.AreEqual <uint>(
                0,
                leaseBreakNotify.BreakReason,
                "Expect that the field BreakReason is set to 0.");
            BaseTestSite.Assert.AreEqual <uint>(
                0,
                leaseBreakNotify.AccessMaskHint,
                "Expect that the field AccessMaskHint is set to 0.");
            BaseTestSite.Assert.AreEqual <uint>(
                0,
                leaseBreakNotify.ShareMaskHint,
                "Expect that the field ShareMaskHint is set to 0.");

            notificationReceived.Set();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Delegate to check negotiate response header and payload in this class.
        /// </summary>
        /// <param name="responseHeader">Response header to be checked</param>
        /// <param name="response">Negotiate response payload to be checked</param>
        public void ReplayNegotiateResponseChecker(Packet_Header responseHeader, NEGOTIATE_Response response)
        {
            BaseTestSite.Assert.AreEqual(
                Smb2Status.STATUS_SUCCESS,
                responseHeader.Status,
                "Negotiation should succeed, actually server returns {0}.", Smb2Status.GetStatusCode(responseHeader.Status));

            TestConfig.CheckNegotiateCapabilities(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL, response);
        }
        private void UpdateCredit(Packet_Header header)
        {
            creditAvailable += header.CreditRequestResponse;

            if (creditAvailable < 0)
            {
                throw new InvalidOperationException("Not enough credit!");
            }
        }
Ejemplo n.º 8
0
        void PrintSequenceWindow(Packet_Header header)
        {
            Site.Log.Add(LogEntryKind.Debug, "Server grants {0} credits after {1}:", header.CreditRequestResponse, header.Command);
            Site.Log.Add(LogEntryKind.Debug, "SequenceWindow after {0}:", header.Command);

            foreach (var item in testClient.SequenceWindow)
            {
                Site.Log.Add(LogEntryKind.Debug, "\t{0}", item);
            }
        }
Ejemplo n.º 9
0
 private void OnChangeNotifyResponseReceived(FILE_NOTIFY_INFORMATION[] fileNotifyInfo, Packet_Header respHeader, CHANGE_NOTIFY_Response changeNotify)
 {
     BaseTestSite.Log.Add(
         LogEntryKind.Debug,
         "Client1 receives the response of CHANGE_NOTIFY");
     receivedChangeNotify       = changeNotify;
     receivedFileNotifyInfo     = fileNotifyInfo;
     receivedChangeNotifyHeader = respHeader;
     changeNotificationReceived.Set();
 }
 void InnerResponseChecker <T>(ResponseChecker <T> checker, Packet_Header header, T response)
 {
     if (checker != null)
     {
         checker(header, response);
     }
     else
     {
         TestClassBase.BaseTestSite.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, header.Status, "{0} should succeed", header.Command);
     }
 }
        private void CheckNegotiateResponse(
            Packet_Header header,
            NEGOTIATE_Response response,
            DialectRevision clientMaxDialectSupported,
            EncryptionAlgorithm[] encryptionAlgs)
        {
            DialectRevision expectedDialect = clientMaxDialectSupported < TestConfig.MaxSmbVersionSupported
                        ? clientMaxDialectSupported : TestConfig.MaxSmbVersionSupported;

            BaseTestSite.Assert.AreEqual(
                Smb2Status.STATUS_SUCCESS,
                header.Status,
                "{0} should succeed, actually server returns {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
            BaseTestSite.Assert.AreEqual(expectedDialect, response.DialectRevision, "Selected dialect should be {0}", expectedDialect);

            if (expectedDialect >= DialectRevision.Smb311)
            {
                BaseTestSite.Assert.AreEqual(
                    PreauthIntegrityHashID.SHA_512,
                    client.SelectedPreauthIntegrityHashID,
                    "[MS-SMB2] 3.3.5.4 The server MUST set Connection.PreauthIntegrityHashId to one of the hash algorithms " +
                    "in the client's SMB2_PREAUTH_INTEGRITY_CAPABILITIES HashAlgorithms array.");

                if (encryptionAlgs != null)
                {
                    BaseTestSite.Assert.IsTrue(
                        TestConfig.SupportedEncryptionAlgorithmList.Contains(client.SelectedCipherID),
                        "[MS-SMB2] 3.3.5.4 The server MUST set Connection.CipherId to one of the ciphers in the client's " +
                        "SMB2_ENCRYPTION_CAPABILITIES Ciphers array in an implementation-specific manner.");
                }
                else
                {
                    BaseTestSite.Assert.AreEqual(
                        EncryptionAlgorithm.ENCRYPTION_NONE,
                        client.SelectedCipherID,
                        "[MS-SMB2] if client doesn't present SMB2_ENCRYPTION_CAPABILITIES context in negotiate request, " +
                        "server should not present this context in negotiate response.");
                }
            }
            else
            {
                // If server supported dialect version is lower than 3.11, server should ignore the negotiate contexts.
                BaseTestSite.Assert.AreEqual(
                    PreauthIntegrityHashID.HashAlgorithm_NONE,
                    client.SelectedPreauthIntegrityHashID,
                    "[MS-SMB2] The server must ignore the SMB2_PREAUTH_INTEGRITY_CAPABILITIES context if Connection.Dialect is less than 3.11. ");
                BaseTestSite.Assert.AreEqual(
                    EncryptionAlgorithm.ENCRYPTION_NONE,
                    client.SelectedCipherID,
                    "[MS-SMB2] The server must ignore the SMB2_ENCRYPTION_CAPABILITIES context if Connection.Dialect is less than 3.11. ");
            }

            CheckServerCapabilities(response);
        }
        private void CheckIoCtlResponse(Packet_Header header, IOCTL_Response response)
        {
            if (header.Status != Smb2Status.STATUS_SUCCESS)
            {
                return;
            }

            FILEID ioCtlFileId;

            ioCtlFileId.Persistent = 0xFFFFFFFFFFFFFFFF;
            ioCtlFileId.Volatile   = 0xFFFFFFFFFFFFFFFF;
            Site.Assert.AreEqual(ioCtlFileId, response.FileId, "FileId MUST be set to { 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF }.");
            Site.Assert.AreEqual(0, (int)response.Flags, "Flags MUST be set to zero.");
            Site.Assert.AreEqual((uint)CtlCode_Values.FSCTL_VALIDATE_NEGOTIATE_INFO, response.CtlCode, "CtlCode MUST be set to FSCTL_VALIDATE_NEGOTIATE_INFO.");
        }
Ejemplo n.º 13
0
        private void OnOpLockBreakNotificationReceived(Packet_Header respHeader, OPLOCK_BREAK_Notification_Packet OpLockBreakNotify)
        {
            BaseTestSite.Log.Add(
                LogEntryKind.Comment,
                "OpLockBreakNotification was received from server");
            OpLockBreakNotifyReceived = OpLockBreakNotify;

            ///The FileId field of the response structure MUST be set to the values from the Open structure,
            ///with the volatile part set to Open.FileId and the persistent part set to Open.DurableFileId.
            BaseTestSite.Assert.AreEqual(fileId, OpLockBreakNotify.FileId, "FileId should be identical");

            BaseTestSite.Assert.IsTrue(
                OpLockBreakNotify.OplockLevel == OPLOCK_BREAK_Notification_Packet_OplockLevel_Values.OPLOCK_LEVEL_II ||
                OpLockBreakNotify.OplockLevel == OPLOCK_BREAK_Notification_Packet_OplockLevel_Values.OPLOCK_LEVEL_NONE,
                "The new oplock level MUST be either SMB2_OPLOCK_LEVEL_NONE or SMB2_OPLOCK_LEVEL_II.");
            OpLockNotificationReceived.Set();
        }
            protected override uint TreeConnect(ushort creditCharge, ushort creditRequest, Packet_Header_Flags_Values flags, ulong messageId, ulong sessionId,
                                                string server, string share, out Packet_Header header, out TREE_CONNECT_Response response)
            {
                uint treeConnectResponseCode = base.TreeConnect(creditCharge, creditRequest, flags, messageId, sessionId, server, share, out header, out response);

                if (supportV1)
                {
                    testSite.Assert.IsTrue(
                        response.ShareFlags.HasFlag(ShareFlags_Values.SHAREFLAG_ENABLE_HASH_V1),
                        "The share content should enable hash v1");
                }
                if (supportV2)
                {
                    testSite.Assert.IsTrue(
                        response.ShareFlags.HasFlag(ShareFlags_Values.SHAREFLAG_ENABLE_HASH_V2),
                        "The share content should enable hash v2");
                }

                return(treeConnectResponseCode);
            }
        /// <summary>
        /// Get the real treeId granted by server.
        /// </summary>
        /// <param name="header">The header of packet</param>
        /// <returns>The real treeId</returns>
        private uint GetRealTreeId(Packet_Header header)
        {
            uint treeId = header.TreeId;

            if ((header.Flags & Packet_Header_Flags_Values.FLAGS_ASYNC_COMMAND)
                == Packet_Header_Flags_Values.FLAGS_ASYNC_COMMAND)
            {
                treeId = GetTreeIdFromAsyncPacket(header);
            }

            if ((header.Flags & Packet_Header_Flags_Values.FLAGS_RELATED_OPERATIONS)
                == Packet_Header_Flags_Values.FLAGS_RELATED_OPERATIONS)
            {
                if (treeId == uint.MaxValue)
                {
                    for (int i = packets.Count - 1; i >= 0; i--)
                    {
                        if ((packets[i].Header.Flags & Packet_Header_Flags_Values.FLAGS_ASYNC_COMMAND)
                            == Packet_Header_Flags_Values.FLAGS_ASYNC_COMMAND)
                        {
                            treeId = GetTreeIdFromAsyncPacket(packets[i].Header);
                        }
                        else
                        {
                            treeId = packets[i].Header.TreeId;
                        }

                        //0xffffffff is not a real treeId
                        //keep searching the real treeId if it
                        //is oxffffffff
                        if (treeId != uint.MaxValue)
                        {
                            break;
                        }
                    }
                }
            }

            return(treeId);
        }
        /// <summary>
        /// Handle the lease break notification.
        /// </summary>
        /// <param name="respHeader">The SMB2 header included in the notification.</param>
        /// <param name="leaseBreakNotify">Lease break notification payload in the notification.</param>
        private void OnLeaseBreakNotificationReceived(Packet_Header respHeader, LEASE_BREAK_Notification_Packet leaseBreakNotify)
        {
            Smb2FunctionalClient client = null;

            if (smb2ClientMainChannel != null)
            {
                client = smb2ClientMainChannel;
            }
            else if (smb2ClientAlternativeChannel != null)
            {
                client = smb2ClientAlternativeChannel;
            }

            if (client != null)
            {
                Site.Log.Add(LogEntryKind.Debug, "Receive a lease break notification and will send lease break acknowledgment.");
                client.LeaseBreakAcknowledgment(
                    treeIdMainChannel,
                    leaseKeyMainChannel,
                    leaseBreakNotify.NewLeaseState);
            }
        }
        /// <summary>
        /// Get the real sessionId granted by server.
        /// </summary>
        /// <param name="header">The header of packet</param>
        /// <returns>The real sessionId</returns>
        private ulong GetRealSessionId(Packet_Header header)
        {
            ulong sessionId = header.SessionId;

            if ((header.Flags & Packet_Header_Flags_Values.FLAGS_RELATED_OPERATIONS)
                == Packet_Header_Flags_Values.FLAGS_RELATED_OPERATIONS)
            {
                if (header.SessionId == ulong.MaxValue)
                {
                    for (int i = packets.Count - 1; i >= 0; i--)
                    {
                        if (packets[i].Header.SessionId != ulong.MaxValue)
                        {
                            sessionId = packets[i].Header.SessionId;
                            break;
                        }
                    }
                }
            }

            return(sessionId);
        }
        /// <summary>
        /// Verify the signature of a Smb2CompoundPacket
        /// </summary>
        /// <param name="packet">The compound packet to be verified</param>
        /// <returns>True when signature verification succeeds and false when fails</returns>
        private bool TryVerifySignature(Smb2CompoundPacket packet)
        {
            try
            {
                Packet_Header header = TypeMarshal.ToStruct <Packet_Header>(packet.ToBytes());

                if ((header.Flags & Packet_Header_Flags_Values.FLAGS_RELATED_OPERATIONS)
                    == Packet_Header_Flags_Values.FLAGS_RELATED_OPERATIONS)
                {
                    //The realSessionId is the sessionId in the first pacekt of the compoundpacket for related packets.
                    ulong realSessionId = packet.Packets[0].Header.SessionId;
                    for (int i = 0; i < packet.Packets.Count; i++)
                    {
                        Smb2SinglePacket singlePacket = packet.Packets[i];
                        if (!TryVerifySignature(singlePacket, realSessionId))
                        {
                            break;
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < packet.Packets.Count; i++)
                    {
                        Smb2SinglePacket singlePacket = packet.Packets[i];
                        if (!TryVerifySignature(singlePacket, singlePacket.Header.SessionId))
                        {
                            break;
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw new Exception("Error happened during signature verification of compound packet: " + packet.ToString() + ". Exception message:" + ex.Message);
            }
        }
Ejemplo n.º 19
0
        public void NegotiateRequest(Sequence <DialectRevision> dialects)
        {
            Packet_Header      responseHeader  = new Packet_Header();
            DialectRevision    selectedDialect = DialectRevision.Smb2Unknown;
            NEGOTIATE_Response responsePayload = new NEGOTIATE_Response();

            byte[]          smb2ClientGssToken;
            ModelSmb2Status status = ModelSmb2Status.STATUS_SUCCESS;

            try
            {
                status = (ModelSmb2Status)smb2Client.Negotiate(0, 1, Packet_Header_Flags_Values.NONE, messageId++, dialects.ToArray(), SecurityMode_Values.NONE, Capabilities_Values.NONE, Guid.NewGuid(),
                                                               out selectedDialect, out smb2ClientGssToken, out responseHeader, out responsePayload);
                if (status != ModelSmb2Status.STATUS_SUCCESS)
                {
                    selectedDialect = DialectRevision.Smb2Unknown;
                }
                this.NegotiateResponse(status, selectedDialect);
            }
            catch
            {
            }
        }
Ejemplo n.º 20
0
            protected override uint TreeConnect(ushort creditCharge, ushort creditRequest, Packet_Header_Flags_Values flags, ulong messageId, ulong sessionId,
                                                string server, string share, out Packet_Header header, out TREE_CONNECT_Response response)
            {
                uint treeConnectResponseCode = base.TreeConnect(
                    creditCharge,
                    creditRequest,
                    flags,
                    messageId,
                    sessionId,
                    server,
                    share,
                    out header,
                    out response);

                this.isShareHashEnabled = response.ShareFlags.HasFlag(ShareFlags_Values.SHAREFLAG_ENABLE_HASH_V1) ||
                                          response.ShareFlags.HasFlag(ShareFlags_Values.SHAREFLAG_ENABLE_HASH_V2);
                BaseTestSite.Assert.AreEqual(
                    true,
                    this.isShareHashEnabled,
                    "The share folder should enable hash V1 or hash V2");

                return(treeConnectResponseCode);
            }
        /// <summary>
        /// Handle the oplock break notification.
        /// </summary>
        /// <param name="respHeader">The SMB2 header included in the notification.</param>
        /// <param name="oplockBreakNotify">Oplock break notification payload in the notification.</param>
        private void OnOplockBreakNotificationReceived(Packet_Header respHeader, OPLOCK_BREAK_Notification_Packet oplockBreakNotify)
        {
            Smb2FunctionalClient client = null;

            if (smb2ClientMainChannel != null)
            {
                client = smb2ClientMainChannel;
            }
            else if (smb2ClientAlternativeChannel != null)
            {
                client = smb2ClientAlternativeChannel;
            }

            if (client != null)
            {
                Site.Log.Add(LogEntryKind.Debug, "Receive an oplock break notification and will send oplock break acknowledgment.");
                client.OplockAcknowledgement(
                    treeIdMainChannel,
                    fileIdMainChannel,
                    (OPLOCK_BREAK_Acknowledgment_OplockLevel_Values)oplockBreakNotify.OplockLevel,
                    checker: (responseHeader, response) => { }
                    );
            }
        }
        /// <summary>
        /// Check the status code of create response
        /// </summary>
        /// <param name="isNonAdmin">true for non admin credential</param>
        /// <param name="createOption">The create option set in create request</param>
        /// <param name="accessMask">The access mark set in create request</param>
        /// <param name="header">Header of create response</param>
        /// <param name="response">create response</param>
        /// <param name="fileNameType">file name type</param>
        private void CheckCreateResponse(bool isNonAdmin, CreateOptions_Values createOption, AccessMask accessMask, Packet_Header header, CREATE_Response response, FileNameType fileNameType)
        {
            switch (fileNameType)
            {
            case FileNameType.SymbolicLinkInMiddle:
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_STOPPED_ON_SYMLINK,
                    header.Status,
                    "3.3.5.9: If any intermediate component of the path specified in the create request is a symbolic link, " +
                    "the server MUST return an error as specified in section 2.2.2.1. " +
                    "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                break;
            }

            case FileNameType.SymbolicLinkAtLast:
            {
                if (!createOption.HasFlag(CreateOptions_Values.FILE_OPEN_REPARSE_POINT))
                {
                    BaseTestSite.Assert.AreEqual(
                        Smb2Status.STATUS_STOPPED_ON_SYMLINK,
                        header.Status,
                        "3.3.5.9: If the final component of the path is a symbolic link, the server behavior depends on whether the flag FILE_OPEN_REPARSE_POINT was specified in the CreateOptions field of the request. " +
                        "If FILE_OPEN_REPARSE_POINT was specified, the server MUST open the underlying file or directory and return a handle to it. " +
                        "Otherwise, the server MUST return an error as specified in section 2.2.2.1. " +
                        "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                }
                break;
            }

            case FileNameType.InvalidSymbolicLink:
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_STOPPED_ON_SYMLINK,
                    header.Status,
                    "3.3.5.9: If the underlying object store returns a failure indicating that the attempted open operation failed due to the presence of a symbolic link in the target path name, " +
                    "the server MUST fail the create operation with the error code STATUS_STOPPED_ON_SYMLINK. " +
                    "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                break;
            }

            case FileNameType.NotExistedValidFileName:
            {
                if (createOption.HasFlag(CreateOptions_Values.FILE_DELETE_ON_CLOSE) &&
                    !(accessMask.HasFlag(AccessMask.DELETE) || accessMask.HasFlag(AccessMask.GENERIC_ALL)))
                {
                    if (testConfig.Platform == Platform.NonWindows)
                    {
                        BaseTestSite.Assert.AreNotEqual(
                            Smb2Status.STATUS_SUCCESS,
                            header.Status,
                            "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and Treeconnect.MaximalAccess does not include DELETE or GENERIC, the server SHOULD<283> fail the request with STATUS_ACCESS_DENIED. " +
                            "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    }
                    else if (testConfig.Platform == Platform.WindowsServer2008 ||
                             testConfig.Platform == Platform.WindowsServer2008R2)
                    {
                        //TD does not specify the behavior of windows 2008 and 2008R2, not check here
                    }
                    else if (testConfig.Platform == Platform.WindowsServer2012)
                    {
                        //For platform windows 2012
                        BaseTestSite.Assert.AreEqual(
                            Smb2Status.STATUS_INVALID_PARAMETER,
                            header.Status,
                            "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and Treeconnect.MaximalAccess does not include DELETE or GENERIC, the server SHOULD<283> fail the request with STATUS_ACCESS_DENIED. " +
                            "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    }
                    else
                    {
                        //For platform windows 2012R2 and above
                        BaseTestSite.Assert.AreEqual(
                            Smb2Status.STATUS_ACCESS_DENIED,
                            header.Status,
                            "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and Treeconnect.MaximalAccess does not include DELETE or GENERIC, the server SHOULD<283> fail the request with STATUS_ACCESS_DENIED. " +
                            "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    }
                }
                else if (createOption.HasFlag(CreateOptions_Values.FILE_DELETE_ON_CLOSE) && isNonAdmin)
                {
                    //NonAdminAccountCredential does not include DELETE or GENERIC_ALL in MaximalAccess
                    if (testConfig.Platform == Platform.NonWindows)
                    {
                        BaseTestSite.Assert.AreNotEqual(
                            Smb2Status.STATUS_SUCCESS,
                            header.Status,
                            "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and Treeconnect.MaximalAccess does not include DELETE or GENERIC, the server SHOULD<283> fail the request with STATUS_ACCESS_DENIED. " +
                            "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    }
                    else if (testConfig.Platform == Platform.WindowsServer2008 ||
                             testConfig.Platform == Platform.WindowsServer2008R2)
                    {
                        //TD does not specify te behavior of windows 2008 and 2008R2, not check here
                    }
                    else
                    {
                        //For platform win2012 and 2012R2
                        BaseTestSite.Assert.AreEqual(
                            Smb2Status.STATUS_ACCESS_DENIED,
                            header.Status,
                            "3.3.5.9: If the FILE_DELETE_ON_CLOSE flag is set in CreateOptions and Treeconnect.MaximalAccess does not include DELETE or GENERIC, the server SHOULD<283> fail the request with STATUS_ACCESS_DENIED. " +
                            "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    }
                }
                else
                {
                    BaseTestSite.Assert.AreEqual(
                        Smb2Status.STATUS_SUCCESS,
                        header.Status,
                        "{0} should be successful, actually server returns with {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
                }
                break;
            }

            case FileNameType.ExistedValidFileName:
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_SUCCESS,
                    header.Status,
                    "{0} should be successful, actually server returns with {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
            }
            break;

            case FileNameType.NotExistedValidFileNameWithDotDirectoryName:
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_SUCCESS,
                    header.Status,
                    "{0} should be successful, actually server returns with {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
            }
            break;

            case FileNameType.NotExistedValidFileNameWithDoubleDotDirectoryName:
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_INVALID_PARAMETER,
                    header.Status,
                    "3.3.5.9: Windows-based servers accept the path names containing Dot Directory Names specified in [MS-FSCC] section 2.1.5.1 and attempt to normalize the path name by removing the pathname components of \".\"  and \"..\"." +
                    "Windows-based servers fail the CREATE request with STATUS_INVALID_PARAMETER if the file name in the Buffer field of the request begins in the form \"subfolder\\..\\\", for example \"x\\..\\y.txt\". " +
                    "Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
            }
            break;

            default:
                throw new ArgumentException("fileNameType");
            }
        }
Ejemplo n.º 23
0
 protected override uint Negotiate(ushort creditCharge, ushort creditRequest, ulong messageId, Guid clientGuid,
                                   out DialectRevision selectedDialect, out byte[] gssToken, out Packet_Header responseHeader, out NEGOTIATE_Response responsePayload)
 {
     return(client.Negotiate(
                creditCharge,
                creditRequest,
                Packet_Header_Flags_Values.NONE,
                messageId,
                new DialectRevision[] { this.dialect },
                SecurityMode_Values.NONE,
                Capabilities_Values.NONE,
                clientGuid,
                out selectedDialect,
                out gssToken,
                out responseHeader,
                out responsePayload));
 }
 private void OnLeaseBreakNotificationReceived(Packet_Header header, LEASE_BREAK_Notification_Packet notification)
 {
     // Set Lease break state
     breakType = ModelBreakType.LeaseBreak;
     leaseClient.LeaseBreakAcknowledgment(treeIdLease, notification.LeaseKey, notification.NewLeaseState);
 }
 private void OnLeaseBreakNotificationReceived(Packet_Header header, OPLOCK_BREAK_Notification_Packet notification)
 {
     breakType = ModelBreakType.OplockBreak;
     oplockClient.OplockAcknowledgement(treeIdOplock, notification.FileId, (OPLOCK_BREAK_Acknowledgment_OplockLevel_Values)notification.OplockLevel);
 }
Ejemplo n.º 26
0
 private void SkipResponseCheck <T>(Packet_Header header, T response)
 {
     // Do nothing, Used to skip check
 }
 protected override void OnLeaseBreakNotificationReceived(Packet_Header respHeader, LEASE_BREAK_Notification_Packet leaseBreakNotify)
 {
     BaseTestSite.Log.Add(LogEntryKind.Debug, "LeaseBreakNotification was received from server");
     isLeaseBreakReceived = true;
 }
        /// <summary>
        /// Build a Smb2Packet from a byte array
        /// </summary>
        /// <param name="data">The byte array</param>
        /// <param name="consumedLen">The consumed data length</param>
        /// <param name="expectedLen">The expected data length</param>
        /// <returns>The Smb2Packet</returns>
        internal override void FromBytes(byte[] data, out int consumedLen, out int expectedLen)
        {
            this.Packets = new List <Smb2SinglePacket>();

            Packet_Header header = TypeMarshal.ToStruct <Packet_Header>(data);

            int innerConsumedLen = 0;
            int innerExpectedLen = 0;

            consumedLen = 0;

            byte[]           temp         = null;
            Smb2SinglePacket singlePacket = null;

            while (header.NextCommand != 0)
            {
                temp = new byte[header.NextCommand];

                Array.Copy(data, consumedLen, temp, 0, temp.Length);
                singlePacket = decoder.DecodeSinglePacket(
                    temp,
                    decoder.DecodeRole,
                    GetRealSessionId(header),
                    GetRealTreeId(header),
                    out innerConsumedLen,
                    out innerExpectedLen
                    ) as Smb2SinglePacket;
                singlePacket.OuterCompoundPacket = this;
                singlePacket.IsInCompoundPacket  = true;
                singlePacket.IsLast = false;

                Packets.Add(singlePacket);

                //If a packet is in compound packet, there may be some padding at the end,
                //here we do not rely on the innerConsumedLen but header.NextCommand
                consumedLen += temp.Length;

                header = TypeMarshal.ToStruct <Packet_Header>(ArrayUtility.SubArray(data, consumedLen));
            }

            temp = new byte[data.Length - consumedLen];
            Array.Copy(data, consumedLen, temp, 0, temp.Length);

            singlePacket = decoder.DecodeSinglePacket(
                temp,
                decoder.DecodeRole,
                GetRealSessionId(header),
                GetRealTreeId(header),
                out innerConsumedLen,
                out innerExpectedLen
                ) as Smb2SinglePacket;

            singlePacket.OuterCompoundPacket = this;
            singlePacket.IsInCompoundPacket  = true;
            singlePacket.IsLast = true;

            Packets.Add(singlePacket);

            consumedLen += innerConsumedLen;
            expectedLen  = 0;
        }
 private void OnLeaseBreakNotificationReceived(Packet_Header header, LEASE_BREAK_Notification_Packet notification)
 {
     // Set Lease breake state
     leaseBreakState = LeaseBreakState.LeaseBreakExisted;
 }
 /// <summary>
 /// Get treeId from the async packet
 /// </summary>
 /// <param name="header">The packet header</param>
 /// <returns>The treeId</returns>
 private uint GetTreeIdFromAsyncPacket(Packet_Header header)
 {
     throw new NotImplementedException();
 }