internal ReconstructedFile(string path, NetworkHost sourceHost, NetworkHost destinationHost, ushort sourcePort, ushort destinationPort, bool tcpTransfer, FileStreamTypes fileStreamType, string details, int initialFrameNumber, DateTime timestamp)
        {
            this.path = path;
            try {
                if (path.Contains("\\"))
                {
                    this.filename = path.Substring(path.LastIndexOf('\\') + 1);
                }
                else if (path.Contains("/"))
                {
                    this.filename = path.Substring(path.LastIndexOf('/') + 1);
                }
                else
                {
                    this.filename = path;
                }
            }
            catch (Exception) {
                this.filename = "";
            }
            this.sourceHost      = sourceHost;
            this.destinationHost = destinationHost;
            this.sourcePort      = sourcePort;
            this.destinationPort = destinationPort;
            this.tcpTransfer     = tcpTransfer;
            this.fileStreamType  = fileStreamType;
            this.details         = details;

            System.IO.FileInfo fi = new System.IO.FileInfo(path);
            this.fileSize           = fi.Length;
            this.initialFrameNumber = initialFrameNumber;
            this.timestamp          = timestamp;
        }
 private FileSegmentAssembler(string fileOutputDirectory, string filePath, string uniqueFileId, FileTransfer.FileStreamAssemblerList fileStreamAssemblerList, PopularityList <string, PacketParser.FileTransfer.FileSegmentAssembler> parentAssemblerList, FileStreamTypes fileStreamType, string details, string serverHostname)
 {
     this.fileOutputDirectory = fileOutputDirectory;
     //this.fileTransferIsServerToClient = fileTransferIsServerToClient;
     this.filePath                = filePath;
     this.uniqueFileId            = uniqueFileId;
     this.parentAssemblerList     = parentAssemblerList;
     this.fileStreamAssemblerList = fileStreamAssemblerList;
     this.fileStreamType          = fileStreamType;
     this.details        = details;
     this.serverHostname = serverHostname;
 }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sourceHost"></param>
        /// <param name="sourcePort"></param>
        /// <param name="destinationHost"></param>
        /// <param name="destinationPort"></param>
        /// <param name="tcpTransfer">True=TCP, False=UDP</param>
        /// <param name="fileStreamType"></param>
        /// <param name="filename">for example "image.gif"</param>
        /// <param name="fileLocation">for example "/images", empty string for root folder</param>
        internal FileStreamAssembler(FileStreamAssemblerList parentAssemblerList, NetworkHost sourceHost, ushort sourcePort, NetworkHost destinationHost, ushort destinationPort, bool tcpTransfer, FileStreamTypes fileStreamType, string filename, string fileLocation, int fileContentLength, int fileSegmentRemainingBytes, string details, string extendedFileId, int initialFrameNumber, DateTime timestamp)
        {
            this.parentAssemblerList       = parentAssemblerList;
            this.sourceHost                = sourceHost;
            this.sourcePort                = sourcePort;
            this.destinationHost           = destinationHost;
            this.destinationPort           = destinationPort;
            this.tcpTransfer               = tcpTransfer;
            this.fileStreamType            = fileStreamType;
            this.fileContentLength         = fileContentLength;//this one can not be set already when the client requests the file...so it has to be changed later
            this.fileSegmentRemainingBytes = fileSegmentRemainingBytes;
            this.details            = details;
            this.contentEncoding    = Packets.HttpPacket.ContentEncodings.Identity;//default
            this.isActive           = false;
            this.extendedFileId     = extendedFileId;
            this.initialFrameNumber = initialFrameNumber;
            this.timestamp          = timestamp;

            this.filename     = filename;
            this.fileLocation = fileLocation;



            //Sigh I just hate the limitation on file and folder length.
            //See: http://msdn2.microsoft.com/en-us/library/aa365247.aspx
            //Or: http://blogs.msdn.com/bclteam/archive/2007/02/13/long-paths-in-net-part-1-of-3-kim-hamilton.aspx

            //see if there is any fileLocation info in the filename and move it to the fileLocation
            FixFilenameAndLocation(ref this.filename, ref this.fileLocation);



            this.assembledByteCount    = 0;
            this.tcpPacketBufferWindow = new SortedList <uint, byte[]>();

            if (isActive)
            {
                this.fileStream = new System.IO.FileStream(GetFilePath(true), System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite);
            }
            else
            {
                this.fileStream = null;
            }
        }
