/// <summary> /// to decode the smb parameters: from the general SmbParameters to the concrete Smb Parameters. /// </summary> protected override void DecodeParameters() { this.smbParameters = TypeMarshal.ToStruct<SMB_COM_TREE_CONNECT_ANDX_Request_SMB_Parameters>( TypeMarshal.ToBytes(this.smbParametersBlock)); }
/// <summary> /// to create a TreeConnectAndx request packet. /// </summary> /// <param name="messageId">This field SHOULD be the multiplex ID that is used to associate a response with a /// request.</param> /// <param name="uid">This field SHOULD identify the authenticated instance of the user.</param> /// <param name="flags">An 8-bit field of 1-bit flags describing various features in effect for the /// message</param> /// <param name="flags2">A 16-bit field of 1-bit flags that represent various features in effect for the /// message. Unspecified bits are reserved and MUST be zero.</param> /// <param name="smbParametersFlags">USHORT A 16-bit field used to modify the SMB_COM_TREE_CONNECT_ANDX /// request. The client MUST set reserved values to 0, and the server MUST ignore them.</param> /// <param name="path">STRING A null-terminated string that represents the server and share name of the resource /// to which the client is attempting to connect</param> /// <param name="service">The type of resource that the client intends to access</param> /// <param name="password">A null-terminated string that represents a share password in plaintext form.</param> /// <param name="andxPacket">the andx packet.</param> /// <returns>a TreeConnectAndx request packet</returns> public SmbTreeConnectAndxRequestPacket CreateTreeConnectAndxRequest( ushort messageId, ushort uid, SmbFlags flags, SmbFlags2 flags2, TreeConnectAndxFlags smbParametersFlags, string path, string service, byte[] password, SmbPacket andxPacket) { if (path == null) { path = string.Empty; } if (service == null) { service = string.Empty; } if (password == null) { password = new byte[0]; } SmbTreeConnectAndxRequestPacket packet = new SmbTreeConnectAndxRequestPacket(); packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_TREE_CONNECT_ANDX, messageId, uid, 0, flags, flags2); SMB_COM_TREE_CONNECT_ANDX_Request_SMB_Parameters smbParameters = new SMB_COM_TREE_CONNECT_ANDX_Request_SMB_Parameters(); if (andxPacket == null) { smbParameters.AndXCommand = SmbCommand.SMB_COM_NO_ANDX_COMMAND; } else { smbParameters.AndXCommand = andxPacket.SmbHeader.Command; } smbParameters.AndXReserved = 0; smbParameters.Flags = (ushort)smbParametersFlags; smbParameters.PasswordLength = (ushort)password.Length; smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord); SMB_COM_TREE_CONNECT_ANDX_Request_SMB_Data smbData = new SMB_COM_TREE_CONNECT_ANDX_Request_SMB_Data(); smbData.Password = password; if ((flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE) { smbData.Pad = new byte[(smbData.Password.Length + 1) % 2]; smbData.Path = CifsMessageUtils.ToSmbStringBytes(path, true); } else { smbData.Pad = new byte[0]; smbData.Path = CifsMessageUtils.ToSmbStringBytes(path, false); } smbData.Service = CifsMessageUtils.ToSmbStringBytes(service, false); smbData.ByteCount = (ushort)(smbData.Password.Length + smbData.Pad.Length + smbData.Path.Length + smbData.Service.Length); packet.SmbParameters = smbParameters; packet.SmbData = smbData; packet.AndxPacket = andxPacket; return packet; }
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 }
public void TraditionalTestCase_Disconnect_14_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 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 the 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; treeconnectRequestSmbParameters.Flags = (ushort)(treeconnectRequestSmbParameters.Flags | (ushort)StackSmb.TreeConnectFlags.TREE_CONNECT_ANDX_DISCONNECT_TID); 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_NT_CREATE_ANDX request // Create the SMB_COM_NT_CREATE_ANDX 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); // Send the SMB_COM_NT_CREATE_ANDX request and expect a response in the 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 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 NT_TRANSACT_QUERY_QUOTA request // 0 indicates that there is no SidList. int sidListLength = 0; // 0 indicates that there is no StartSid. int startSidLength = 0; // 90 represents the offset of the StartSid in the parameter buffer. int startSidOffset = 90; // Create the NT_TRANSACT_QUERY_QUOTA request. ushort fileId = createResponse.SmbParameters.FID; SmbNtTransQueryQuotaRequestPacket nTTransQueryQuotaRequest = smbClientStack.CreateNTTransQueryQuotaRequest( fileId, true, false, sidListLength, startSidLength, startSidOffset); // Send the NT_TRANSACT_QUERY_QUOTA request and expect a response in the timeout milliseconds. smbClientStack.SendPacket(nTTransQueryQuotaRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "NT_TRANSACT_QUERY_QUOTA response should not be null."); // Check whether server returns a NT_TRANSACT_QUERY_QUOTA response. Site.Assert.IsInstanceOfType( response, typeof(SmbNtTransQueryQuotaResponsePacket), "NT_TRANSACT_QUERY_QUOTA response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbNtTransQueryQuotaResponsePacket nTTransQueryQuotaResponse = (SmbNtTransQueryQuotaResponsePacket)response; Site.Assert.AreEqual <uint>( (uint)SmbStatus.STATUS_SUCCESS, nTTransQueryQuotaResponse.SmbHeader.Status, "NT_TRANSACT_QUERY_QUOTA response status should be SUCCESS."); // Check the response validity by verifying the ParameterCount field in the response. Site.Assert.AreEqual <uint>( 4, nTTransQueryQuotaResponse.SmbParameters.ParameterCount, "parameterCount should be 4 in the nTTransQueryQuota response"); #endregion #region Capture requirement r10357 // according to theTD , 0x0001 is the value of, TREE_CONNECT_ANDX_DISCONNECT_TID. if (((uint)nTTransQueryQuotaRequest.SmbHeader.Flags & 0x0001) == 0x0001) { // The logic above has disconnect the tree connect specified by the TID // in the SMB header of the request. this RS has been verified as it. Site.CaptureRequirement( 10357, @"[In Client Request Extensions,TREE_CONNECT_ANDX_DISCONNECT_TID] If set, the tree connect specified by the TID in the SMB header of the request is disconnected when the server sends the response in Windows."); } #endregion #region Disconnect // Disconnect smbClientStack.Disconnect(); Site.Assert.IsFalse( smbClientStack.IsDataAvailable, "SmbClient should not receive any packet after Disconnect method is called."); #endregion }