/// <summary>
        /// expect transport event from transport.<para/>
        /// if event arrived and packet data buffer is empty, return event directly.<para/>
        /// decode packet from packet data buffer, return packet if arrived, otherwise, return event.
        /// </summary>
        /// <param name="timeout">
        /// a TimeSpan struct that specifies the timeout of waiting for a packet or event from the transport.
        /// </param>
        /// <returns>
        /// a TransportEvent object that contains the expected event from transport.
        /// </returns>
        /// <exception cref="TimeoutException">
        /// thrown when timeout to wait for packet coming.
        /// </exception>
        /// <exception cref="TimeoutException">
        /// thrown when timeout to wait for event coming.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when stream client is not connected, must invoke Connect() first.
        /// </exception>
        public TransportEvent ExpectTransportEvent(TimeSpan timeout)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("StreamTransport");
            }

            if (this.thread == null)
            {
                throw new InvalidOperationException(
                          "stream client is not connected, must invoke Connect() first.");
            }

            // decode packet
            StackPacket packet = this.ExpectPacket(timeout);

            // if packet is decoded, return it.
            if (packet != null)
            {
                return(new TransportEvent(
                           EventType.ReceivedPacket, this.localEndPoint, null, this.localEndPoint, packet));
            }

            // if no packet, and there is event coming, return event.
            // set timeout to zero, must not wait for event coming.
            return(eventQueue.Dequeue(new TimeSpan()));
        }
        /// <summary>
        /// expect transport event from transport.<para/>
        /// if event arrived and packet data buffer is empty, return event directly.<para/>
        /// decode packet from packet data buffer, return packet if arrived, otherwise, return event.
        /// </summary>
        /// <param name="timeout">
        /// a TimeSpan struct that specifies the timeout of waiting for a packet or event from the transport.
        /// </param>
        /// <returns>
        /// a TransportEvent object that contains the expected event from transport.
        /// </returns>
        /// <exception cref="TimeoutException">
        /// thrown when timeout to wait for packet coming.
        /// </exception>
        /// <exception cref="TimeoutException">
        /// thrown when timeout to wait for event coming.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when the udp client is not connected to server, must invoke Start() first.
        /// </exception>
        public TransportEvent ExpectTransportEvent(TimeSpan timeout)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("UdpClientTransport");
            }

            if (this.udpClient == null)
            {
                throw new InvalidOperationException("udp client is not start, must invoke Start() first.");
            }

            try
            {
                object localEP  = this.LspHookedLocalEP;
                object remoteEP = null;

                // decode packet
                StackPacket packet = this.GetPacket(timeout, true, out remoteEP);

                // if packet is decoded, return it.
                return(new TransportEvent(EventType.ReceivedPacket, remoteEP, localEP, packet));
            }
            catch (InvalidOperationException exc)
            {
                if (exc.Data.Count == 0)
                {
                    throw;
                }
            }

            // if no packet, and there is event coming, return event.
            // set timeout to zero, must not wait for event coming.
            return(eventQueue.Dequeue(new TimeSpan()));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Method provided to socket, which can use it to send packet
 /// </summary>
 /// <param name="remoteEP">Remote endpoint</param>
 /// <param name="packet"></param>
 private void PacketSender(IPEndPoint remoteEP, StackPacket packet)
 {
     if (started)
     {
         udpTransport.SendPacket(localEndPoint, remoteEP, packet);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Method provided to socket, which can use it to send packet
 /// </summary>
 /// <param name="remoteEP">Remote endpoint</param>
 /// <param name="packet"></param>
 private void packetsender(IPEndPoint remoteEP, StackPacket packet)
 {
     if (running)
     {
         udpTransport.SendPacket(localEndPoint, remoteEP, packet);
     }
 }
        /// <summary>
        /// expect transport event from transport.<para/>
        /// if event arrived and packet data buffer is empty, return event directly.<para/>
        /// decode packet from packet data buffer, return packet if arrived, otherwise, return event.
        /// </summary>
        /// <param name="timeout">
        /// a TimeSpan struct that specifies the timeout of waiting for a packet or event from the transport.
        /// </param>
        /// <returns>
        /// a TransportEvent object that contains the expected event from transport.
        /// </returns>
        /// <exception cref="TimeoutException">
        /// thrown when timeout to wait for packet coming.
        /// </exception>
        /// <exception cref="TimeoutException">
        /// thrown when timeout to wait for event coming.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when tcp client is not connected to server, must invoke Connect() first.
        /// </exception>
        public TransportEvent ExpectTransportEvent(TimeSpan timeout)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("TcpClientTransport");
            }

            if (this.stream == null)
            {
                throw new InvalidOperationException(
                          "tcp client is not connected to server, must invoke Connect() first.");
            }

            // decode packet
            StackPacket packet = this.ExpectPacket(timeout);

            // if packet is decoded, return it.
            if (packet != null)
            {
                return(new TransportEvent(
                           EventType.ReceivedPacket, this.localEndPoint, this.remoteEndPoint, this.localEndPoint, packet));
            }

            // eventQueue == null which should only happens in dispose during disconnect
            // Temporally adding wait loop would avoid calling on the null object
            while (eventQueue == null)
            {
                System.Threading.Thread.Sleep(100);
            }

            // if no packet, and there is event coming, return event.
            // set timeout to zero, must not wait for event coming.
            return(eventQueue.Dequeue(new TimeSpan()));
        }
        /// <summary>
        /// Send a packet over the transport.<para/>
        /// the underlayer transport must be TcpClient, Stream or NetbiosClient.
        /// </summary>
        /// <param name="packet">
        /// a StackPacket object that contains the packet to send to target.
        /// </param>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when tcp client is not connected to server, must invoke Connect() first.
        /// </exception>
        public void SendPacket(StackPacket packet)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("TcpClientTransport");
            }

            this.SendBytes(packet.ToBytes());
        }
 /// <summary>
 /// Process a static virtual channel received
 /// </summary>
 /// <param name="packet"></param>
 public override void ReceivePackets(StackPacket packet)
 {
     if (packet is Virtual_Channel_RAW_Pdu)
     {
         Virtual_Channel_Complete_Pdu reassembledPacket = ReassembleChunkData(packet as Virtual_Channel_RAW_Pdu);
         if (reassembledPacket != null)
         {
             ProcessSVCData(reassembledPacket.virtualChannelData);
         }
     }
 }
 /// <summary>
 /// Process a static virtual channel received
 /// </summary>
 /// <param name="packet"></param>
 public override void ReceivePackets(StackPacket packet)
 {
     if (packet is Virtual_Channel_RAW_Server_Pdu)
     {
         Virtual_Channel_Complete_Server_Pdu reassembledPacket = ReassembleChunkData(packet as Virtual_Channel_RAW_Server_Pdu);
         if (reassembledPacket != null)
         {
             ProcessSVCData(reassembledPacket.virtualChannelData);
         }
     }
 }
        /// <summary>
        /// Send a packet over the transport.<para/>
        /// the underlayer transport must be TcpClient, UdpClient, Stream or NetbiosClient.<para/>
        /// the UdpClient will send data to the remote endpoint that stored in config.
        /// </summary>
        /// <param name="packet">
        /// a StackPacket object that contains the packet to send to target.
        /// </param>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when udp client is not start, must invoke Start() first.
        /// </exception>
        public void SendPacket(StackPacket packet)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("UdpClientTransport");
            }

            if (this.udpClient == null)
            {
                throw new InvalidOperationException("udp client is not start, must invoke Start() first.");
            }

            this.SendBytes(packet.ToBytes());
        }
        /// <summary>
        /// Send a packet over the transport.<para/>
        /// the underlayer transport must be TcpClient, Stream or NetbiosClient.
        /// </summary>
        /// <param name="packet">
        /// a StackPacket object that contains the packet to send to target.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// thrown when packet is null
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when stream client is not connected, must invoke Connect() first.
        /// </exception>
        public void SendPacket(StackPacket packet)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("StreamTransport");
            }

            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }

            this.SendBytes(packet.ToBytes());
        }
Exemplo n.º 11
0
        /// <summary>
        /// Expect a static virtual channel Packet
        /// </summary>
        /// <param name="timeout"></param>
        /// <param name="channelId"></param>
        /// <returns></returns>
        public override StackPacket ExpectPacket(TimeSpan timeout, out UInt16 channelId)
        {
            DateTime endTime = DateTime.Now + timeout;

            channelId = 0;
            while (DateTime.Now < endTime)
            {
                StackPacket pdu = context.Client.ExpectChannelPdu(endTime - DateTime.Now);
                if (pdu is Virtual_Channel_RAW_Server_Pdu)
                {
                    channelId = (pdu as Virtual_Channel_RAW_Server_Pdu).commonHeader.channelId;
                    return(pdu);
                }
            }
            return(null);
        }
Exemplo n.º 12
0
        /// <summary>
        /// expect packet from transport.<para/>
        /// the underlayer transport must be TcpClient, Stream or NetbiosClient.
        /// </summary>
        /// <param name="timeout">
        /// a TimeSpan object that indicates the timeout to expect event.
        /// </param>
        /// <returns>
        /// a StackPacket object that specifies the received packet.
        /// </returns>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when stream client is not connected, must invoke Connect() first.
        /// </exception>
        public StackPacket ExpectPacket(TimeSpan timeout)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("StreamTransport");
            }

            if (this.stream == null)
            {
                throw new InvalidOperationException(
                          "stream client is not connected, must invoke Connect() first.");
            }


            StackPacket packet = packetCache.Dequeue(timeout);

            return(packet);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Method used to process a received packet
        /// </summary>
        /// <param name="packet"></param>
        public void ReceivePacket(StackPacket packet)
        {
            // Transfer packet to
            RdpeudpPacket eudpPacket = new RdpeudpPacket();

            byte[] packetBytes = packet.ToBytes();
            if (!PduMarshaler.Unmarshal(packetBytes, eudpPacket, false))
            {
                return;
            }

            // ETW Provider Dump Message
            string messageName = "RDPEUDP:ReceivedPDU";

            ExtendedLogger.DumpMessage(messageName, DumpLevel_LayerTLS, eudpPacket.GetType().Name, packetBytes);

            ReceivePacket(eudpPacket);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Send a packet to a special remote host.<para/>
        /// the transport must be UdpServer
        /// </summary>
        /// <param name="localEndPoint">
        /// an object that specifies the local endpoint to send bytes.
        /// </param>
        /// <param name="remoteEndPoint">
        /// an object that specifies the target endpoint to which send packet.
        /// </param>
        /// <param name="packet">
        /// a StackPacket object that contains the packet to send to target.
        /// </param>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when the server is not started, must invoke Start() first.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// thrown when remoteEndPoint is null.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when udp server is not start, must invoke Start() first.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// thrown when the specified endpoint is not an IPEndPoint.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when udp server is not start, must invoke Start() first.
        /// </exception>
        public void SendPacket(object localEndPoint, object remoteEndPoint, StackPacket packet)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("UdpServerTransport");
            }

            if (!this.started)
            {
                throw new InvalidOperationException("server is not started, must invoke Start() first.");
            }

            if (this.listeners.Count == 0)
            {
                throw new InvalidOperationException("udp server is not start, must invoke Start() first.");
            }

            this.SendBytes(localEndPoint, remoteEndPoint, packet.ToBytes());
        }
