Exemple #1
0
        public void ImportASE()
        {
            ITrafficParser parser = new DefaultTrafficParser();

            //test ASE import
            TestImportParser(parser, MakeDummyASETrafficLog(), ParsingOptions.GetDefaultProfile());
        }
Exemple #2
0
        private static TrafficViewerFile MakeDummyTrafficFile()
        {
            TrafficViewerFile tvf    = new TrafficViewerFile();
            TempFile          log    = MakeDummyASETrafficLog();
            ITrafficParser    parser = new DefaultTrafficParser();

            tvf.StartImport(parser, log.Path, ParsingOptions.GetDefaultProfile());
            return(tvf);
        }
Exemple #3
0
        public void ExportAppscanToEXD()
        {
            ParsingOptions options = ParsingOptions.GetLegacyAppScanProfile();

            ITrafficParser parser = new DefaultTrafficParser();

            //test appscan import
            TrafficViewerFile tvFile = new TrafficViewerFile();
            TempFile          log    = new TempFile();

            log.Write(Properties.Resources.AppScanMETraffic);

            tvFile.StartImport(parser, log.Path, options);

            Assert.AreEqual(8, tvFile.RequestCount);

            ITrafficExporter exdExporter = new ManualExploreExporter();

            TempFile temp = new TempFile();

            Stream stream = temp.OpenStream();

            exdExporter.Export(tvFile, stream, "newHost.com", 8080);

            Assert.IsTrue(stream.Length > 0);

            stream.Flush();

            stream.Position = 0;

            XmlDocument doc = new XmlDocument();

            doc.XmlResolver = null;
            doc.Load(stream);

            int noOfRequests = doc.SelectNodes("//request").Count;

            Assert.AreEqual(8, noOfRequests);

            //check that the post request is properly formed
            XmlNode postRequest = doc.SelectSingleNode("//request[@method='POST']");

            Assert.AreEqual(3, postRequest.SelectNodes("parameter").Count);
            Assert.AreEqual(2, postRequest.SelectNodes("cookie").Count);
            Assert.AreEqual(11, postRequest.SelectNodes("header").Count);

            stream.Close();
        }
Exemple #4
0
        public void ImportAppscan()
        {
            ParsingOptions options = ParsingOptions.GetLegacyAppScanProfile();

            ITrafficParser parser = new DefaultTrafficParser();

            //test appscan import
            TrafficViewerFile tvFile = new TrafficViewerFile();
            TempFile          log    = new TempFile();

            log.Write(Properties.Resources.AppScanMETraffic);

            tvFile.StartImport(parser, log.Path, options);

            Assert.AreEqual(8, tvFile.RequestCount);

            string response = Encoding.UTF8.GetString(tvFile.LoadResponseData(3));

            Assert.IsTrue(response.Contains("ONLINE BANKING LOGIN"));
        }
Exemple #5
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: Traffic2Exd <traffic file path> <EXD file path>");
                Console.WriteLine("Supported import formats: .har, .txt, .htd");
                Console.WriteLine("If the EXD file already exists the tool will append to it.");

                Console.WriteLine("Exit codes: 1 - No args, 2 - Incorrect file path, 3 - Parsing error, 4 - Export error, 5 - Unsupported Exception.");
                Environment.ExitCode = 1;
            }
            else
            {
                string trafficFilePath = args[0];
                string exdFilePath     = args[1];
                if (!File.Exists(trafficFilePath))
                {
                    Console.WriteLine("Could not find har file: '{0}'", trafficFilePath);
                    Environment.ExitCode = 2;
                }
                else
                {
                    TrafficViewerFile tvf = new TrafficViewerFile();
                    try
                    {
                        if (File.Exists(exdFilePath))
                        {
                            Console.WriteLine("EXD file {0} already exists. Appending to it.", exdFilePath);
                            ConfigurationParser exdParser = new ConfigurationParser();
                            exdParser.Parse(exdFilePath, tvf, ParsingOptions.GetDefaultProfile());
                        }


                        Console.WriteLine("Importing from '{0}'...", trafficFilePath);
                        ITrafficParser parser = null;


                        if (trafficFilePath.ToLower().EndsWith(".har"))
                        {
                            parser = new HarParser();
                        }
                        else if (trafficFilePath.ToLower().EndsWith(".txt"))
                        {
                            parser = new DefaultTrafficParser();
                        }
                        else if (trafficFilePath.ToLower().EndsWith(".htd"))
                        {
                            TrafficViewerFile tvf2 = new TrafficViewerFile();
                            tvf2.Open(trafficFilePath);
                            int           id   = -1;
                            TVRequestInfo info = null;

                            while ((info = tvf2.GetNext(ref id)) != null)
                            {
                                tvf.AddRequestResponse(tvf2.LoadRequestData(info.Id), tvf2.LoadResponseData(info.Id));
                            }
                        }
                        else
                        {
                            Console.WriteLine("File extension is unsupported. Supported extensions/formats: .har, .txt, .htd");
                            Environment.ExitCode = 5;
                        }

                        if (parser != null)
                        {
                            parser.Parse(trafficFilePath, tvf, ParsingOptions.GetRawProfile());
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Parsing exception: '{0}'", ex.Message);
                        Environment.ExitCode = 3;
                    }
                    //now export

                    try
                    {
                        Console.WriteLine("Exporting to '{0}'...", exdFilePath);
                        var exporter = new ManualExploreExporter();
                        exporter.Export(tvf, new FileStream(exdFilePath, FileMode.Create, FileAccess.ReadWrite));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Export exception: '{0}'", ex.Message);
                        Environment.ExitCode = 4;
                    }
                    tvf.Close(false);
                    Console.WriteLine("Done.");
                }
            }
        }