コード例 #1
0
        /// <summary>
        /// Create  TRANS2_QUERY_PATH_INFORMATION Response 
        /// </summary>
        /// <param name="connection">the connection identified the client</param>
        /// <param name = "data">The Data buffer that contains the information bytes requested </param>
        /// <returns>The SmbTrans2QueryPathInformationResponsePacket </returns>
        /// <exception cref="ArgumentNullException">connection must not be null</exception>
        public virtual SmbTrans2QueryPathInformationResponsePacket CreateTrans2QueryPathInformationResponse(
            SmbServerConnection connection,
            object data)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            SmbTrans2QueryPathInformationResponsePacket packet = new SmbTrans2QueryPathInformationResponsePacket();

            // get the request packet
            SmbPacket request = connection.GetRequestPacket(connection.MessageId);

            // create smb packet header
            packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(
                SmbCommand.SMB_COM_TRANSACTION2,
                connection.ProcessId, connection.MessageId, request.SmbHeader.Uid, request.SmbHeader.Tid,
                (SmbFlags)connection.Capability.Flag, (SmbFlags2)connection.Capability.Flags2);

            // update smb parameters
            SMB_COM_TRANSACTION2_FinalResponse_SMB_Parameters smbParameters = packet.SmbParameters;

            smbParameters.Setup = new ushort[0];

            smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_TRANSACTION2_FinalResponse_SMB_Parameters>(
                smbParameters) / SmbCapability.NUM_BYTES_OF_WORD);

            // update smb data
            SMB_COM_TRANSACTION2_FinalResponse_SMB_Data smbData = packet.SmbData;

            // update trans2 param
            TRANS2_QUERY_PATH_INFORMATION_Response_Trans2_Parameters trans2Parameters = packet.Trans2Parameters;

            // update trans2 data
            TRANS2_QUERY_PATH_INFORMATION_Response_Trans2_Data trans2Data = packet.Trans2Data;

            trans2Data.Data = data;

            // store the parameters and data to packet.
            packet.Trans2Parameters = trans2Parameters;
            packet.Trans2Data = trans2Data;
            packet.SmbParameters = smbParameters;
            packet.SmbData = smbData;

            packet.UpdateCountAndOffset();

            return packet;
        }