Exemplo n.º 15
0
        /// <summary>
        /// Expect transport event from transport.
        /// if event arrived and packet data buffer is empty, return event directly.
        /// decode packet from packet data buffer, return packet if arrived, otherwise, return event.
        /// </summary>
        /// <param name="timeout">
        /// TimeSpan struct that specifies the timeout of waiting for a  packet or event from the transport.
        /// </param>
        /// <returns>
        /// TransportEvent object that contains the expected event from transport.
        /// </returns>
        /// <exception cref="ObjectDisposedException">
        /// Thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// Thrown when the under layer transport is null! the config for TransportStack is invalid.
        /// </exception>
        public TransportEvent ExpectTransportEvent(TimeSpan timeout)
        {
            TransportEvent eventPacket = this.packetQueue.GetObject(ref timeout) as TransportEvent;

            if (eventPacket == null)
            {
                throw new InvalidOperationException("Invalid object are cached in the queue.");
            }

            if (eventPacket.EventType == EventType.ReceivedPacket)
            {
                StackPacket packet = eventPacket.EventObject as StackPacket;
            }
            else if (eventPacket.EventType == EventType.Exception)
            {
                throw new InvalidOperationException(
                          "There's an exception thrown when receiving a packet.",
                          (Exception)eventPacket.EventObject);
            }

            return(eventPacket);
        }
        /// <summary>
        /// Receive loop
        /// </summary>
        private void ReceiveLoop()
        {
            while (running)
            {
                UInt16 channelId;
                try
                {
                    StackPacket packet = ExpectPacket(timeout, out channelId);

                    if (packet != null &&
                        channelDicById != null && channelDicById.ContainsKey(channelId))
                    {
                        channelDicById[channelId].ReceivePackets(packet);
                    }
                }
                catch
                {
                    // catch exception in not main thread.
                }
                Thread.Sleep(waitInterval);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Receive loop
        /// </summary>
        private void ReceiveLoop()
        {
            while (!receiveThreadCancellationTokenSource.IsCancellationRequested)
            {
                UInt16 channelId;
                try
                {
                    StackPacket packet = ExpectPacket(timeout, out channelId);

                    if (packet != null &&
                        channelDicById != null && channelDicById.ContainsKey(channelId))
                    {
                        channelDicById[channelId].ReceivePackets(packet);
                    }
                }
                catch
                {
                    // catch exception in not main thread.
                }
                Thread.Sleep(waitInterval);
            }
        }
        /// <summary>
        /// to decode the CIFS packets.
        /// </summary>
        /// <param name="endPoint">the identification of the connection.</param>
        /// <param name="messageBytes">the message to be decoded.</param>
        /// <param name="consumedLength">the bytes length which are consumed when decode.</param>
        /// <param name="expectedLength">the expected length of data to be received.</param>
        /// <returns>the packets decoded from the input buffer.</returns>
        public StackPacket[] DecodePacket(
            object endPoint,
            byte[] messageBytes,
            out int consumedLength,
            out int expectedLength)
        {
            StackPacket[] packets = new StackPacket[0];

            StackPacket response = this.DecodeSmbResponseFromBytes((int)endPoint, messageBytes, out consumedLength);

            // Use the decoded packet to UpdateRoleContext if it is not null and ContextUpdate is enabled:
            if (response != null)
            {
                if (this.isContextUpdateEnabled)
                {
                    this.clientContext.UpdateRoleContext((int)endPoint, response);
                }
                packets = new StackPacket[] { response };
            }

            expectedLength = 0;
            return(packets);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Send a packet to a special remote host.
        /// </summary>
        /// <param name="endPoint">The remote host to which the packet will be sent.</param>
        /// <param name="packet">The packet to be sent.</param>
        public void SendPacket(object endPoint, StackPacket packet)
        {
            ValidServerHasStarted();

            IPEndPoint ipEndPoint = endPoint as IPEndPoint;

            if (ipEndPoint == null)
            {
                throw new ArgumentException("The endPoint is not an IPEndPoint.", "endPoint");
            }

            // If we use raw bytes to construct the packet, we send the raw bytes out directly,
            // otherwise we convert the packet to bytes and send it out.
            byte[] writeBytes = (packet.PacketBytes == null) ? packet.ToBytes() : packet.PacketBytes;
            Stream stream     = GetStream(ipEndPoint.Address, ipEndPoint.Port);

            if (stream == null)
            {
                throw new InvalidOperationException("The endPoint is not in the connect list.");
            }

            stream.Write(writeBytes, 0, writeBytes.Length);
        }
        public void TraditionalTestCase_IgnoreFields_Tree_04_Case()
        {
            #region Connect to the specified server

            smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize);

            #endregion

            #region Send the Negotiate request

            // Create a SMB_COM_NEGOTIATE request.
            SmbNegotiateRequestPacket negotiateRequest =
                smbClientStack.CreateNegotiateRequest(
                    StackSmb.SignState.NONE,
                    new string[] {
                DialectNameString.PCNET1,
                DialectNameString.LANMAN10,
                DialectNameString.WFW10,
                DialectNameString.LANMAN12,
                DialectNameString.LANMAN21,
                DialectNameString.NTLANMAN
            });

            // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(negotiateRequest);
            StackPacket response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NEGOTIATE response should not be null.");

            // Check whether server returns a SMB_COM_NEGOTIATE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNegotiateResponsePacket),
                "SMB_COM_NEGOTIATE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                negotiateRequest.SmbHeader.Status,
                "SMB_COM_NEGOTIATE response status should be SUCCESS.");

            #endregion

            #region Send the first SMB_COM_SESSION_SETUP_ANDX  Request

            SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse(
                typeof(SmbSecurityPackage),
                Site.Properties["SmbSecurityPackageType"] as string,
                true);

            // Create the first SMB_COM_SESSION_SETUP_ANDX request.
            SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest =
                smbClientStack.CreateFirstSessionSetupRequest(
                    smbSecurityPackage,
                    serverName,
                    domainName,
                    userName,
                    password);

            // Send the first SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(sessionSetupAndxRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

            // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbSessionSetupAndxResponsePacket),
                "SMB_COM_SESSION_SETUP_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            // If SMB SecurityPackage type is NTLM, the expected SUCCESS response status is STATUS_MORE_PROCESSING_REQUIRED,
            // else if SMB SecurityPackage type is Kerberos, the expected SUCCESS response status is STATUS_SUCCESS.
            SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
            Site.Assert.IsTrue(
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED ||
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_SUCCESS,
                "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the second SMB_COM_SESSION_SETUP_ANDX  request

            // Create the second SMB_COM_SESSION_SETUP_ANDX request.
            ushort sessionUid = sessionSetupResponse.SmbHeader.Uid;

            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                SmbSessionSetupAndxRequestPacket secondSessionSetupRequest =
                    smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage);

                // Send the second SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
                smbClientStack.SendPacket(secondSessionSetupRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server returns a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

                // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
                Site.Assert.IsInstanceOfType(
                    response,
                    typeof(SmbSessionSetupAndxResponsePacket),
                    "SMB_COM_SESSION_SETUP_ANDX response should be received.");

                // Check the response validity by verifying the Status field in the SMB Header packet.
                sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    sessionSetupResponse.SmbHeader.Status,
                    "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");
            }

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            // Create a SMB_COM_TREE_CONNECT_ANDX request.
            string path = Site.Properties["SutNtfsShare1FullName"];
            SmbTreeConnectAndxRequestPacket treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            #region Set the request parameters

            StackCifs.SMB_COM_TREE_CONNECT_ANDX_Request_SMB_Parameters treeconnectRequestSmbParameters
                = treeconnectRequest.SmbParameters;

            // The Flags field is set to:TREE_CONNECT_ANDX_DISCONNECT_TID(0x0001),
            // TREE_CONNECT_ANDX_EXTENDED_SIGNATURES(0x0004), TREE_CONNECT_ANDX_EXTENDED_RESPONSE(0x0008).
            treeconnectRequestSmbParameters.Flags =
                (ushort)(treeconnectRequestSmbParameters.Flags & SmbTreeConnectAndxFlags);

            treeconnectRequest.SmbParameters = treeconnectRequestSmbParameters;

            #endregion

            // Send the SMB_COM_TREE_CONNECT_ANDX request and expect a response in the timeout milliseconds.
            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_CONNECT_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_TREE_CONNECT_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeConnectAndxResponsePacket),
                "SMB_COM_TREE_CONNECT_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeConnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_CONNECT_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            // Create the SMB_COM_TREE_CONNECT_ANDX request.
            path = Site.Properties["SutNtfsShare1FullName"];
            treeconnectRequest = smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            //The bits not listed in TD 2.2.4.7.1 of Flags field set to 0.
            //Other fields set according to TD.
            treeconnectRequestSmbParameters = treeconnectRequest.SmbParameters;

            // The Flags field is set to:TREE_CONNECT_ANDX_DISCONNECT_TID(0x0001),
            // TREE_CONNECT_ANDX_EXTENDED_SIGNATURES(0x0004), TREE_CONNECT_ANDX_EXTENDED_RESPONSE(0x0008).
            treeconnectRequestSmbParameters.Flags =
                (ushort)(treeconnectRequestSmbParameters.Flags & SmbTreeConnectAndxFlags);

            treeconnectRequest.SmbParameters = treeconnectRequestSmbParameters;

            // Send the SMB_COM_TREE_CONNECT_ANDX request and expect the response in the timeout milliseconds.
            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_CONNECT_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_TREE_CONNECT_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeConnectAndxResponsePacket),
                "SMB_COM_TREE_CONNECT_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeConnectAndxResponsePacket treeConnectResponse2 = (SmbTreeConnectAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeConnectResponse2.SmbHeader.Status,
                "SMB_COM_TREE_CONNECT_ANDX response status should be SUCCESS.");

            #endregion

            #region Capture requirement r5596

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R5596");

            //
            // Verify MS-SMB requirement: MS-SMB_R5596
            //
            bool isVerifyR5596 = VerifyTreeConnectResponse(treeConnectResponse, treeConnectResponse2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR5596,
                5596,
                @"[In Client Request Extensions]Flags (2 bytes):
                whatever these values are, the server's reply is the same.");

            #endregion
        }
        /// <summary>
        /// Send a packet over the transport.<para/>
        /// the underlayer transport must be TcpClient, UdpClient, Stream or NetbiosClient.<para/>
        /// the UdpClient will send data to the remote endpoint that stored in config.
        /// </summary>
        /// <param name="packet">
        /// a StackPacket object that contains the packet to send to target.
        /// </param>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// thrown when packet is null
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when the underlayer transport is not TcpClient, UdpClient, Stream and NetbiosClient.
        /// </exception>
        public virtual void SendPacket(StackPacket packet)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("TransportStack");
            }

            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }

            ISourceSend source = this.transport as ISourceSend;

            if (source == null)
            {
                throw new InvalidOperationException(
                    "the underlayer transport is not TcpClient, UdpClient, Stream and NetbiosClient.");
            }

            if (packet.PacketBytes != null)
            {
                source.SendBytes(packet.PacketBytes);
            }
            else
            {
                source.SendPacket(packet);
            }
        }
 /// <summary>
 /// Method provided to socket, which can use it to send packet
 /// </summary>
 /// <param name="remoteEP">Remote endpoint</param>
 /// <param name="packet"></param>
 private void packetsender(IPEndPoint remoteEP, StackPacket packet)
 {
     if (running)
     {
         udpTransport.SendPacket(localEndPoint, remoteEP, packet);
     }
 }
 public StackPacketInfo(object localEp, object remoteEp, StackPacket pkt)
 {
     localEndPoint = localEp;
     remoteEndpoint = remoteEp;
     packet = pkt;
 }
        /// <summary>
        /// Send a packet over the transport.<para/>
        /// the underlayer transport must be TcpClient, Stream or NetbiosClient.
        /// </summary>
        /// <param name="packet">
        /// a StackPacket object that contains the packet to send to target.
        /// </param>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when tcp client is not connected to server, must invoke Connect() first.
        /// </exception>
        public void SendPacket(StackPacket packet)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("TcpClientTransport");
            }

            this.SendBytes(packet.ToBytes());
        }
 /// <summary>
 /// Process received static virtual channel packet
 /// </summary>
 /// <param name="packet"></param>
 public abstract void ReceivePackets(StackPacket packet);
        /// <summary>
        /// Send a packet over the transport.<para/>
        /// the underlayer transport must be TcpClient, UdpClient, Stream or NetbiosClient.<para/>
        /// the UdpClient will send data to the remote endpoint that stored in config.
        /// </summary>
        /// <param name="packet">
        /// a StackPacket object that contains the packet to send to target.
        /// </param>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when udp client is not start, must invoke Start() first.
        /// </exception>
        public void SendPacket(StackPacket packet)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("UdpClientTransport");
            }

            if (this.udpClient == null)
            {
                throw new InvalidOperationException("udp client is not start, must invoke Start() first.");
            }

            this.SendBytes(packet.ToBytes());
        }
        /// <summary>
        /// Method used to process a received packet
        /// </summary>
        /// <param name="packet"></param>
        public void ReceivePacket(StackPacket packet)
        {
            // Transfer packet to
            RdpeudpPacket eudpPacket = new RdpeudpPacket();
            byte[] packetBytes = packet.ToBytes();
            if (!PduMarshaler.Unmarshal(packetBytes, eudpPacket, false))
            {
                return;
            }

            // ETW Provider Dump Message
            string messageName = "RDPEUDP:ReceivedPDU";
            ExtendedLogger.DumpMessage(messageName, DumpLevel_LayerTLS, eudpPacket.GetType().Name, packetBytes);

            ReceivePacket(eudpPacket);
        }
        /// <summary>
        /// Send a packet to a special remote host.<para/>
        /// the transport must be UdpServer
        /// </summary>
        /// <param name="localEndPoint">
        /// an object that specifies the local endpoint to send bytes.
        /// </param>
        /// <param name="remoteEndPoint">
        /// an object that specifies the target endpoint to which send packet.
        /// </param>
        /// <param name="packet">
        /// a StackPacket object that contains the packet to send to target.
        /// </param>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when the server is not started, must invoke Start() first.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// thrown when remoteEndPoint is null.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when udp server is not start, must invoke Start() first.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// thrown when the specified endpoint is not an IPEndPoint.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when udp server is not start, must invoke Start() first.
        /// </exception>
        public void SendPacket(object localEndPoint, object remoteEndPoint, StackPacket packet)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("UdpServerTransport");
            }

            if (!this.started)
            {
                throw new InvalidOperationException("server is not started, must invoke Start() first.");
            }

            if (this.listeners.Count == 0)
            {
                throw new InvalidOperationException("udp server is not start, must invoke Start() first.");
            }

            this.SendBytes(localEndPoint, remoteEndPoint, packet.ToBytes());
        }
        /// <summary>
        /// Decodes LDAP packets.
        /// </summary>
        /// <param name="endPoint">The end point of the client.</param>
        /// <param name="messageBytes">The message bytes that contains the packet data.</param>
        /// <param name="consumedLength">Consumed length.</param>
        /// <param name="expectedLength">
        /// Indicates expected length if the message bytes doesn't contain all packet data.
        /// </param>
        /// <returns>Decoded packets.</returns>
        internal override StackPacket[] DecodeLdapPacketCallBack(
            object endPoint,
            byte[] messageBytes,
            out int consumedLength,
            out int expectedLength)
        {
            consumedLength = 0;
            expectedLength = 0;
            byte[] data = messageBytes;

            if (this.client.Security != null && messageBytes != null)
            {
                data = this.client.Security.Decode(messageBytes);
            }

            List <StackPacket> packets = new List <StackPacket>();

            while (data != null && data.Length > 0)
            {
                int    nextPacketIndex = 0;
                byte[] packetData      = this.GetSinglePacketData(data, out nextPacketIndex, out expectedLength);
                consumedLength += nextPacketIndex;

                if (packetData == null)
                {
                    break;
                }

                data = ArrayUtility.SubArray <byte>(data, nextPacketIndex);

                StackPacket packet = null;
                try
                {
                    packet = this.decoder.ParseAdtsLdapPacket(packetData, this.client.Context);
                }
                // because sometimes there is some zero bytes after packet, and cannot be parsed and throw exception,
                // so just ignore the exception.
                catch (Asn1Exception ae)
                {
                    if (ae.Message.Contains("Decoding error. Unexpected data is read"))
                    {
                        throw ae;
                    }
                    else
                    {
                        break;
                    }
                }

                if (packet == null)
                {
                    break;
                }

                packets.Add(packet);
            }

            // add the comsumed length of security decorder
            if (this.client.Security != null && this.client.Security.ConsumedData)
            {
                consumedLength = this.client.Security.ConsumedLength;
            }

            if (packets.Count == 0)
            {
                return(null);
            }

            return(packets.ToArray());
        }
 /// <summary>
 /// Method provided to socket, which can use it to send packet
 /// </summary>
 /// <param name="remoteEP">Remote endpoint</param>
 /// <param name="packet"></param>
 private void PacketSender(IPEndPoint remoteEP, StackPacket packet)
 {
     udpTransport.SendPacket(remoteEP, packet);
 }