示例#4
0
        internal ReconstructedFile(string path, Uri relativeUri, FiveTuple fiveTuple, bool transferIsClientToServer, FileStreamTypes fileStreamType, string details, long initialFrameNumber, DateTime timestamp, string serverHostname)
        {
            this.path        = path;
            this.RelativeUri = relativeUri;
            try {
                if (path.Contains("\\"))
                {
                    this.filename = path.Substring(path.LastIndexOf('\\') + 1);
                }
                else if (path.Contains("/"))
                {
                    this.filename = path.Substring(path.LastIndexOf('/') + 1);
                }
                else
                {
                    this.filename = path;
                }
            }
            catch (Exception) {
                this.filename = "";
            }
            this.fiveTuple = fiveTuple;
            this.transferIsClientToServer = transferIsClientToServer;

            /*
             * this.sourceHost=sourceHost;
             * this.destinationHost=destinationHost;
             * this.sourcePort=sourcePort;
             * this.destinationPort=destinationPort;
             * this.tcpTransfer=tcpTransfer;
             */
            this.fileStreamType = fileStreamType;
            this.details        = details;

            System.IO.FileInfo fi = new System.IO.FileInfo(path);
            this.fileSize           = fi.Length;
            this.initialFrameNumber = initialFrameNumber;
            this.timestamp          = timestamp;
            this.serverHostname     = serverHostname;

            //SharedUtils.Logger.Log("Reconstructed file: " + fi.Name, System.Diagnostics.EventLogEntryType.Information);
        }