コード例 #2
0
        private SmbPacket CreateTransaction2ResponsePacket(SmbPacket request, SmbHeader smbHeader, Channel channel)
        {
            SmbPacket smbPacket = null;

            if (smbHeader.Status == 0 && channel.Peek<byte>(0) == 0 && channel.Peek<ushort>(1) == 0)
            {
                return smbPacket;
            }

            SmbTransaction2RequestPacket transaction2Request = request as SmbTransaction2RequestPacket;
            if (transaction2Request == null)
            {
                return smbPacket;
            }

            // if no setup command. break
            if (transaction2Request.SmbParameters.SetupCount == 0)
            {
                return smbPacket;
            }

            // decode packet using the setup command
            switch ((Trans2SubCommand)transaction2Request.SmbParameters.Setup[0])
            {
                case Trans2SubCommand.TRANS2_QUERY_FILE_INFORMATION:
                    SmbTrans2QueryFileInformationRequestPacket queryFileRequest =
                        transaction2Request as SmbTrans2QueryFileInformationRequestPacket;
                    if (queryFileRequest != null)
                    {
                        smbPacket = new SmbTrans2QueryFileInformationResponsePacket(
                            queryFileRequest.Trans2Parameters.InformationLevel);
                    }
                    break;

                case Trans2SubCommand.TRANS2_QUERY_PATH_INFORMATION:
                    SmbTrans2QueryPathInformationRequestPacket queryPathRequest =
                       transaction2Request as SmbTrans2QueryPathInformationRequestPacket;
                    if (queryPathRequest != null)
                    {
                        smbPacket = new SmbTrans2QueryPathInformationResponsePacket(
                            queryPathRequest.Trans2Parameters.InformationLevel);
                    }
                    break;

                case Trans2SubCommand.TRANS2_SET_FILE_INFORMATION:
                    smbPacket = new SmbTrans2SetFileInformationResponsePacket();
                    break;

                case Trans2SubCommand.TRANS2_SET_PATH_INFORMATION:
                    smbPacket = new SmbTrans2SetPathInformationResponsePacket();
                    break;

                case Trans2SubCommand.TRANS2_QUERY_FS_INFORMATION:
                    SmbTrans2QueryFsInformationRequestPacket queryFsRequest =
                        transaction2Request as SmbTrans2QueryFsInformationRequestPacket;
                    if (queryFsRequest != null)
                    {
                        smbPacket = new SmbTrans2QueryFsInformationResponsePacket(
                            queryFsRequest.Trans2Parameters.InformationLevel);
                    }
                    break;

                case Trans2SubCommand.TRANS2_SET_FS_INFORMATION:
                    smbPacket = new SmbTrans2SetFsInformationResponsePacket();
                    break;

                case Trans2SubCommand.TRANS2_FIND_FIRST2:
                    SmbTrans2FindFirst2RequestPacket first2Request =
                       transaction2Request as SmbTrans2FindFirst2RequestPacket;
                    if (first2Request != null)
                    {
                        smbPacket = new SmbTrans2FindFirst2ResponsePacket(first2Request.Trans2Parameters.InformationLevel,
                            (first2Request.Trans2Parameters.Flags & Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS)
                            == Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS);
                    }
                    break;

                case Trans2SubCommand.TRANS2_FIND_NEXT2:
                    SmbTrans2FindNext2RequestPacket next2Request =
                       transaction2Request as SmbTrans2FindNext2RequestPacket;
                    if (next2Request != null)
                    {
                        smbPacket = new SmbTrans2FindNext2ResponsePacket(next2Request.Trans2Parameters.InformationLevel,
                            (next2Request.Trans2Parameters.Flags & Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS)
                            == Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS);
                    }
                    break;

                case Trans2SubCommand.TRANS2_GET_DFS_REFERRAL:
                    smbPacket = new SmbTrans2GetDfsReferralResponsePacket();
                    break;

                default:
                    break;
            }

            return smbPacket;
        }
