Exemple #1
0
        public void EditARequest()
        {
            string originalRequest  = "GET / HTTP/1.1";
            string originalResponse = "HTTP/1.1 200 OK";

            TrafficViewerFile file = new TrafficViewerFile();
            int reqId = file.AddRequestResponse(originalRequest, originalResponse);

            Assert.AreEqual(1, file.RequestCount);
            TVRequestInfo reqInfo = file.GetRequestInfo(reqId);

            string newRequest  = "POST /login HTTP/1.1";
            string newResponse = "HTTP/1.1 302 Redirect";

            file.SaveRequest(reqId, Encoding.UTF8.GetBytes(newRequest));
            file.SaveResponse(reqId, Encoding.UTF8.GetBytes(newResponse));

            //check the response info was updated
            Assert.AreEqual(newRequest, reqInfo.RequestLine);
            Assert.AreEqual("302", reqInfo.ResponseStatus);
            Assert.AreEqual(newRequest.Length, reqInfo.RequestLength);
            Assert.AreEqual(newResponse.Length, reqInfo.ResponseLength);

            string loadedRequest = Encoding.UTF8.GetString(file.LoadRequestData(reqId));

            Assert.AreEqual(newRequest, loadedRequest);
            string loadedResponse = Encoding.UTF8.GetString(file.LoadResponseData(reqId));

            Assert.AreEqual(newResponse, loadedResponse);
            file.Close(false);
        }
Exemple #2
0
        public void RemoveARangeOfRequests()
        {
            string originalRequest  = "GET / HTTP/1.1";
            string originalResponse = "HTTP/1.1 200 OK";

            List <int> addedRequests = new List <int>();

            TrafficViewerFile file = new TrafficViewerFile();

            addedRequests.Add(file.AddRequestResponse(originalRequest, originalResponse));
            addedRequests.Add(file.AddRequestResponse(originalRequest, originalResponse));

            //add one more
            int savedRequestId = file.AddRequestResponse(originalRequest, originalResponse);

            addedRequests.Add(file.AddRequestResponse(originalRequest, originalResponse));
            addedRequests.Add(file.AddRequestResponse(originalRequest, originalResponse));

            Assert.AreEqual(5, file.RequestCount);

            file.RemoveRequestBatch(addedRequests);


            Assert.AreEqual(1, file.RequestCount);

            Assert.IsNotNull(file.GetRequestInfo(savedRequestId));

            file.Close(false);
        }
Exemple #3
0
        //[TestMethod]
        public void TestLoginExportType()
        {
            TempFile temp = new TempFile();

            temp.Write(Resources.AltoroLogin);

            TrafficViewerFile origFile = new TrafficViewerFile();

            origFile.Open(temp.Path);

            Assert.AreEqual(4, origFile.RequestCount);

            //export

            IList <ITrafficExporter> exporters = TrafficViewer.Instance.TrafficExporters;

            ITrafficExporter loginExporter = null;

            foreach (ITrafficExporter exporter in exporters)
            {
                if (exporter.Caption == "ASE Login Files (.login)")
                {
                    loginExporter = exporter;
                }
            }

            Assert.IsNotNull(loginExporter);

            TempFile exportedFile = new TempFile("exporttest.login");
            Stream   stream       = exportedFile.OpenStream();

            loginExporter.Export(origFile, stream, "demo.testfire.net", 80);

            stream.Close();

            //import the exported file

            TrafficViewerFile import = new TrafficViewerFile();

            ITrafficParser configurationParser = TrafficViewer.Instance.GetParser("Configuration Parser");

            Assert.IsNotNull(configurationParser);

            configurationParser.Parse(exportedFile.Path, import, ParsingOptions.GetLegacyAppScanProfile());


            Assert.AreEqual(origFile.RequestCount, import.RequestCount);

            int           i = -1;
            TVRequestInfo origInfo;

            while ((origInfo = origFile.GetNext(ref i)) != null)
            {
                TVRequestInfo importInfo      = import.GetRequestInfo(origInfo.Id);
                string        origRequest     = Constants.DefaultEncoding.GetString(origFile.LoadRequestData(origInfo.Id));
                string        importedRequest = Constants.DefaultEncoding.GetString(import.LoadRequestData(origInfo.Id));

                Assert.AreEqual(origRequest, importedRequest);
            }
        }
Exemple #4
0
        public void TestEncryptedRequest()
        {
            TrafficViewerFile file      = new TrafficViewerFile();
            string            request1  = "GET /unencrypted HTTP/1.1";
            string            request2  = "GET /encrypted\r\n\r\nsecret=123456789 HTTP/1.1";
            string            response1 = "HTTP 200 OK\r\n\r\nUnencrypted Response";
            string            response2 = "HTTP 200 OK\r\n\r\nEncrypted Response (secret 1234567789)";

            file.AddRequestResponse(request1, response1);
            file.AddRequestResponse(request2, response2);

            var reqInfo = file.GetRequestInfo(1);

            Assert.IsFalse(reqInfo.IsEncrypted, "Default should be unencrypted");
            reqInfo.IsEncrypted = true;
            //resave the request
            file.SaveRequestResponse(1, request2, response2);
            TempFile tempFile = new TempFile();

            file.EnableDefrag = true; //defrag the raw file
            file.Save(tempFile.Path);

            file = new TrafficViewerFile();

            file.Open(tempFile.Path);


            Assert.IsFalse(file.GetRequestInfo(0).IsEncrypted, "First request should not be encrypted");
            Assert.IsTrue(file.GetRequestInfo(1).IsEncrypted, "Second request should be encrypted");


            string testRequest = Constants.DefaultEncoding.GetString(file.LoadRequestData(1));

            Assert.AreEqual(request2, testRequest);

            string testResponse = Constants.DefaultEncoding.GetString(file.LoadResponseData(1));

            Assert.AreEqual(response2, testResponse);
            file.Close(false);
            File.Delete(tempFile.Path);
        }