示例#5
0
        internal PartialFileAssembler(FileStreamAssembler.FileAssmeblyRootLocation fileAssmeblyRootLocation, FiveTuple fiveTuple, bool transferIsClientToServer, FileStreamTypes fileStreamType, string fileLocation, string filename, FileStreamAssemblerList parentAssemblerList, string extendedFileId, long totalFileSize, long initialFrameNumber, string serverHostname)
        {
            this.fileAssmeblyRootLocation = fileAssmeblyRootLocation;

            /*
             * this.tcpTransfer = tcpTransfer;
             * this.sourceHost = sourceHost;
             * this.destinationHost = destinationHost;
             * this.sourcePort = sourcePort;
             * this.destinationPort = destinationPort;
             */
            this.fiveTuple = fiveTuple;
            this.transferIsClientToServer = transferIsClientToServer;
            this.fileStreamType           = fileStreamType;
            this.fileLocation             = fileLocation;
            this.filename            = filename;
            this.parentAssemblerList = parentAssemblerList;
            this.extendedFileId      = extendedFileId;
            this.totalFileSize       = totalFileSize;
            //this.originalLocation = originalLocation;
            this.filePartList       = new SortedList <long, ReconstructedFile>();
            this.initialFrameNumber = initialFrameNumber;
            this.serverHostname     = serverHostname;
        }
 public AuFileAssembler(string auFilename, FileStreamAssemblerList fileStreamAssemblerList, FiveTuple fiveTuple, FileStreamTypes fileStreamType, long initialFrameNumber, DateTime startTime, Encoding auEncoding, uint sampleRate = 8000) :
     base(fileStreamAssemblerList, fiveTuple, true, fileStreamType, auFilename, "/", fileStreamType.ToString() + " " + fiveTuple.ToString(), initialFrameNumber, startTime)
 {
     this.sampleRate = sampleRate;
     this.AuEncoding = auEncoding;
     //unknown file size
     this.FileContentLength         = -1;
     this.FileSegmentRemainingBytes = -1;
 }
 internal IEnumerable <FileStreamAssembler> GetAssemblers(NetworkHost sourceHost, NetworkHost destinationHost, FileStreamTypes fileStreamType, bool isActive)
 {
     foreach (FileStreamAssembler assembler in base.GetValueEnumerator())
     {
         if (assembler.IsActive == isActive && assembler.SourceHost == sourceHost && assembler.DestinationHost == destinationHost && assembler.FileStreamType == fileStreamType)
         {
             yield return(assembler);
         }
     }
     yield break;
 }
        /*
         * internal bool ContainsAssembler(NetworkHost sourceHost, ushort sourcePort, NetworkHost destinationHost, ushort destinationPort, bool tcpTransfer, bool assemblerIsAcive, FileStreamTypes fileStreamType){
         *  string id=GetAssemblerId(sourceHost, sourcePort, destinationHost, destinationPort, tcpTransfer);
         *  return (base.ContainsKey(id) && base[id].FileStreamType==fileStreamType && base[id].IsActive==assemblerIsAcive);
         * }
         */
        internal bool ContainsAssembler(FiveTuple fiveTuple, bool transferIsClientToServer, bool assemblerIsAcive, FileStreamTypes fileStreamType)
        {
            string id = GetAssemblerId(fiveTuple, transferIsClientToServer);

            return(base.ContainsKey(id) && base[id].FileStreamType == fileStreamType && base[id].IsActive == assemblerIsAcive);
        }
        internal FileSegmentAssembler(string fileOutputDirectory, NetworkTcpSession networkTcpSession, bool transferIsClientToServer, string filePath, string uniqueFileId, FileTransfer.FileStreamAssemblerList fileStreamAssemblerList, PopularityList <string, PacketParser.FileTransfer.FileSegmentAssembler> parentAssemblerList, FileStreamTypes fileStreamType, string details, string serverHostname)
            : this(fileOutputDirectory, filePath, uniqueFileId, fileStreamAssemblerList, parentAssemblerList, fileStreamType, details, serverHostname)
        {
            //this.fileOutputDirectory = fileOutputDirectory;

            //this.networkTcpSession = networkTcpSession;
            this.fiveTuple = networkTcpSession.Flow.FiveTuple;
            this.transferIsClientToServer = transferIsClientToServer;

            /*
             * if (this.fileTransferIsServerToClient) {
             *  this.sourceHost = networkTcpSession.ServerHost;
             *  this.destinationHost = networkTcpSession.ClientHost;
             *  this.sourcePort = networkTcpSession.ServerTcpPort;
             *  this.destinationPort = networkTcpSession.ClientTcpPort;
             * }
             * else {
             *  this.sourceHost = networkTcpSession.ClientHost;
             *  this.destinationHost = networkTcpSession.ServerHost;
             *  this.sourcePort = networkTcpSession.ClientTcpPort;
             *  this.destinationPort = networkTcpSession.ServerTcpPort;
             * }*/

            /*
             * this.filePath = filePath;
             * this.uniqueFileId = uniqueFileId;
             * this.parentAssemblerList = parentAssemblerList;
             * this.fileStreamAssemblerList = fileStreamAssemblerList;
             * this.fileStreamType = fileStreamType;
             * this.details = details;
             */
        }
        internal FileSegmentAssembler(string fileOutputDirectory, bool transferIsClientToServer, string filePath, string uniqueFileId, FileTransfer.FileStreamAssemblerList fileStreamAssemblerList, PopularityList <string, PacketParser.FileTransfer.FileSegmentAssembler> parentAssemblerList, FileStreamTypes fileStreamType, string details, FiveTuple fiveTuple, string serverHostname)
            : this(fileOutputDirectory, filePath, uniqueFileId, fileStreamAssemblerList, parentAssemblerList, fileStreamType, details, serverHostname)
        {
            this.fiveTuple = fiveTuple;
            this.transferIsClientToServer = transferIsClientToServer;

            /*
             * this.sourceHost = sourceHost;
             * this.destinationHost = destinationHost;
             * this.sourcePort = sourcePort;
             * this.destinationPort = destinationPort;
             */
        }