コード例 #3
0
        private void FSCCTrans2QueryPathInformation(SmbTrans2QueryPathInformationResponsePacket
            smbTrans2QueryPathInformationPacket)
        {
            switch (fsccQueryPathLevel)
            {
                //FileBasicInformation,
                case 0:
                    NamespaceFscc.FsccFileBasicInformationResponsePacket fileBasicInformationResponse
                        = new NamespaceFscc.FsccFileBasicInformationResponsePacket();
                    fileBasicInformationResponse.FromBytes(smbTrans2QueryPathInformationPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileBasicInformation fileBasicInformation = fileBasicInformationResponse.Payload;

                    VerifyDataTypeFileBasicInformation(fileBasicInformation);

                    break;

                //FileStandardInformation,
                case 1:
                    NamespaceFscc.FsccFileStandardInformationResponsePacket fileStandardInformationResponse
                        = new NamespaceFscc.FsccFileStandardInformationResponsePacket();
                    fileStandardInformationResponse.FromBytes(smbTrans2QueryPathInformationPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileStandardInformation fileStandardInformation = fileStandardInformationResponse.Payload;

                    bool isFileDeletionRequested = Boolean.Parse(Site.Properties["IsFileDeletionRequestedForFscc"]);
                    bool isDirector = Boolean.Parse(Site.Properties["IsDirectorForFscc"]);

                    VerifyDataTypeFileStandardInformation(
                        fileStandardInformation,
                        isFileDeletionRequested,
                        isDirector);
                    break;

                //FileInternalInformation,
                case 2:
                    NamespaceFscc.FsccFileInternalInformationResponsePacket fileInternalInformationResponse
                        = new NamespaceFscc.FsccFileInternalInformationResponsePacket();
                    fileInternalInformationResponse.FromBytes(smbTrans2QueryPathInformationPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileInternalInformation fileInternalInformation = fileInternalInformationResponse.Payload;

                    bool isSupportFileReferenceNum = Boolean.Parse(Site.Properties["IsSupportFileReferenceNumForFscc"]);
                    VerifyDataTypeFileInternalInformation(fileInternalInformation, isSupportFileReferenceNum);
                    break;

                //FileEaInformation,
                case 3:
                    NamespaceFscc.FsccFileEaInformationResponsePacket fileEaInformationResponse
                        = new NamespaceFscc.FsccFileEaInformationResponsePacket();
                    fileEaInformationResponse.FromBytes(smbTrans2QueryPathInformationPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileEaInformation fileEaInformation = fileEaInformationResponse.Payload;

                    uint EAlength = uint.Parse(Site.Properties["EAlengthForFscc"]);
                    VerifyDataTypeFileEaInformation(fileEaInformation, EAlength);
                    break;

                //FileAccessInformation,
                case 4:
                    NamespaceFscc.FsccFileAccessInformationResponsePacket fileAccessInformationResponse
                        = new NamespaceFscc.FsccFileAccessInformationResponsePacket();
                    fileAccessInformationResponse.FromBytes(smbTrans2QueryPathInformationPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FILE_ACCESS_INFORMATION fileAccessInformation = fileAccessInformationResponse.Payload;

                    VerifyDataTypeFileAccessInformation(fileAccessInformation);
                    break;

                //FileNameInformation,
                case 5:
                    NamespaceFscc.FsccFileNameInformationResponsePacket fileNameInformationResponse
                        = new NamespaceFscc.FsccFileNameInformationResponsePacket();
                    fileNameInformationResponse.FromBytes(smbTrans2QueryPathInformationPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileNameInformation fileNameInformation = fileNameInformationResponse.Payload;

                    VerifyDataTypeFileNameInformation(fileNameInformation);
                    VerifyMessageSyntaxFileNameInformation(fileNameInformation);
                    break;

                //FileModeInformation,
                case 6:
                    NamespaceFscc.FsccFileModeInformationResponsePacket fileModeInformationResponse
                        = new NamespaceFscc.FsccFileModeInformationResponsePacket();
                    fileModeInformationResponse.FromBytes(smbTrans2QueryPathInformationPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FILE_MODE_INFORMATION fileModeInformation = fileModeInformationResponse.Payload;

                    bool isDeleteFile = Boolean.Parse(Site.Properties["IsDeleteFileForFscc"]);
                    VerifyMessageSyntaxFileModeinformation(fileModeInformation, isDeleteFile);

                    VerifyDataTypeFileModeInformation(fileModeInformation);
                    break;

                //FileAlignmentInformation,
                case 7:
                    NamespaceFscc.FsccFileAlignmentInformationResponsePacket fileAlignmentInformationResponse
                        = new NamespaceFscc.FsccFileAlignmentInformationResponsePacket();
                    fileAlignmentInformationResponse.FromBytes(smbTrans2QueryPathInformationPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FILE_ALIGNMENT_INFORMATION fileAlignmentInformation
                        = fileAlignmentInformationResponse.Payload;

                    VerifyDataTypeFileAlignmentInformation(
                        fileAlignmentInformation,
                        smbTrans2QueryPathInformationPacket.SmbData.Trans2_Data.Length);
                    break;

                //FileAlternateNameInformation,
                case 8:
                    NamespaceFscc.FsccFileAlternateNameInformationResponsePacket fileAlternateNameInformationResponse
                        = new NamespaceFscc.FsccFileAlternateNameInformationResponsePacket();
                    fileAlternateNameInformationResponse.FromBytes(smbTrans2QueryPathInformationPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileAlternateNameInformation fileAlternateNameInformation
                        = fileAlternateNameInformationResponse.Payload;

                    VerifyDataTypeFileAlternateNameInformation(fileAlternateNameInformation);
                    break;

                //FileStreamInformation,
                case 9:
                    NamespaceFscc.FsccFileStreamInformationResponsePacket fileStreamInformationResponse
                        = new NamespaceFscc.FsccFileStreamInformationResponsePacket();
                    fileStreamInformationResponse.FromBytes(smbTrans2QueryPathInformationPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileStreamInformation fileStreamInformation = fileStreamInformationResponse.Payload;

                    bool isNoOtherEntriesFollow = Boolean.Parse(Site.Properties["IsNoOtherEntriesFollowForFSCC"]);
                    bool isMultipleEntriesPresent = Boolean.Parse(Site.Properties["IsMultipleEntriesPresentForFSCC"]);
                    VerifyDataTypeFileStreamInformation(
                        fileStreamInformation,
                        isMultipleEntriesPresent,
                        isNoOtherEntriesFollow);
                    break;

                //FileCompressionInformation,
                case 10:
                    NamespaceFscc.FsccFileCompressionInformationResponsePacket fileCompressionInformationResponse
                        = new NamespaceFscc.FsccFileCompressionInformationResponsePacket();
                    fileCompressionInformationResponse.FromBytes(smbTrans2QueryPathInformationPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileCompressionInformation fileCompressionInformation
                        = fileCompressionInformationResponse.Payload;

                    int compressionFormat = int.Parse(Site.Properties["FompressionFormatForFSCC"]);
                    byte chunkShift = byte.Parse(Site.Properties["ChunkShiftForFSCC"]);
                    byte clusterShift = byte.Parse(Site.Properties["ClusterShiftForFSCC"]);
                    byte clusterSize = byte.Parse(Site.Properties["ClusterSizeForFSCC"]);
                    VerifyDataTypeFileCompressionInformationForOld(
                        fileCompressionInformation,
                        compressionFormat,
                        chunkShift,
                        clusterShift,
                        clusterSize);

                    string typeOfFileSystem = Site.Properties["TypeOfFileSystemForFscc"];
                    byte expectedInitializedClusterShift
                        = byte.Parse(Site.Properties["ExpectedInitializedClusterShiftForFscc"]);
                    VerifyDataTypeFileCompressionInformation(
                        fileCompressionInformation,
                        typeOfFileSystem,
                        expectedInitializedClusterShift
                        );

                    break;

                //FileNetworkOpenInformation,
                case 11:
                    NamespaceFscc.FsccFileNetworkOpenInformationResponsePacket fileNetworkOpenInformationResponse
                        = new NamespaceFscc.FsccFileNetworkOpenInformationResponsePacket();
                    fileNetworkOpenInformationResponse.FromBytes(smbTrans2QueryPathInformationPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileNetworkOpenInformation fileNetworkOpenInformation
                        = fileNetworkOpenInformationResponse.Payload;

                    int allocationSize = int.Parse(Site.Properties["AllocationSizeForFSCC"]);
                    uint fileAttributes = uint.Parse(Site.Properties["FileAttributesForFSCC"]);
                    VerifyDataTypeFileNetworkOpenInformation(
                        fileNetworkOpenInformation,
                        allocationSize,
                        fileAttributes);
                    break;

                //FileAttributeTagInformation,
                case 12:
                    NamespaceFscc.FsccFileAttributeTagInformationResponsePacket fileAttributeTagInformationResponse
                        = new NamespaceFscc.FsccFileAttributeTagInformationResponsePacket();
                    fileAttributeTagInformationResponse.FromBytes(smbTrans2QueryPathInformationPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FileAttributeTagInformation fileAttributeTagInformation
                        = fileAttributeTagInformationResponse.Payload;

                    uint fileAttributesTag = uint.Parse(Site.Properties["FileAttributesForFSCC"]);
                    VerifyDataTypeFileAttributeTagInformation(fileAttributeTagInformation, fileAttributesTag);
                    break;

                case 13://FilePositionInformation
                    NamespaceFscc.FsccFilePositionInformationResponsePacket filePositionInformationResponse
                        = new NamespaceFscc.FsccFilePositionInformationResponsePacket();
                    filePositionInformationResponse.FromBytes(smbTrans2QueryPathInformationPacket.SmbData.Trans2_Data);
                    NamespaceFscc.FILE_POSITION_INFORMATION filePositionInformation
                        = filePositionInformationResponse.Payload;

                    VerifyDataTypeFilePositionInformation(filePositionInformation);

                    break;
                default:
                    break;
            }
        }
コード例 #4
0
        private SmbPacket CreateTransaction2ResponsePacket(SmbPacket request, SmbHeader smbHeader, Channel channel)
        {
            SmbPacket smbPacket = null;

            if (smbHeader.Status == 0 && channel.Peek <byte>(0) == 0 && channel.Peek <ushort>(1) == 0)
            {
                return(smbPacket);
            }

            SmbTransaction2RequestPacket transaction2Request = request as SmbTransaction2RequestPacket;

            if (transaction2Request == null)
            {
                return(smbPacket);
            }

            // if no setup command. break
            if (transaction2Request.SmbParameters.SetupCount == 0)
            {
                return(smbPacket);
            }

            // decode packet using the setup command
            switch ((Trans2SubCommand)transaction2Request.SmbParameters.Setup[0])
            {
            case Trans2SubCommand.TRANS2_QUERY_FILE_INFORMATION:
                SmbTrans2QueryFileInformationRequestPacket queryFileRequest =
                    transaction2Request as SmbTrans2QueryFileInformationRequestPacket;
                if (queryFileRequest != null)
                {
                    smbPacket = new SmbTrans2QueryFileInformationResponsePacket(
                        queryFileRequest.Trans2Parameters.InformationLevel);
                }
                break;

            case Trans2SubCommand.TRANS2_QUERY_PATH_INFORMATION:
                SmbTrans2QueryPathInformationRequestPacket queryPathRequest =
                    transaction2Request as SmbTrans2QueryPathInformationRequestPacket;
                if (queryPathRequest != null)
                {
                    smbPacket = new SmbTrans2QueryPathInformationResponsePacket(
                        queryPathRequest.Trans2Parameters.InformationLevel);
                }
                break;

            case Trans2SubCommand.TRANS2_SET_FILE_INFORMATION:
                smbPacket = new SmbTrans2SetFileInformationResponsePacket();
                break;

            case Trans2SubCommand.TRANS2_SET_PATH_INFORMATION:
                smbPacket = new SmbTrans2SetPathInformationResponsePacket();
                break;

            case Trans2SubCommand.TRANS2_QUERY_FS_INFORMATION:
                SmbTrans2QueryFsInformationRequestPacket queryFsRequest =
                    transaction2Request as SmbTrans2QueryFsInformationRequestPacket;
                if (queryFsRequest != null)
                {
                    smbPacket = new SmbTrans2QueryFsInformationResponsePacket(
                        queryFsRequest.Trans2Parameters.InformationLevel);
                }
                break;

            case Trans2SubCommand.TRANS2_SET_FS_INFORMATION:
                smbPacket = new SmbTrans2SetFsInformationResponsePacket();
                break;

            case Trans2SubCommand.TRANS2_FIND_FIRST2:
                SmbTrans2FindFirst2RequestPacket first2Request =
                    transaction2Request as SmbTrans2FindFirst2RequestPacket;
                if (first2Request != null)
                {
                    smbPacket = new SmbTrans2FindFirst2ResponsePacket(first2Request.Trans2Parameters.InformationLevel,
                                                                      (first2Request.Trans2Parameters.Flags & Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS)
                                                                      == Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS);
                }
                break;

            case Trans2SubCommand.TRANS2_FIND_NEXT2:
                SmbTrans2FindNext2RequestPacket next2Request =
                    transaction2Request as SmbTrans2FindNext2RequestPacket;
                if (next2Request != null)
                {
                    smbPacket = new SmbTrans2FindNext2ResponsePacket(next2Request.Trans2Parameters.InformationLevel,
                                                                     (next2Request.Trans2Parameters.Flags & Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS)
                                                                     == Trans2FindFlags.SMB_FIND_RETURN_RESUME_KEYS);
                }
                break;

            case Trans2SubCommand.TRANS2_GET_DFS_REFERRAL:
                smbPacket = new SmbTrans2GetDfsReferralResponsePacket();
                break;

            default:
                break;
            }

            return(smbPacket);
        }