Exemplo n.º 31
0
        /// <summary>
        /// Expect the specified pdu from RDP server within the timeout.
        /// </summary>
        public TS_LICENSE_PDU ExpectPdu(TimeSpan timeout)
        {
            TS_LICENSE_PDU licensePdu = null;
            StackPacket    packet     = rdpbcgrClient.ExpectPdu(timeout);

            if (packet == null)
            {
                return(null);
            }
            if (packet is Server_License_Error_Pdu_Valid_Client)
            {
                licensePdu = new TS_LICENSE_PDU(rdpbcgrClient.context);
                licensePdu.commonHeader = ((Server_License_Error_Pdu_Valid_Client)packet).commonHeader;
                licensePdu.preamble     = ((Server_License_Error_Pdu_Valid_Client)packet).preamble;
                licensePdu.LicensingMessage.LicenseError = ((Server_License_Error_Pdu_Valid_Client)packet).validClientMessage;
            }
            else if (packet is RdpelePdu)
            {
                licensePdu = new TS_LICENSE_PDU(rdpbcgrClient.context);
                licensePdu.commonHeader = ((RdpelePdu)packet).commonHeader;
                licensePdu.preamble     = ((RdpelePdu)packet).preamble;
                licensePdu.FromBytes(((RdpelePdu)packet).rdpeleData);

                if (licensePdu.preamble.bMsgType == bMsgType_Values.LICENSE_REQUEST)
                {
                    // Save server random and decode cert to get public key for future use.
                    serverRandom = licensePdu.LicensingMessage.ServerLicenseRequest.Value.ServerRandom;

                    // According to [MS-RDPELE] section 2.2.2.1
                    // The terminal server can choose not to send the certificate by setting the wblobLen field in the Licensing Binary BLOB structure to 0.
                    // If encryption is in effect and is already protecting RDP traffic, the licensing protocol MAY<3> choose not to send the server certificate
                    // (for RDP security measures, see [MS-RDPBCGR] sections 5.3 and 5.4). If the licensing protocol chooses not to send the server certificate,
                    // then the client uses the public key obtained from the server certificate sent as part of Server Security Data in the
                    // Server MCS Connect Response PDU (see [MS-RDPBCGR] section 2.2.1.4).
                    if (licensePdu.LicensingMessage.ServerLicenseRequest.Value.ServerCertificate.wBlobLen == 0)
                    {
                        publicExponent = rdpbcgrClient.context.ServerExponent;
                        modulus        = rdpbcgrClient.context.ServerModulus;
                    }
                    else
                    {
                        int index = 0;
                        SERVER_CERTIFICATE cert = RdpbcgrDecoder.DecodeServerCertificate(
                            licensePdu.LicensingMessage.ServerLicenseRequest.Value.ServerCertificate.blobData,
                            ref index,
                            (uint)licensePdu.LicensingMessage.ServerLicenseRequest.Value.ServerCertificate.blobData.Length);
                        RdpbcgrDecoder.DecodePubicKey(cert, out publicExponent, out modulus);
                    }
                }
                else if (licensePdu.preamble.bMsgType == bMsgType_Values.PLATFORM_CHALLENGE)
                {
                    // Decrypt platform challenge for future use.
                    byte[] encryptedPlatformChallenge = licensePdu.LicensingMessage.ServerPlatformChallenge.Value.EncryptedPlatformChallenge.blobData;
                    platformChallenge = RC4(encryptedPlatformChallenge);
                    if (platformChallenge == null)
                    {
                        throw new Exception("The decrpyted PlatformChallenge should not be NULL!");
                    }

                    if (!VerifyServerMAC(licensePdu.LicensingMessage.ServerPlatformChallenge.Value.MACData, platformChallenge))
                    {
                        throw new Exception("The MACData of PLATFORM_CHALLENGE from Server is invalid!");
                    }
                }
                else if (licensePdu.preamble.bMsgType == bMsgType_Values.NEW_LICENSE)
                {
                    // Decrypt the license info for future use.
                    var decryptedLicenseInfo = RC4(licensePdu.LicensingMessage.ServerNewLicense.Value.EncryptedLicenseInfo.blobData);
                    newLicenseInfo = TypeMarshal.ToStruct <NEW_LICENSE_INFO>(decryptedLicenseInfo);

                    if (!VerifyServerMAC(licensePdu.LicensingMessage.ServerNewLicense.Value.MACData, decryptedLicenseInfo))
                    {
                        throw new Exception("The MACData of SERVER_NEW_LICENSE from Server is invalid!");
                    }
                }
                else if (licensePdu.preamble.bMsgType == bMsgType_Values.UPGRADE_LICENSE)
                {
                    // Decrypt the license info for future use.
                    var decryptedLicenseInfo = RC4(licensePdu.LicensingMessage.ServerUgradeLicense.Value.EncryptedLicenseInfo.blobData);
                    upgradedLicenseInfo = TypeMarshal.ToStruct <NEW_LICENSE_INFO>(decryptedLicenseInfo);

                    if (!VerifyServerMAC(licensePdu.LicensingMessage.ServerUgradeLicense.Value.MACData, decryptedLicenseInfo))
                    {
                        throw new Exception("The MACData of SERVER_UPGRADE_LICENSE from Server is invalid!");
                    }
                }
                else
                {
                    throw new Exception($"The received PDU type should not be {licensePdu.preamble.bMsgType}!");
                }
            }

            return(licensePdu);
        }
        /// <summary>
        /// This method expect a TS_FRAME_ACKNOWLEDGE_PDU from client.
        /// </summary>
        /// <param name="expectedFrameId">The expected frame id.</param>
        /// <param name="ackTimeout">The time span to wait.</param>
        public void ExpectTsFrameAcknowledgePdu(uint expectedFrameId, TimeSpan ackTimeout)
        {
            this.frameMakerFrameId = expectedFrameId;
            if (this.rdpbcgrAdapter != null)
            {
                this.rdpbcgrAdapter.WaitForPacket <TS_FRAME_ACKNOWLEDGE_PDU>(ackTimeout);
            }
            else if (this.rdpbcgrServerStack != null && this.rdpbcgrSessionContext != null)
            {
                StackPacket receivedPdu         = null;
                TS_FRAME_ACKNOWLEDGE_PDU ackPdu = null;
                bool     isReceived             = false;
                TimeSpan leftTime      = ackTimeout;
                DateTime expiratedTime = DateTime.Now + ackTimeout;

                foreach (StackPacket pdu in pduCache)
                {
                    ackPdu = pdu as TS_FRAME_ACKNOWLEDGE_PDU;
                    if (ackPdu != null)
                    {
                        isReceived = true;
                        pduCache.Remove(pdu);
                        break;
                    }
                }

                while (!isReceived && leftTime.CompareTo(new TimeSpan(0)) > 0)
                {
                    try
                    {
                        receivedPdu = this.rdpbcgrServerStack.ExpectPdu(this.rdpbcgrSessionContext, leftTime);
                        ackPdu      = receivedPdu as TS_FRAME_ACKNOWLEDGE_PDU;
                        if (ackPdu != null)
                        {
                            isReceived = true;
                            break;
                        }
                        else
                        {
                            Site.Log.Add(LogEntryKind.TestInProgress, "Received and cached Pdu: {0}.", receivedPdu.GetType());
                            pduCache.Add(receivedPdu);
                        }
                    }
                    catch (TimeoutException)
                    {
                        Site.Assert.Fail("Timeout when expecting {0}", typeof(TS_FRAME_ACKNOWLEDGE_PDU));
                    }
                    catch (InvalidOperationException ex)
                    {
                        //break;
                        Site.Log.Add(LogEntryKind.Warning, "Exception thrown out when receiving client PDUs {0}.", ex.Message);
                    }
                    finally
                    {
                        System.Threading.Thread.Sleep(100);//Wait some time for next packet.
                        leftTime = expiratedTime - DateTime.Now;
                    }
                }
                if (isReceived)
                {
                    this.VerifyTS_FRAME_ACKNOWLEDGE_PDU(ackPdu);
                }
                else
                {
                    site.Assert.Fail("Timeout when expecting {0}.", typeof(TS_FRAME_ACKNOWLEDGE_PDU));
                }
            }
        }
        /// <summary>
        /// Send a packet over the transport.<para/>
        /// the underlayer transport must be TcpClient, Stream or NetbiosClient.
        /// </summary>
        /// <param name="packet">
        /// a StackPacket object that contains the packet to send to target.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// thrown when packet is null
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when stream client is not connected, must invoke Connect() first.
        /// </exception>
        public void SendPacket(StackPacket packet)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("StreamTransport");
            }

            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }

            this.SendBytes(packet.ToBytes());
        }