示例#11
0
        private static string GetFilePath(bool tempCachePath, bool tcpTransfer, System.Net.IPAddress sourceIp, System.Net.IPAddress destinationIp, ushort sourcePort, ushort destinationPort, FileStreamTypes fileStreamType, string fileLocation, string filename, FileStreamAssemblerList parentAssemblerList, string extendedFileId)
        {
            //sanitize filename
            if (filename.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) >= 0)
            {
                foreach (char c in System.IO.Path.GetInvalidFileNameChars())
                {
                    filename.Replace(c, '_');
                }
            }

            //sanitize file location
            fileLocation = fileLocation.Replace("..", "_");//just to ensure that no file is written to a parent directory
            if (fileLocation.IndexOfAny(System.IO.Path.GetInvalidPathChars()) >= 0)
            {
                foreach (char c in System.IO.Path.GetInvalidPathChars())
                {
                    fileLocation.Replace(c, '_');
                }
            }

            string filePath;
            string protocolString;

            if (fileStreamType == FileStreamTypes.HttpGetNormal || fileStreamType == FileStreamTypes.HttpGetChunked)
            {
                protocolString = "HTTP";
            }
            else if (fileStreamType == FileStreamTypes.SMB)
            {
                protocolString = "SMB";
            }
            else if (fileStreamType == FileStreamTypes.TFTP)
            {
                protocolString = "TFTP";
            }
            else if (fileStreamType == FileStreamTypes.TlsCertificate)
            {
                protocolString = "TLS_Cert";
            }
            else if (fileStreamType == FileStreamTypes.FTP)
            {
                protocolString = "FTP";
            }
            else if (fileStreamType == FileStreamTypes.HttpPostMimeMultipartFormData)
            {
                protocolString = "MIME_form-data";
            }
            else if (fileStreamType == FileStreamTypes.HttpPostMimeFileData)
            {
                protocolString = "MIME_file-data";
            }
            else if (fileStreamType == FileStreamTypes.OscarFileTransfer)
            {
                protocolString = "OSCAR";
            }
            else if (fileStreamType == FileStreamTypes.SMTP)
            {
                protocolString = "SMTP";
            }
            else
            {
                throw new Exception("Not implemented yet");
            }

            string transportString;

            if (tcpTransfer)
            {
                transportString = "TCP";
            }
            else
            {
                transportString = "UDP";
            }



            if (tempCachePath)
            {
                filePath = "cache/" + sourceIp.ToString().Replace(':', '-') + "_" + transportString + sourcePort.ToString() + " - " + destinationIp.ToString().Replace(':', '-') + "_" + transportString + destinationPort.ToString() + "_" + protocolString + extendedFileId + ".txt";//with extendedFileId 2011-04-18
                //filePath = "cache/" + sourceIp.ToString().Replace(':', '-') + "_" + transportString + sourcePort.ToString() + " - " + destinationIp.ToString().Replace(':', '-') + "_" + transportString + destinationPort.ToString() + "_" + protocolString + ".txt";//without extendedFileId
            }
            else
            {
                filePath = sourceIp.ToString().Replace(':', '-') + "/" + protocolString + " - " + transportString + " " + sourcePort.ToString() + fileLocation + "/" + filename;
                try {
                    System.IO.Path.GetDirectoryName(filePath);
                }
                catch {
                    //something could be wrong with the path.. so let's replace it with something that should work better
                    //Examples of things that can go wrong is that the file or directory has a reserved name (like COM2, CON or LPT1) as shown here:
                    //http://www.ureader.com/msg/144639432.aspx
                    //http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
                    filePath = sourceIp.ToString().Replace(':', '-') + "/" + protocolString + " - " + transportString + " " + sourcePort.ToString() + "/" + System.IO.Path.GetRandomFileName();
                }
            }


            //filePath=System.IO.Path.GetDirectoryName(parentAssemblerList.FileOutputFolder)+"\\"+filePath;
            filePath = parentAssemblerList.FileOutputDirectory + System.IO.Path.DirectorySeparatorChar + filePath;

            if (System.IO.Path.DirectorySeparatorChar != '/' && filePath.Contains("/"))
            {
                filePath = filePath.Replace('/', System.IO.Path.DirectorySeparatorChar);
            }

            /*if(filePath.Length>=248)
             *  filePath="\\\\?\\"+filePath;*/

            if (!tempCachePath && System.IO.File.Exists(filePath))
            {
                //change filename to avoid overwriting previous files
                int    iterator = 1;
                string filePathPrefix;
                string filePathSuffix;                             //including the "." as in ".txt"
                //now, find the breakpoint in filePath where "[1]" should be inserted
                int extentionPosition = filePath.LastIndexOf('.'); //The index position of value if that character is found, or -1 if it is not
                int filenamePosition  = filePath.LastIndexOf(System.IO.Path.DirectorySeparatorChar);

                if (extentionPosition < 0)
                {
                    filePathPrefix = filePath;
                    filePathSuffix = "";
                }
                else if (extentionPosition > filenamePosition)
                {
                    filePathPrefix = filePath.Substring(0, extentionPosition);
                    filePathSuffix = filePath.Substring(extentionPosition);
                }
                else
                {
                    filePathPrefix = filePath;
                    filePathSuffix = "";
                }

                string uniqueFilePath = filePathPrefix + "[" + iterator + "]" + filePathSuffix;
                while (System.IO.File.Exists(uniqueFilePath))
                {
                    iterator++;
                    uniqueFilePath = filePathPrefix + "[" + iterator + "]" + filePathSuffix;
                }
                filePath = uniqueFilePath;
            }

            return(filePath);
        }
