Allows us to save/load the HTTP URL details to/from XML
Example #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="session"></param>
        /// <param name="fileInfo"></param>
        private void ProcessUrls(Session session, FileInfo fileInfo)
        {
            AlternateDataStreamInfo ads = fileInfo.GetAlternateDataStream("info", FileMode.Open);
            using (TextReader reader = ads.OpenText())
            {
                UrlDetails urlDetails = new UrlDetails();
                urlDetails.SrcIp = session.SrcIpText;
                urlDetails.SrcPort = session.SourcePort;
                urlDetails.DstIp = session.DstIpText;
                urlDetails.DstPort = session.DestinationPort;

                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.StartsWith("LINK: ") == false)
                    {
                        continue;
                    }

                    string url = line.Substring(6);

                    if (urlDetails.Urls.Contains(session.HttpHost + url) == false)
                    {
                        urlDetails.Urls.Add(session.HttpHost + url);
                    }
                }

                if (urlDetails.Urls.Count > 0)
                {
                    string dir = session.SrcIpText + "." + session.SourcePort + "-" + session.DstIpText + "." + session.DestinationPort;
                    if (System.IO.Directory.Exists(System.IO.Path.Combine(this.outputDirectory, dir)) == false)
                    {
                        IO.CreateDirectory(System.IO.Path.Combine(this.outputDirectory, dir));
                    }

                    urlDetails.Save(System.IO.Path.Combine(this.outputDirectory, dir, "Url.Details." + session.Guid + ".xml"));
                }
            }
        }
Example #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dataDirectory"></param>
        /// <param name="outputDirectory"></param>
        public void PostProcess(string dataDirectory, string outputDirectory)
        {
            CsvConfiguration csvConfiguration = new CsvConfiguration();
            csvConfiguration.QuoteAllFields = true;

            using (FileStream fileStream = new FileStream(System.IO.Path.Combine(outputDirectory, "Urls.csv"), FileMode.Append, FileAccess.Write, FileShare.Read))
            using (StreamWriter streamWriter = new StreamWriter(fileStream))
            using (CsvHelper.CsvWriter csvWriter = new CsvHelper.CsvWriter(streamWriter, csvConfiguration))
            {
                foreach (string file in System.IO.Directory.EnumerateFiles(outputDirectory,
                                                                           "*.xml",
                                                                           SearchOption.AllDirectories))
                {
                    string fileName = System.IO.Path.GetFileName(file);
                    if (fileName.StartsWith("Url.Details.") == false)
                    {
                        continue;
                    }

                    UrlDetails urlDetails = new UrlDetails();
                    string ret = urlDetails.Load(file);
                    if (ret.Length == 0)
                    {
                        foreach (string url in urlDetails.Urls)
                        {
                            csvWriter.WriteField(url);
                            csvWriter.WriteField(urlDetails.SrcIp);
                            csvWriter.WriteField(urlDetails.SrcPort);
                            csvWriter.WriteField(urlDetails.DstIp);
                            csvWriter.WriteField(urlDetails.DstPort);
                            csvWriter.NextRecord();
                        }
                    }
                }
            }
        }