Exemplo n.º 34
0
        public void TraditionalTestCase_IgnoreFields_SET_FILE_09_Case()
        {
            #region Connect to the specified server

            smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize);

            #endregion

            #region Send the Negotiate request

            // Create a SMB_COM_NEGOTIATE request.
            SmbNegotiateRequestPacket negotiateRequest =
                smbClientStack.CreateNegotiateRequest(
                    StackSmb.SignState.NONE,
                    new string[] {
                DialectNameString.PCNET1,
                DialectNameString.LANMAN10,
                DialectNameString.WFW10,
                DialectNameString.LANMAN12,
                DialectNameString.LANMAN21,
                DialectNameString.NTLANMAN
            });

            // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(negotiateRequest);
            StackPacket response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NEGOTIATE response should not be null.");

            // Check whether server returns a SMB_COM_NEGOTIATE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNegotiateResponsePacket),
                "SMB_COM_NEGOTIATE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                negotiateRequest.SmbHeader.Status,
                "SMB_COM_NEGOTIATE response status should be SUCCESS.");

            #endregion

            #region Send the first SMB_COM_SESSION_SETUP_ANDX  Request

            SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse(
                typeof(SmbSecurityPackage),
                Site.Properties["SmbSecurityPackageType"] as string,
                true);

            // Create the first SMB_COM_SESSION_SETUP_ANDX request.
            SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest =
                smbClientStack.CreateFirstSessionSetupRequest(
                    smbSecurityPackage,
                    serverName,
                    domainName,
                    userName,
                    password);

            // Send the first SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(sessionSetupAndxRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

            // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbSessionSetupAndxResponsePacket),
                "SMB_COM_SESSION_SETUP_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            // If SMB SecurityPackage type is NTLM, the expected SUCCESS response status is STATUS_MORE_PROCESSING_REQUIRED,
            // else if SMB SecurityPackage type is Kerberos, the expected SUCCESS response status is STATUS_SUCCESS.
            SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
            Site.Assert.IsTrue(
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED ||
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_SUCCESS,
                "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the second SMB_COM_SESSION_SETUP_ANDX  request

            // Create the second SMB_COM_SESSION_SETUP_ANDX request.
            ushort sessionUid = sessionSetupResponse.SmbHeader.Uid;
            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                SmbSessionSetupAndxRequestPacket secondSessionSetupRequest =
                    smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage);

                // Send the second SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
                smbClientStack.SendPacket(secondSessionSetupRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server returns a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

                // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
                Site.Assert.IsInstanceOfType(
                    response,
                    typeof(SmbSessionSetupAndxResponsePacket),
                    "SMB_COM_SESSION_SETUP_ANDX response should be received.");

                // Check the response validity by verifying the Status field in the SMB Header packet.
                sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    sessionSetupResponse.SmbHeader.Status,
                    "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");
            }

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            // Create the SMB_COM_TREE_CONNECT_ANDX request.
            string path = Site.Properties["SutNtfsShare1FullName"];
            SmbTreeConnectAndxRequestPacket treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            // Send the SMB_COM_TREE_CONNECT_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_CONNECT_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_TREE_CONNECT_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeConnectAndxResponsePacket),
                "SMB_COM_TREE_CONNECT_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeConnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_CONNECT_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            // Create the Create request.
            ushort treeId   = treeConnectResponse.SmbHeader.Tid;
            string fileName = Site.Properties["SutShareTest2"];
            SmbNtCreateAndxRequestPacket createRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName,
                    StackCifs.NtTransactDesiredAccess.GENERIC_ALL,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.FILE_SHARE_DELETE
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_READ
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_WRITE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_IDENTIFY,
                    CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            // Send the SMB_COM_NT_CREATE_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            // Check if server returns a SMB_COM_NT_CREATE_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse = (SmbNtCreateAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                createResponse.SmbHeader.Status,
                "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the TRANS2_SET_FILE_INFORMATION request

            // Create a TRANS2_SET_FILE_INFORMATION request.
            ushort fileId = createResponse.SmbParameters.FID;
            StackFscc.FileLinkInformation fileLinkInformation = new StackFscc.FileLinkInformation();

            // 1 indicates that if the link already exists, it should be replaced with the new link.
            fileLinkInformation.ReplaceIfExists = 1;

            // The Reserved filed is a 7 bytes array
            fileLinkInformation.Reserved = new byte[7];

            // The name of the newly created link.
            fileLinkInformation.FileName       = Encoding.Unicode.GetBytes("wl.txt.lnk");
            fileLinkInformation.FileNameLength = (uint)fileLinkInformation.FileName.Length;

            // 0 indicates a network operations.
            fileLinkInformation.RootDirectory = 0;

            StackFscc.FsccFileLinkInformationRequestPacket linkPacket =
                new StackFscc.FsccFileLinkInformationRequestPacket();

            linkPacket.Payload = TypeMarshal.ToBytes <StackFscc.FileLinkInformation>(fileLinkInformation);
            byte[] data = linkPacket.ToBytes();
            smbClientStack.Capability.IsUsePassThrough = false;

            // Create a TRANS2_SET_FILE_INFORMATION Request.
            SmbTrans2SetFileInformationRequestPacket trans2SetFileInformationRequest =
                smbClientStack.CreateTrans2SetFileInformationRequest(
                    fileId,
                    StackCifs.Trans2SmbParametersFlags.NONE,
                    StackCifs.SetInformationLevel.SMB_INFO_STANDARD,
                    data);

            // Send the TRANS2_SET_FILE_INFORMATION request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(trans2SetFileInformationRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "TRANS2_SET_FILE_INFORMATION response should not be null.");

            // Check whether server returns a TRANS2_SET_FILE_INFORMATION response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTrans2SetFileInformationResponsePacket),
                "TRANS2_SET_FILE_INFORMATION response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTrans2SetFileInformationResponsePacket trans2SetFileInformationResponse =
                (SmbTrans2SetFileInformationResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                trans2SetFileInformationResponse.SmbHeader.Status,
                "TRANS2_SET_FILE_INFORMATION response status should be SUCCESS.");

            #endregion

            #region Send the TRANS2_SET_FILE_INFORMATION request

            StackFscc.FsccFileLinkInformationRequestPacket linkPacket2 =
                new StackFscc.FsccFileLinkInformationRequestPacket();
            fileLinkInformation = new StackFscc.FileLinkInformation();

            // 1 indicates that if the link already exists, it should be replaced with the new link.
            fileLinkInformation.ReplaceIfExists = 1;

            // The Reserved filed is a 7 bytes array
            fileLinkInformation.Reserved = new byte[7];

            // The name of the newly created link.
            fileLinkInformation.FileName       = Encoding.Unicode.GetBytes("wl.txt.lnk");
            fileLinkInformation.FileNameLength = (uint)fileLinkInformation.FileName.Length;

            // 0 indicates a network operations.
            fileLinkInformation.RootDirectory = 0;

            linkPacket2.Payload = TypeMarshal.ToBytes <StackFscc.FileLinkInformation>(fileLinkInformation);
            smbClientStack.Capability.IsUsePassThrough = false;

            // Create a TRANS2_SET_FILE_INFORMATION request.
            SmbTrans2SetFileInformationRequestPacket trans2SetFileInformationRequest2 =
                smbClientStack.CreateTrans2SetFileInformationRequest(
                    fileId,
                    StackCifs.Trans2SmbParametersFlags.NONE,
                    StackCifs.SetInformationLevel.SMB_INFO_STANDARD,
                    linkPacket2.ToBytes());

            // Send the TRANS2_SET_FILE_INFORMATION request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(trans2SetFileInformationRequest2);
            StackPacket response2 = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response2,
                "TRANS2_SET_FILE_INFORMATION response should not be null.");

            // Check whether server returns a TRANS2_SET_FILE_INFORMATION response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTrans2SetFileInformationResponsePacket),
                "TRANS2_SET_FILE_INFORMATION response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTrans2SetFileInformationResponsePacket trans2SetFileInformationResponse2 =
                (SmbTrans2SetFileInformationResponsePacket)response2;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                trans2SetFileInformationResponse.SmbHeader.Status,
                "TRANS2_SET_FILE_INFORMATION response status should be SUCCESS.");

            #endregion

            #region Send the SMB_CLOSE request

            // Create the SMB_CLOSE request.
            SmbCloseRequestPacket CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            // Send the Close request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(CloseRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_CLOSE response should not be null.");

            // Check whether server returns a SMB_CLOSE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                "SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbCloseResponsePacket closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                "SMB_CLOSE response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_TREE_DISCONNECT request

            // Create the SMB_COM_TREE_DISCONNECT request.
            SmbTreeDisconnectRequestPacket treeDisconnectRequest = smbClientStack.CreateTreeDisconnectRequest(treeId);

            // Send the TreeDisconnect request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(treeDisconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_DISCONNECT response should not be null.");

            // Check whether server returns a SMB_COM_TREE_DISCONNECT response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeDisconnectResponsePacket),
                "SMB_COM_TREE_DISCONNECT response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeDisconnectResponsePacket treeDisconnectResponse = (SmbTreeDisconnectResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeDisconnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_DISCONNECT response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_LOGOFF_ANDX request

            // Create the SMB_COM_LOGOFF_ANDX request.
            SmbLogoffAndxRequestPacket logoffRequest = smbClientStack.CreateLogoffRequest(sessionUid);

            // Send the LogOff request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(logoffRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_LOGOFF_ANDX response should not be null.");

            // Check whether server returns a response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbLogoffAndxResponsePacket),
                "SMB_COM_LOGOFF_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbLogoffAndxResponsePacket logoffResponse = (SmbLogoffAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                logoffResponse.SmbHeader.Status,
                "SMB_COM_LOGOFF_ANDX response status should be SUCCESS.");

            #endregion

            #region Disconnect

            // Disconnect
            smbClientStack.Disconnect();

            Site.Assert.IsFalse(
                smbClientStack.IsDataAvailable,
                "SmbClient should not receive any packet after Disconnect method is called.");

            #endregion

            #region Capture requirement r109590

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109590");

            //
            // Verify MS-SMB requirement: MS-SMB_R109590
            //
            bool isVerifyR109590 =
                VerifyisVerifyTrans2SetFileInformation(
                    trans2SetFileInformationResponse,
                    trans2SetFileInformationResponse2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR109590,
                109590,
                @"<77> Section 2.2.8.4: Reserved (3 bytes): reply is the same whether zero or non-zero");

            #endregion
        }
        /// <summary>
        /// Send a packet to a special remote host.<para/>
        /// the transport must be a TcpServer, UdpClient or UdpServer.
        /// </summary>
        /// <param name="remoteEndPoint">
        /// an object that specifies the target endpoint to which send packet.
        /// </param>
        /// <param name="packet">
        /// a StackPacket object that contains the packet to send to target.
        /// </param>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when the server is not started, must invoke Start() first.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// thrown when remoteEndPoint is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// thrown when the specified endpoint is not an IPEndPoint.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when the client specified by endpoint cannot be found!
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when the client specified by endpoint is null!
        /// </exception>
        public void SendPacket(object remoteEndPoint, StackPacket packet)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("TcpServerTransport");
            }

            if (!this.started)
            {
                throw new InvalidOperationException("server is not started, must invoke Start() first.");
            }

            this.SendBytes(remoteEndPoint, packet.ToBytes());
        }
        /// <summary>
        /// Send a packet to a special remote host.<para/>
        /// the transport must be a TcpServer, NetbiosServer or UdpClient.
        /// </summary>
        /// <param name="remoteEndPoint">
        /// an object that specifies the target endpoint to which send packet.<para/>
        /// if Tcp/Udp, it's an IPEndPoint that specifies the target endpoint.<para/>
        /// if Netbios, it's an int value that specifies the remote client session id.
        /// </param>
        /// <param name="packet">
        /// a StackPacket object that contains the packet to send to target.
        /// </param>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// thrown when packet is null
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when the underlayer transport is not TcpServer, NetbiosServer and UdpClient.
        /// </exception>
        public virtual void SendPacket(object remoteEndPoint, StackPacket packet)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("TransportStack");
            }

            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }

            ITarget target = this.transport as ITarget;

            if (target == null)
            {
                throw new InvalidOperationException(
                    "the underlayer transport is not TcpServer, NetbiosServer and UdpClient.");
            }

            target.SendPacket(remoteEndPoint, packet);
        }
 /// <summary>
 /// Method provided to socket, which can use it to send packet
 /// </summary>
 /// <param name="remoteEP">Remote endpoint</param>
 /// <param name="packet"></param>
 private void packetsender(IPEndPoint remoteEP, StackPacket packet)
 {
     udpTransport.SendPacket(remoteEP, packet);
 }
        /// <summary>
        /// Send a packet to a special remote host.<para/>
        /// the transport must be UdpServer
        /// </summary>
        /// <param name="localEndPoint">
        /// an object that specifies the local endpoint to send bytes.
        /// </param>
        /// <param name="remoteEndPoint">
        /// an object that specifies the target endpoint to which send packet.
        /// </param>
        /// <param name="packet">
        /// a StackPacket object that contains the packet to send to target.
        /// </param>
        /// <exception cref="ObjectDisposedException">
        /// thrown when this object is disposed.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// thrown when packet is null
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// thrown when the underlayer transport is not UdpServer.
        /// </exception>
        public virtual void SendPacket(object localEndPoint, object remoteEndPoint, StackPacket packet)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("TransportStack");
            }

            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }

            ITargetSend target = this.transport as ITargetSend;

            if (target == null)
            {
                throw new InvalidOperationException("the underlayer transport is not UdpServer.");
            }

            target.SendPacket(localEndPoint, remoteEndPoint, packet);
        }