Exemple #5
0
        public void SaveAndOpen()
        {
            string expectedRequest  = "GET / HTTP/1.1";
            string expectedResponse = "HTTP/1.1 200 OK";

            TrafficViewerFile file = new TrafficViewerFile();
            int reqId = file.AddRequestResponse(expectedRequest, expectedResponse);

            file.GetRequestInfo(reqId).IsHttps = true;

            Assert.AreEqual(1, file.RequestCount);

            TempFile temp = new TempFile(".tvf");

            file.Save(temp.Path);
            //verify that the file can be saved
            Assert.IsTrue(File.Exists(temp.Path), "Cannot save the file");

            file.Close(false);

            //make a new file and verify we can open
            TrafficViewerFile file2 = new TrafficViewerFile();

            file2.Open(temp.Path);
            //verify actual file was open
            Assert.AreEqual(1, file2.RequestCount, "Incorrect request count after opening saved file");
            //verify request data is correct
            int           requestId = -1;
            TVRequestInfo info      = file2.GetNext(ref requestId);

            Assert.IsNotNull(info, "Cannot obtain request info");

            //veryfy transport info
            Assert.IsTrue(info.IsHttps);

            //verify request data
            string loadedRequest = Encoding.UTF8.GetString(file2.LoadRequestData(info.Id));

            Assert.AreEqual(expectedRequest, loadedRequest);

            string loadedResponse = Encoding.UTF8.GetString(file2.LoadResponseData(info.Id));

            Assert.AreEqual(expectedResponse, loadedResponse);


            file2.Close(false);
        }
Exemple #6
0
        public void RemoveARequest()
        {
            string originalRequest  = "GET / HTTP/1.1";
            string originalResponse = "HTTP/1.1 200 OK";

            TrafficViewerFile file = new TrafficViewerFile();
            int reqId = file.AddRequestResponse(originalRequest, originalResponse);

            //add one more
            file.AddRequestResponse(originalRequest, originalResponse);

            Assert.AreEqual(2, file.RequestCount);

            file.RemoveRequest(reqId);

            Assert.AreEqual(1, file.RequestCount);

            Assert.IsNull(file.GetRequestInfo(reqId));

            file.Close(false);
        }
Exemple #7
0
        static void Main(string[] args)
        {
            TrafficViewerFile file = new TrafficViewerFile();

            file.Profile.SetExclusions((IEnumerable <string>) new string[2]
            {
                "\\.(js|axd|zip|Z|tar|t?gz|sit|cab|pdf|ps|doc|ppt|xls|rtf|dot|mp(p|t|d|e|a|3|4|ga)|m4p|mdb|csv|pp(s|a)|xl(w|a)|dbf|slk|prn|dif|avi|mpe?g|mov(ie)?|qt|moov|rmi?|as(f|x)|m1v|wm(v|f|a)|wav|ra|au|aiff|midi?|m3u|gif|jpe?g|bmp|png|tif?f|ico|pcx|css|xml|dll)\\b",
                ConvertorProperties.ExcludedDomainsFromRecordingPattern
            });


            try
            {
                // Create an instance of StreamReader to read from a file.
                // The using statement also closes the StreamReader.
                using (StreamReader sr = new StreamReader(args[0]))
                {
                    String line;
                    // Read and display lines from the file until the end of
                    // the file is reached.
                    while ((line = sr.ReadLine()) != null)
                    {
                        Har har             = JsonConvert.DeserializeObject <Har>(line);
                        int requestHeaderId = 0;
                        int counter         = 0;
                        foreach (Entry tempEntry in har.log.entries)
                        {
                            if (HtdConvertorUtil.isRelevantRequest(tempEntry))
                            {
                                counter++;
                                requestHeaderId = file.AddRequestResponse(tempEntry.request.ToString(), tempEntry.response.ToString());

                                if (tempEntry.request.postData != null)
                                {
                                    Console.WriteLine(tempEntry.request.postData.ToString());
                                }

                                file.GetRequestInfo(requestHeaderId).Description = "AppScan Proxy Request to Server";

                                if (tempEntry.request.isHttps)
                                {
                                    file.GetRequestInfo(requestHeaderId).IsHttps = true;
                                }
                            }
                        }
                        Console.WriteLine(counter);
                    }
                }


                file.Save(args[1]);
                file.Close(false);
                Console.WriteLine("Recording has been done");
                //Console.ReadLine();
            }
            catch (Exception e)
            {
                // Let the user know what went wrong.
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
        }