示例#12
0
 internal FileStreamAssembler(FileStreamAssemblerList parentAssemblerList, NetworkHost sourceHost, ushort sourcePort, NetworkHost destinationHost, ushort destinationPort, bool tcpTransfer, FileStreamTypes fileStreamType, string filename, string fileLocation, string details, string extendedFileId, int initialFrameNumber, DateTime timestamp)
     :
     this(parentAssemblerList, sourceHost, sourcePort, destinationHost, destinationPort, tcpTransfer, fileStreamType, filename, fileLocation, 0, 0, details, extendedFileId, initialFrameNumber, timestamp)  //shall I maybe have -1 as fileContentLength???
 {
 }
        internal FileSegmentAssembler(string fileOutputDirectory, NetworkTcpSession networkTcpSession, bool transferIsClientToServer, string filePath, string uniqueFileId, FileTransfer.FileStreamAssemblerList fileStreamAssemblerList, PopularityList <string, PacketParser.FileTransfer.FileSegmentAssembler> parentAssemblerList, FileStreamTypes fileStreamType, string details, string serverHostname)
            : this(fileOutputDirectory, filePath, uniqueFileId, fileStreamAssemblerList, parentAssemblerList, fileStreamType, details, serverHostname)
        {
            //this.fileOutputDirectory = fileOutputDirectory;

            //this.networkTcpSession = networkTcpSession;
            this.fiveTuple = networkTcpSession.Flow.FiveTuple;
            this.transferIsClientToServer = transferIsClientToServer;
        }
        internal bool ContainsAssembler(NetworkHost sourceHost, ushort sourcePort, NetworkHost destinationHost, ushort destinationPort, bool tcpTransfer, bool assemblerIsAcive, FileStreamTypes fileStreamType)
        {
            string id = GetAssemblerId(sourceHost, sourcePort, destinationHost, destinationPort, tcpTransfer);

            return(base.ContainsKey(id) && base[id].FileStreamType == fileStreamType && base[id].IsActive == assemblerIsAcive);
        }
示例#15
0
 public WavFileAssembler(string wavFilename, FileStreamAssemblerList fileStreamAssemblerList, FiveTuple fiveTuple, FileStreamTypes fileStreamType, long initialFrameNumber, DateTime startTime, uint sampleRate = 8000) :
     base(fileStreamAssemblerList, fiveTuple, true, fileStreamType, wavFilename, "/", fileStreamType.ToString() + " " + fiveTuple.ToString(), initialFrameNumber, startTime)
 {
     if (fileStreamType == FileStreamTypes.RTP)
     {
         this.FileContentLength         = -1;
         this.FileSegmentRemainingBytes = -1;
         //this.fileStreamAssemblerList.Add(assembler);
     }
     this.sampleRate = sampleRate;
 }