Exemplo n.º 39
0
 /// <summary>
 /// Process received static virtual channel packet
 /// </summary>
 /// <param name="packet"></param>
 public abstract void ReceivePackets(StackPacket packet);
        public void TraditionalTestCase_IgnoreFields_CopyChunk_05()
        {
            #region Connect to the specified server

            smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize);

            #endregion

            #region Send the Negotiate request

            // Create a SMB_COM_NEGOTIATE request.
            SmbNegotiateRequestPacket negotiateRequest =
                smbClientStack.CreateNegotiateRequest(
                    StackSmb.SignState.NONE,
                    new string[] {
                DialectNameString.PCNET1,
                DialectNameString.LANMAN10,
                DialectNameString.WFW10,
                DialectNameString.LANMAN12,
                DialectNameString.LANMAN21,
                DialectNameString.NTLANMAN
            });

            // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(negotiateRequest);
            StackPacket response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NEGOTIATE response should not be null.");

            // Check whether server returns a SMB_COM_NEGOTIATE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNegotiateResponsePacket),
                "SMB_COM_NEGOTIATE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                negotiateRequest.SmbHeader.Status,
                "SMB_COM_NEGOTIATE response status should be SUCCESS.");

            #endregion

            #region Send the first SMB_COM_SESSION_SETUP_ANDX  Request

            SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse(
                typeof(SmbSecurityPackage),
                Site.Properties["SmbSecurityPackageType"] as string,
                true);

            // Create the first SMB_COM_SESSION_SETUP_ANDX request.
            SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest =
                smbClientStack.CreateFirstSessionSetupRequest(
                    smbSecurityPackage,
                    serverName,
                    domainName,
                    userName,
                    password);

            // Send the first SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(sessionSetupAndxRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

            // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbSessionSetupAndxResponsePacket),
                "SMB_COM_SESSION_SETUP_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            // If SMB SecurityPackage type is NTLM, the expected SUCCESS response status is STATUS_MORE_PROCESSING_REQUIRED,
            // else if SMB SecurityPackage type is Kerberos, the expected SUCCESS response status is STATUS_SUCCESS.
            SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
            Site.Assert.IsTrue(
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED ||
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_SUCCESS,
                "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the second SMB_COM_SESSION_SETUP_ANDX  request

            // Create the second SMB_COM_SESSION_SETUP_ANDX request.
            ushort sessionUid = sessionSetupResponse.SmbHeader.Uid;

            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                SmbSessionSetupAndxRequestPacket secondSessionSetupRequest =
                    smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage);

                // Send the second SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
                smbClientStack.SendPacket(secondSessionSetupRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server return a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

                // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
                Site.Assert.IsInstanceOfType(
                    response,
                    typeof(SmbSessionSetupAndxResponsePacket),
                    "SMB_COM_SESSION_SETUP_ANDX response should be received.");

                // Check the response validity by verifying the Status field in the SMB Header packet.
                sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    sessionSetupResponse.SmbHeader.Status,
                    "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");
            }

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            string path = Site.Properties["SutNtfsShare1FullName"];

            SmbTreeConnectAndxRequestPacket treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response;
            #endregion

            #region Send the NT_CREATE_ANDX request

            ushort treeId   = treeConnectResponse.SmbHeader.Tid;
            string fileName = Site.Properties["SutShareTest1"];
            smbClientStack.Capability.Flag |= SmbHeader_Flags_Values.OPLOCK;

            SmbNtCreateAndxRequestPacket createRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName,
                    StackCifs.NtTransactDesiredAccess.FILE_READ_DATA
                    | StackCifs.NtTransactDesiredAccess.FILE_READ_EA
                    | StackCifs.NtTransactDesiredAccess.FILE_READ_ATTRIBUTES
                    | StackCifs.NtTransactDesiredAccess.FILE_WRITE_DATA,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.FILE_SHARE_READ
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_DELETE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_OPEN_REPARSE_POINT
                    | NtTransactCreateOptions.FILE_SEQUENTIAL_ONLY
                    | NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                    CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            #endregion

            #region Send the NT_CREATE_ANDX request

            SmbNtCreateAndxResponsePacket createResponse = (SmbNtCreateAndxResponsePacket)response;
            ushort fileId1   = createResponse.SmbParameters.FID;
            uint   offset    = uint.Parse(Site.Properties["SmbTransportWriteOffset"].ToString());
            byte[] writeData = new byte[17000];

            for (int i = 0; i < writeData.Length; i++)
            {
                writeData[i] = (byte)'a';
            }

            SmbWriteAndxRequestPacket writeRequest = smbClientStack.CreateWriteRequest(fileId1, offset, writeData);

            smbClientStack.SendPacket(writeRequest);
            response = smbClientStack.ExpectPacket(timeout);

            #endregion

            #region Send the WRITE_ANDX request

            SmbWriteAndxResponsePacket writeAndxResponsePacket = response as SmbWriteAndxResponsePacket;
            string fileName2 = Site.Properties["SutShareTest2"];

            SmbNtCreateAndxRequestPacket createSecondRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName2,
                    StackCifs.NtTransactDesiredAccess.FILE_READ_DATA
                    | StackCifs.NtTransactDesiredAccess.FILE_WRITE_DATA
                    | StackCifs.NtTransactDesiredAccess.FILE_APPEND_DATA,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.FILE_SHARE_WRITE
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_DELETE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_OPEN_REPARSE_POINT
                    | NtTransactCreateOptions.FILE_SEQUENTIAL_ONLY
                    | NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                    CreateFlags.NT_CREATE_REQUEST_OPBATCH);

            smbClientStack.SendPacket(createSecondRequest);
            response = smbClientStack.ExpectPacket(timeout);

            #endregion

            #region Send the NT_CREATE_ANDX

            SmbNtCreateAndxResponsePacket createSecondResponse = (SmbNtCreateAndxResponsePacket)response;
            ushort fileId2 = createSecondResponse.SmbParameters.FID;

            SmbNtTransFsctlSrvRequestResumeKeyRequestPacket nTTransIOCtlRequestResumeKeyRequest =
                smbClientStack.CreateNTTransIOCtlRequestResumeKeyRequest(fileId1, true, 0);

            StackCifs.SmbHeader smbHeader = nTTransIOCtlRequestResumeKeyRequest.SmbHeader;
            smbHeader.Uid = sessionUid;
            smbHeader.Tid = treeId;
            nTTransIOCtlRequestResumeKeyRequest.SmbHeader = smbHeader;

            smbClientStack.SendPacket(nTTransIOCtlRequestResumeKeyRequest);
            response = smbClientStack.ExpectPacket(timeout);

            SmbNtTransFsctlSrvRequestResumeKeyResponsePacket nTTransIOCtlRequestResumeKeyResponse =
                (SmbNtTransFsctlSrvRequestResumeKeyResponsePacket)response;

            #endregion

            #region Send the NT_TRANS_IO_CTL request

            bool   isFsctl            = true;
            byte   isFlags            = (byte)0;
            byte[] copychunkResumeKey = nTTransIOCtlRequestResumeKeyResponse.NtTransData.ResumeKey;

            nTTransIOCtlRequestResumeKeyRequest =
                smbClientStack.CreateNTTransIOCtlRequestResumeKeyRequest(fileId1, true, 0);

            smbHeader     = nTTransIOCtlRequestResumeKeyRequest.SmbHeader;
            smbHeader.Uid = sessionUid;
            smbHeader.Tid = treeId;
            nTTransIOCtlRequestResumeKeyRequest.SmbHeader = smbHeader;

            smbClientStack.SendPacket(nTTransIOCtlRequestResumeKeyRequest);
            response = smbClientStack.ExpectPacket(timeout);

            #endregion

            #region Capture requirement r9074

            nTTransIOCtlRequestResumeKeyResponse =
                (SmbNtTransFsctlSrvRequestResumeKeyResponsePacket)response;
            byte[] copychunkResumeKey2 = nTTransIOCtlRequestResumeKeyResponse.NtTransData.ResumeKey;

            // Compare copychunkResumeKey and copychunkResumeKey2, if same, capture 9074
            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R9074");

            //
            // Verify MS-SMB requirement: MS-SMB_R9074
            //
            bool isVerifyR9074 = CompareArrayEquals(copychunkResumeKey, copychunkResumeKey2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR9074,
                9074,
                @"[In Copychunk Resume Key Generation] The generation of Copychunk Resume Keys MUST satisfy the 
                following constraints:The Copychunk Resume Key MUST remain valid for the lifetime of the open file 
                on the server.");

            #endregion

            #region Send the NT_TRANSACT_COPY_CHUNK_List request

            NT_TRANSACT_COPY_CHUNK_List list = new NT_TRANSACT_COPY_CHUNK_List();
            list.Length            = (uint)64;
            list.SourceOffset      = (ulong)0;
            list.DestinationOffset = (ulong)0;

            SmbNtTransFsctlSrvCopyChunkRequestPacket nTTransIOCtlCopyChunkRequest =
                smbClientStack.CreateNTTransIOCtlCopyChunkRequest(fileId2, isFsctl, isFlags, copychunkResumeKey, list);

            smbClientStack.SendPacket(nTTransIOCtlCopyChunkRequest);
            response = smbClientStack.ExpectPacket(timeout);

            #endregion

            #region Send the NT_TRANSACT_COPY_CHUNK_Request_NT_Trans_Data request

            SmbNtTransFsctlSrvCopyChunkResponsePacket nTTransIOCtlCopyChunkResponse1 =
                (SmbNtTransFsctlSrvCopyChunkResponsePacket)response;

            list.Length            = (uint)64;
            list.SourceOffset      = (ulong)0;
            list.DestinationOffset = (ulong)0;
            list.Reserved          = 0xFFFF;

            nTTransIOCtlCopyChunkRequest =
                smbClientStack.CreateNTTransIOCtlCopyChunkRequest(fileId2, isFsctl, isFlags, copychunkResumeKey, list);
            NT_TRANSACT_COPY_CHUNK_Request_NT_Trans_Data TransData = nTTransIOCtlCopyChunkRequest.NtTransData;

            TransData.Unused = 0xFFFF;
            nTTransIOCtlCopyChunkRequest.NtTransData = TransData;

            smbClientStack.SendPacket(nTTransIOCtlCopyChunkRequest);
            response = smbClientStack.ExpectPacket(timeout);

            #endregion

            #region Capture requirements R109390

            SmbNtTransFsctlSrvCopyChunkResponsePacket nTTransIOCtlCopyChunkResponse2 =
                (SmbNtTransFsctlSrvCopyChunkResponsePacket)response;

            // Compare 2 copy chunckResponse
            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109390");

            //
            // Verify MS-SMB requirement: MS-SMB_R109390
            //
            bool isVerifyR109390 = VerifyResponse(nTTransIOCtlCopyChunkResponse1, nTTransIOCtlCopyChunkResponse2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR109390,
                109390,
                @"[In  Client Request Extensions]Reserved (4 bytes):
                reply is the same whether zero or non-zero is used this field.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109396");

            //
            // Verify MS-SMB requirement: MS-SMB_R109396
            //
            bool isVerifyR109396 = VerifyResponse(nTTransIOCtlCopyChunkResponse1, nTTransIOCtlCopyChunkResponse2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR109396,
                109396,
                @"[In SRV_COPYCHUNK]Reserved (4 bytes):
                reply is the same whether zero or non-zero is used in this field.");

            #endregion

            #region Send the SMB_NT_TRANS_FSCTL_SRV request request

            nTTransIOCtlRequestResumeKeyRequest =
                smbClientStack.CreateNTTransIOCtlRequestResumeKeyRequest(fileId2, true, 0);

            smbHeader     = nTTransIOCtlRequestResumeKeyRequest.SmbHeader;
            smbHeader.Uid = sessionUid;
            smbHeader.Tid = treeId;
            nTTransIOCtlRequestResumeKeyRequest.SmbHeader = smbHeader;

            smbClientStack.SendPacket(nTTransIOCtlRequestResumeKeyRequest);
            response = smbClientStack.ExpectPacket(timeout);

            #endregion

            #region Capture reuqirements R9073

            nTTransIOCtlRequestResumeKeyResponse =
                (SmbNtTransFsctlSrvRequestResumeKeyResponsePacket)response;

            byte[] copychunkResumeKey3 = nTTransIOCtlRequestResumeKeyResponse.NtTransData.ResumeKey;

            //
            // Add the comment information for debugging
            //
            Site.Log.Add(
                LogEntryKind.Comment,
                @"Verify MS-SMB_R9073");

            //
            // Verify MS-SMB requirement: MS-SMB_R9073
            //
            bool isVerifyR9073 = CompareArrayEquals(copychunkResumeKey, copychunkResumeKey3);

            Site.CaptureRequirementIfIsFalse(
                isVerifyR9073,
                9073,
                @"[In Copychunk Resume Key Generation]
                The generation of Copychunk Resume Keys MUST satisfy the following constraints:
                The Copychunk Resume Key MUST be unique on the SMB server for a given open file on a server.");

            #endregion

            #region Disconnect the tree, session and connection.

            // TreeDisconnect
            SmbTreeDisconnectRequestPacket treeDisconnectRequest =
                smbClientStack.CreateTreeDisconnectRequest(treeId);

            smbClientStack.SendPacket(treeDisconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_DISCONNECT response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeDisconnectResponsePacket),
                "SMB_COM_TREE_DISCONNECT response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeDisconnectResponsePacket treeDisconnectResponse = (SmbTreeDisconnectResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeDisconnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_DISCONNECT response status should be SUCCESS.");

            // LogOff
            SmbLogoffAndxRequestPacket logoffRequest = smbClientStack.CreateLogoffRequest(sessionUid);

            smbClientStack.SendPacket(logoffRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_LOGOFF_ANDX response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbLogoffAndxResponsePacket),
                "SMB_COM_LOGOFF_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbLogoffAndxResponsePacket logoffResponse = (SmbLogoffAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                logoffResponse.SmbHeader.Status,
                "SMB_COM_LOGOFF_ANDX response status should be SUCCESS.");

            // Disconnect
            smbClientStack.Disconnect();

            Site.Assert.IsFalse(
                smbClientStack.IsDataAvailable,
                "SmbClient should not receive any packet after Disconnect method is called.");

            #endregion
        }
Exemplo n.º 41
0
 public StackPacketInfo(object localEp, object remoteEp, StackPacket pkt)
 {
     localEndPoint  = localEp;
     remoteEndpoint = remoteEp;
     packet         = pkt;
 }
        public void TraditionalTestCase_NetServerEnum3_06()
        {
            #region Connect to the specified server

            smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize);

            #endregion

            #region Send the Negotiate request

            // Create a SMB_COM_NEGOTIATE request.
            SmbNegotiateRequestPacket negotiateRequest =
                smbClientStack.CreateNegotiateRequest(
                    StackSmb.SignState.NONE,
                    new string[] {
                DialectNameString.PCNET1,
                DialectNameString.LANMAN10,
                DialectNameString.WFW10,
                DialectNameString.LANMAN12,
                DialectNameString.LANMAN21,
                DialectNameString.NTLANMAN
            });

            // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(negotiateRequest);
            StackPacket response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NEGOTIATE response should not be null.");

            // Check whether server returns a SMB_COM_NEGOTIATE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNegotiateResponsePacket),
                "SMB_COM_NEGOTIATE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                negotiateRequest.SmbHeader.Status,
                "SMB_COM_NEGOTIATE response status should be SUCCESS.");

            #endregion

            #region Send the first SMB_COM_SESSION_SETUP_ANDX  Request

            SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse(
                typeof(SmbSecurityPackage),
                Site.Properties["SmbSecurityPackageType"] as string,
                true);

            // Create the first SMB_COM_SESSION_SETUP_ANDX request.
            SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest =
                smbClientStack.CreateFirstSessionSetupRequest(
                    smbSecurityPackage,
                    serverName,
                    domainName,
                    userName,
                    password);

            // Send the first SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(sessionSetupAndxRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

            // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbSessionSetupAndxResponsePacket),
                "SMB_COM_SESSION_SETUP_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            // If SMB SecurityPackage type is NTLM, the expected SUCCESS response status is STATUS_MORE_PROCESSING_REQUIRED,
            // else if SMB SecurityPackage type is Kerberos, the expected SUCCESS response status is STATUS_SUCCESS.
            SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
            Site.Assert.IsTrue(
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED ||
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_SUCCESS,
                "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the second SMB_COM_SESSION_SETUP_ANDX  request

            // Create the second SMB_COM_SESSION_SETUP_ANDX request.
            ushort sessionUid = sessionSetupResponse.SmbHeader.Uid;

            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                SmbSessionSetupAndxRequestPacket secondSessionSetupRequest =
                    smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage);

                // Send the second SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
                smbClientStack.SendPacket(secondSessionSetupRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server return a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

                // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
                Site.Assert.IsInstanceOfType(
                    response,
                    typeof(SmbSessionSetupAndxResponsePacket),
                    "SMB_COM_SESSION_SETUP_ANDX response should be received.");

                // Check the response validity by verifying the Status field in the SMB Header packet.
                sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    sessionSetupResponse.SmbHeader.Status,
                    "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");
            }

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            string path = Site.Properties["SutNamedPipeFullName"];

            SmbTreeConnectAndxRequestPacket treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response;
            #endregion

            #region SMB transaction
            // System.Text.ASCIIEncoding.ASCII.GetBytes("WrLehDZz");
            byte[] paramDesc = new byte[] { 0x57, 0x72, 0x4c, 0x65, 0x68, 0x44, 0x7a, 0x7a, 0x00 };

            byte[] dataDesc            = new byte[] { 0x42, 0x31, 0x36, 0x42, 0x42, 0x44, 0x7a, 0x00 };
            byte[] rapParamsAndAuxDesc = new byte[] { 0x01, 0x00, 0xFF, 0xFF };

            byte[] rapInData = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0x45, 0x4e, 0x44, 0x50,
                                            0x4f, 0x49, 0x4e, 0x54, 0x30, 0x31, 0x00 };

            SmbTransRapRequestPacket netServerEnmum2Request =
                smbClientStack.CreateTransNamedRapRequest(treeConnectResponse.SmbHeader.Tid,
                                                          StackCifs.TransSmbParametersFlags.NONE,
                                                          (ushort)0x00D7,
                                                          paramDesc,
                                                          dataDesc,
                                                          rapParamsAndAuxDesc, rapInData);
            smbClientStack.SendPacket(netServerEnmum2Request);
            response = smbClientStack.ExpectPacket(timeout);
            #endregion
        }
        private T ExpectPacket <T>(TimeSpan timeout) where T : StackPacket
        {
            T receivedPacket = null;

            // Firstly, go through the receive buffer, if have packet with type T, return it.
            if (receiveBuffer.Count > 0)
            {
                lock (receiveBuffer)
                {
                    for (int i = 0; i < receiveBuffer.Count; i++)
                    {
                        if (receiveBuffer[i] is T)
                        {
                            receivedPacket = receiveBuffer[i] as T;
                            receiveBuffer.RemoveAt(i);
                            return(receivedPacket);
                        }
                    }
                }
            }

            // Then, expect new packet from lower level transport
            DateTime endTime = DateTime.Now + timeout;

            while (DateTime.Now < endTime)
            {
                timeout = endTime - DateTime.Now;
                if (timeout.TotalMilliseconds > 0)
                {
                    StackPacket packet = null;
                    try
                    {
                        packet = this.ExpectPdu(timeout);
                    }
                    catch (TimeoutException)
                    {
                        packet = null;
                    }

                    if (packet != null)
                    {
                        if (packet is T)
                        {
                            return(packet as T);
                        }
                        else if (packet is ErrorPdu)
                        {
                            DetectorUtil.WriteLog("Expect packste throws exception: " + string.Format(((ErrorPdu)packet).ErrorMessage));
                        }
                        else
                        {
                            // If the type of received packet is not T, add it into receive buffer
                            lock (receiveBuffer)
                            {
                                receiveBuffer.Add(packet);
                            }
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 44
0
        public void TraditionalTestCase_IgnoreFields_Create_01_Case()
        {
            #region Connect to the specified server

            smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize);

            #endregion

            #region Send the Negotiate request

            // Create a SMB_COM_NEGOTIATE request.
            SmbNegotiateRequestPacket negotiateRequest =
                smbClientStack.CreateNegotiateRequest(
                    StackSmb.SignState.NONE,
                    new string[] {
                DialectNameString.PCNET1,
                DialectNameString.LANMAN10,
                DialectNameString.WFW10,
                DialectNameString.LANMAN12,
                DialectNameString.LANMAN21,
                DialectNameString.NTLANMAN
            });

            // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(negotiateRequest);
            StackPacket response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NEGOTIATE response should not be null.");

            // Check whether server returns a SMB_COM_NEGOTIATE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNegotiateResponsePacket),
                "SMB_COM_NEGOTIATE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                negotiateRequest.SmbHeader.Status,
                "SMB_COM_NEGOTIATE response status should be SUCCESS.");

            #endregion

            #region Send the first SMB_COM_SESSION_SETUP_ANDX request

            SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse(
                typeof(SmbSecurityPackage),
                Site.Properties["SmbSecurityPackageType"] as string,
                true);

            // Create the first SMB_COM_SESSION_SETUP_ANDX request.
            SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest =
                smbClientStack.CreateFirstSessionSetupRequest(
                    smbSecurityPackage,
                    serverName,
                    domainName,
                    userName,
                    password);

            // Send the first SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(sessionSetupAndxRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

            // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbSessionSetupAndxResponsePacket),
                "SMB_COM_SESSION_SETUP_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            // If SMB SecurityPackage type is NTLM, the expected SUCCESS response status is STATUS_MORE_PROCESSING_REQUIRED,
            // else if SMB SecurityPackage type is Kerberos, the expected SUCCESS response status is STATUS_SUCCESS.
            SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
            Site.Assert.IsTrue(
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED ||
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_SUCCESS,
                "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            // Create the SMB_COM_TREE_CONNECT_ANDX request.
            string path = Site.Properties["SutNtfsShare1FullName"];
            SmbTreeConnectAndxRequestPacket treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(sessionSetupResponse.SmbHeader.Uid, path);

            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                // Send the SMB_COM_TREE_CONNECT_ANDX request and expect the response in timeout milliseconds.
                smbClientStack.SendPacket(treeconnectRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server returns a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_TREE_CONNECT_ANDX response should not be null.");

                #region Capture requirements r11008

                // Check the response validity by verifying the Status field in the SMB Header packet.
                SmbErrorResponsePacket smbErrorResponsePacket = response as SmbErrorResponsePacket;;

                // Add the debug information
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R11008");

                //
                // Verify MS-SMB requirement: MS-SMB_R11008
                //

                // When the session setup is in-progress, the client should have not been granted access, then expects a STATUS_ACCESS_DENIED from server
                Site.CaptureRequirementIfAreEqual <uint>(
                    (uint)MessageStatus.AccessDenied,
                    smbErrorResponsePacket.SmbHeader.Status,
                    11008,
                    @"[In Receiving an SMB_COM_TREE_CONNECT_ANDX Request] If no access is granted for the client on this share, 
                the server MUST fail the request with STATUS_ACCESS_DENIED.");

                #endregion
            }

            #endregion

            #region Send the second SMB_COM_SESSION_SETUP_ANDX  request

            // Create the second SMB_COM_SESSION_SETUP_ANDX request.
            ushort sessionUid = sessionSetupResponse.SmbHeader.Uid;

            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                SmbSessionSetupAndxRequestPacket secondSessionSetupRequest =
                    smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage);

                // Send the second SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
                smbClientStack.SendPacket(secondSessionSetupRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server return a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

                // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
                Site.Assert.IsInstanceOfType(
                    response,
                    typeof(SmbSessionSetupAndxResponsePacket),
                    "SMB_COM_SESSION_SETUP_ANDX response should be received.");

                // Check the response validity by verifying the Status field in the SMB Header packet.
                sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    sessionSetupResponse.SmbHeader.Status,
                    "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");
            }

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            // Create the SMB_COM_TREE_CONNECT_ANDX request.
            path = Site.Properties["SutNtfsShare1FullName"];
            treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            // Send the SMB_COM_TREE_CONNECT_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_CONNECT_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_TREE_CONNECT_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeConnectAndxResponsePacket),
                "SMB_COM_TREE_CONNECT_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeConnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_CONNECT_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            // Create the Create request.
            ushort treeId   = treeConnectResponse.SmbHeader.Tid;
            string fileName = Site.Properties["SutShareTest2"];
            SmbNtCreateAndxRequestPacket createRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName,
                    StackCifs.NtTransactDesiredAccess.GENERIC_READ
                    | StackCifs.NtTransactDesiredAccess.GENERIC_WRITE,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.NONE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                    CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            #region Set the request parameters

            StackCifs.SMB_COM_NT_CREATE_ANDX_Request_SMB_Parameters createRequestSmbParameters =
                createRequest.SmbParameters;

            // Reserved bits in ExtFileAttributes field set to 0.
            createRequestSmbParameters.ExtFileAttributes = 0;

            // Set the Flags field with
            // NT_CREATE_REQUEST_OPLOCK, NT_CREATE_OPEN_TARGET_DIR and NT_CREATE_REQUEST_EXTENDED_RESPONSE.
            createRequestSmbParameters.Flags = createRequestSmbParameters.Flags & (uint)(
                CreateFlags.NT_CREATE_REQUEST_OPLOCK
                | CreateFlags.NT_CREATE_OPEN_TARGET_DIR
                | CreateFlags.NT_CREATE_REQUEST_EXTENDED_RESPONSE);

            createRequest.SmbParameters = createRequestSmbParameters;

            #endregion

            // Send the SMB_COM_NT_CREATE_ANDX request with the File_Open_If flag and expect the response
            // in timeout milliseconds.
            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            // Check if server returns a SMB_COM_NT_CREATE_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse = (SmbNtCreateAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                createResponse.SmbHeader.Status,
                "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_CLOSE request

            // Create the Close request.
            ushort fileId = createResponse.SmbParameters.FID;
            SmbCloseRequestPacket CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            // Send the Close request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(CloseRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_CLOSE response should not be null.");

            // Check whether server returns a SMB_CLOSE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                "SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbCloseResponsePacket closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                "SMB_CLOSE response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            // Create the Create request.
            createRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName,
                    StackCifs.NtTransactDesiredAccess.GENERIC_READ
                    | StackCifs.NtTransactDesiredAccess.GENERIC_WRITE,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.NONE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                    CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            #region Set the request parameters

            createRequestSmbParameters = createRequest.SmbParameters;

            // The ExtFileAttributes field is set to ATTR_READONLY(0x001).
            createRequestSmbParameters.ExtFileAttributes = 1;

            // Set the Flags field with
            // NT_CREATE_REQUEST_OPLOCK, NT_CREATE_OPEN_TARGET_DIR and NT_CREATE_REQUEST_EXTENDED_RESPONSE.
            createRequestSmbParameters.Flags = createRequestSmbParameters.Flags & (uint)(
                CreateFlags.NT_CREATE_REQUEST_OPLOCK
                | CreateFlags.NT_CREATE_OPEN_TARGET_DIR
                | CreateFlags.NT_CREATE_REQUEST_EXTENDED_RESPONSE);

            createRequest.SmbParameters = createRequestSmbParameters;

            #endregion

            // Send the Create request with the File_Open_If flag and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse2 = (SmbNtCreateAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                createResponse2.SmbHeader.Status,
                "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

            #region Capture requirements r109027, r109243

            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109027");

            //
            // Verify MS-SMB requirement: MS-SMB_R109027
            //
            bool isVerifyR109027 = VerifyCreateResponse(createResponse, createResponse2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR109027,
                109027,
                @"[In Extended File Attribute (SMB_EXT_FILE_ATTR) Extensions]Reserved 0xFFFF8048:
                Reply is the same no matter what value is used.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109243");

            //
            // Verify MS-SMB requirement: MS-SMB_R109243
            //
            bool isVerifyR109243 = VerifyCreateResponse(createResponse, createResponse2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR109243,
                109243,
                @"[In Client Request Extensions]Flags (4 bytes):
                For Unused bits, reply is the same no matter what value is used.");

            #endregion

            #endregion

            #region Send the SMB_CLOSE request

            // Create the SMB_CLOSE request.
            fileId       = createResponse2.SmbParameters.FID;
            CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            // Send the Close request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(CloseRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_CLOSE response should not be null.");

            // Check whether server returns a SMB_CLOSE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                "SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                "SMB_CLOSE response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            // Create the SMB_COM_NT_CREATE_ANDX request.
            createRequest = smbClientStack.CreateCreateRequest(
                treeId,
                fileName,
                StackCifs.NtTransactDesiredAccess.GENERIC_READ
                | StackCifs.NtTransactDesiredAccess.GENERIC_WRITE,
                StackCifs.SMB_EXT_FILE_ATTR.NONE,
                StackCifs.NtTransactShareAccess.NONE,
                StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                NtTransactCreateOptions.FILE_OPEN_REQUIRING_OPLOCK,
                StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            // Send the Create request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_NT_CREATE_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse3 = (SmbNtCreateAndxResponsePacket)response;

            if (sutOsVersion == Platform.Win7 || sutOsVersion == Platform.Win2K8R2)
            {
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    createResponse3.SmbHeader.Status,
                    "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

                #region Cpature requirements r9459

                //
                // Add the comment information for debugging
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R9459");

                //
                // Verify MS-SMB requirement: MS-SMB_R9459
                //
                bool isVerifyR9549 = createResponse3.SmbHeader.Status == (uint)SmbStatus.STATUS_SUCCESS;

                Site.CaptureRequirementIfIsTrue(
                    isVerifyR9549,
                    9549,
                    @"<51> Section 2.2.4.9.1: Windows 7 and Windows Server 2008 R2 also support 
                    two new CreateOptions flags:FILE_OPEN_REQUIRING_OPLOCK (0x00010000),FILE_DISALLOW_EXCLUSIVE (0x00020000).");

                #endregion
            }

            #endregion

            #region Send the SMB_CLOSE request

            // Create the SMB_CLOSE request.
            fileId       = createResponse3.SmbParameters.FID;
            CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            // Send the Close request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(CloseRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_CLOSE response should not be null.");

            // Check whether server returns a SMB_CLOSE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                "SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                "SMB_CLOSE response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            // Create the SMB_COM_NT_CREATE_ANDX request.
            fileName      = Site.Properties["SutShareTest2"];
            createRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName,
                    StackCifs.NtTransactDesiredAccess.GENERIC_READ
                    | StackCifs.NtTransactDesiredAccess.GENERIC_WRITE,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.NONE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                    CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            #region Set the request parameters

            createRequestSmbParameters = createRequest.SmbParameters;
            createRequestSmbParameters.ExtFileAttributes = 0;

            // Set the Flags field with
            // NT_CREATE_REQUEST_OPLOCK, NT_CREATE_OPEN_TARGET_DIR and NT_CREATE_REQUEST_EXTENDED_RESPONSE.
            createRequestSmbParameters.Flags = createRequestSmbParameters.Flags & (uint)(
                CreateFlags.NT_CREATE_REQUEST_OPLOCK
                | CreateFlags.NT_CREATE_OPEN_TARGET_DIR
                | CreateFlags.NT_CREATE_REQUEST_EXTENDED_RESPONSE);

            createRequest.SmbParameters = createRequestSmbParameters;

            #endregion

            // Send the Create request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_NT_CREATE_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse4 = (SmbNtCreateAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                createResponse4.SmbHeader.Status,
                "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

            #region Cpature requirements r109550, r5227, r405227

            if (sutOsVersion == Platform.Win7 || sutOsVersion == Platform.Win2K8R2)
            {
                //
                // Add the comment information for debugging
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109550");

                //
                // Verify MS-SMB requirement: MS-SMB_R109550
                //
                bool isVerifyR109550 = VerifyCreateResponse(createResponse3, createResponse4);

                Site.CaptureRequirementIfIsTrue(
                    isVerifyR109550,
                    109550,
                    @"<51> Section 2.2.4.9.1:FILE_OPEN_REQUIRING_OPLOCK (0x00010000) 
                reply from Windows 7 and Windows Server 2008 R2  is the same 
                whether zero or non-zero is used in this field.");
            }

            // As all the marked Unused fields that have been ignored are verified, this RS is covered by it.
            Site.CaptureRequirement(
                5227,
                @"[In Message Syntax]Unless otherwise noted, 
                 whatever the values of fields marked as Unused are, reply is the same upon receipt.");

            // As all the unused or reserved bits in bit fields that are ignored, this RS can be verified directly.
            Site.CaptureRequirement(
                405227,
                @"[In Message Syntax]Unless otherwise noted, 
                 whatever the values of unused or reserved bits in bit fields  are, reply is the same upon receipt.");

            #endregion

            #endregion

            #region Send the SMB_CLOSE request

            // Create the SMB_CLOSE request.
            fileId       = createResponse4.SmbParameters.FID;
            CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            // Send the Close request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(CloseRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_CLOSE response should not be null.");

            // Check whether server returns a SMB_CLOSE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                "SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                "SMB_CLOSE response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            // Create the SMB_COM_NT_CREATE_ANDX request.
            createRequest = smbClientStack.CreateCreateRequest(
                treeId,
                fileName,
                StackCifs.NtTransactDesiredAccess.GENERIC_READ
                | StackCifs.NtTransactDesiredAccess.GENERIC_WRITE,
                StackCifs.SMB_EXT_FILE_ATTR.NONE,
                StackCifs.NtTransactShareAccess.NONE,
                StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                NtTransactCreateOptions.FILE_DISALLOW_EXCLUSIVE,
                StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            // Send the Create request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_NT_CREATE_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse5 = (SmbNtCreateAndxResponsePacket)response;

            if (sutOsVersion == Platform.Win7 || sutOsVersion == Platform.Win2K8R2)
            {
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    createResponse5.SmbHeader.Status,
                    "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

                #region Cpature requirements r9459, r119551

                //
                // Add the comment information for debugging
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R9459");

                //
                // Verify MS-SMB requirement: MS-SMB_R9459
                //
                bool isVerifyR9549 = createResponse5.SmbHeader.Status == (uint)SmbStatus.STATUS_SUCCESS;

                Site.CaptureRequirementIfIsTrue(
                    isVerifyR9549,
                    9549,
                    @"<51> Section 2.2.4.9.1: Windows 7 and Windows Server 2008 R2 also support 
                    two new CreateOptions flags:FILE_OPEN_REQUIRING_OPLOCK (0x00010000),FILE_DISALLOW_EXCLUSIVE (0x00020000).");

                //
                // Add the comment information for debugging
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R119551");

                //
                // Verify MS-SMB requirement: MS-SMB_R119551
                //
                bool isVerifyR119551 = VerifyCreateResponse(createResponse4, createResponse5);
                Site.CaptureRequirementIfIsTrue(
                    isVerifyR119551,
                    119551,
                    @"<51> Section 2.2.4.9.1: FILE_DISALLOW_EXCLUSIVE (0x00020000) reply from Windows 7 
                and Windows Server 2008 R2 is the same whether zero or non-zero is used in this field.");

                #endregion
            }

            #endregion

            #region Send the SMB_CLOSE request

            // Create the SMB_CLOSE request.
            fileId       = createResponse5.SmbParameters.FID;
            CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            // Send the Close request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(CloseRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_CLOSE response should not be null.");

            // Check whether server returns a SMB_CLOSE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                "SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                "SMB_CLOSE response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_TREE_DISCONNECT request

            // Create the SMB_COM_TREE_DISCONNECT request.
            SmbTreeDisconnectRequestPacket treeDisconnectRequest = smbClientStack.CreateTreeDisconnectRequest(treeId);

            // Send the TreeDisconnect request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(treeDisconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_DISCONNECT response should not be null.");

            // Check whether server returns a SMB_COM_TREE_DISCONNECT response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeDisconnectResponsePacket),
                "SMB_COM_TREE_DISCONNECT response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeDisconnectResponsePacket treeDisconnectResponse = (SmbTreeDisconnectResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeDisconnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_DISCONNECT response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_LOGOFF_ANDX request

            // Create the SMB_COM_LOGOFF_ANDX request.
            SmbLogoffAndxRequestPacket logoffRequest = smbClientStack.CreateLogoffRequest(sessionUid);

            // Send the LogOff request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(logoffRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_LOGOFF_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_LOGOFF_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbLogoffAndxResponsePacket),
                "SMB_COM_LOGOFF_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbLogoffAndxResponsePacket logoffResponse = (SmbLogoffAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                logoffResponse.SmbHeader.Status,
                "SMB_COM_LOGOFF_ANDX response status should be SUCCESS.");

            #endregion

            #region Disconnect

            // Disconnect
            smbClientStack.Disconnect();

            Site.Assert.IsFalse(
                smbClientStack.IsDataAvailable,
                "SmbClient should not receive any packet after Disconnect method is called.");

            #endregion
        }