public void CustomTester_SingleCharacterValue()
        {
            TrafficViewerFile  mockSite           = new TrafficViewerFile();
            MockTestController mockTestController = new MockTestController(mockSite);


            string          testRequest = "GET /search.aspx?txtSearch=a&a1=a HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n";
            string          paramName   = "txtSearch";
            string          paramName2  = "a1";
            CustomTestsFile file        = GetCustomTestFile();
            Tester          tester      = new Tester(mockTestController, file);
            CustomTestDef   def         = file.GetCustomTests()["Path Traversal"];
            HttpRequestInfo original    = new HttpRequestInfo(testRequest, true);
            Uri             uri         = new Uri(original.FullUrl);

            string          entityId       = tester.GetEntityId(uri, paramName);
            string          entityString   = tester.GetEntityString(testRequest, uri, paramName, original.QueryVariables[paramName]);
            TestJob         testJob        = new TestJob(paramName, original.QueryVariables[paramName], RequestLocation.Query, def);
            string          mutatedRequest = tester.GenerateMutatedRequestList(testRequest, testJob, entityString, entityId)[0];
            HttpRequestInfo mutatedReqInfo = new HttpRequestInfo(mutatedRequest, true);

            Assert.IsTrue(mutatedReqInfo.QueryVariables.ContainsKey(paramName), "Could no longer find parameter");
            Assert.AreEqual(original.QueryVariables[paramName] + MockTestController.PATH_TRAVERSAL, mutatedReqInfo.QueryVariables[paramName], "Incorrect test value");
            Assert.AreEqual(original.QueryVariables[paramName2], mutatedReqInfo.QueryVariables[paramName2], "Incorrect non-test value");
        }
        public void CustomTester_TestMultiEncoding()
        {
            TrafficViewerFile mockSite = new TrafficViewerFile();
            string            payload  = "<'\0a";
            CustomTestDef     def      = new CustomTestDef("LT", "LT",
                                                           payload, "", "");
            TestJob         job  = new TestJob("x", "y", RequestLocation.Query, def);
            CustomTestsFile file = GetCustomTestFile();

            file.GenerateAllEncodings = true;
            Tester tester = new Tester(new MockTestController(mockSite), file);

            var list = tester.GeneratePayloadListFromMutation("GET /x=y HTTP/1.1\r\n", job, false, "don't care");

            Assert.IsNotNull(list);
            Assert.AreEqual(7, list.Count);

            Assert.AreEqual(payload, list[0]);
            Assert.AreEqual(Utils.UrlEncode(payload), list[1]);
            Assert.AreEqual(Utils.UrlEncode(Utils.UrlEncode(payload)), list[2]);
            Assert.AreEqual(Utils.UrlEncodeAll(payload), list[3]);
            Assert.AreEqual(Utils.JSONEncode(payload), list[4]);
            Assert.AreEqual(Utils.HtmlEncode(payload), list[5]);
            Assert.AreEqual(Utils.Base64Encode(payload), list[6]);
        }
        public void CustomTester_MatchHeaderValidation()
        {
            TrafficViewerFile  mockSite           = new TrafficViewerFile();
            MockTestController mockTestController = new MockTestController(mockSite);


            string testRequest = "GET /search.aspx?txtSearch=a&a1=a HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n";
            string paramName   = "txtSearch";

            CustomTestsFile file   = GetCustomTestFile();
            Tester          tester = new Tester(mockTestController, file);
            CustomTestDef   def    = file.GetCustomTests()["Path Traversal"];



            def.Validation = "$header=" + "root:\\s?:";

            HttpRequestInfo original = new HttpRequestInfo(testRequest, true);
            Uri             uri      = new Uri(original.FullUrl);

            string  entityId       = tester.GetEntityId(uri, paramName);
            string  entityString   = tester.GetEntityString(testRequest, uri, paramName, original.QueryVariables[paramName]);
            TestJob testJob        = new TestJob(paramName, original.QueryVariables[paramName], RequestLocation.Query, def);
            string  mutatedRequest = tester.GenerateMutatedRequestList(testRequest, testJob, entityString, entityId)[0];

            Assert.IsFalse(tester.ValidateSingleTest(testRequest, "HTTP/1.1 200 OK\r\nbla", new Uri("http://demo.testfire.net/search.aspx"),
                                                     paramName, entityId, def, mutatedRequest, "HTTP/1.1 200 OK\r\n\r\nroot::"));
            Assert.IsTrue(tester.ValidateSingleTest(testRequest, "HTTP/1.1 200 OK\r\nbla", new Uri("http://demo.testfire.net/search.aspx"),
                                                    paramName, entityId, def, mutatedRequest, "HTTP/1.1 200 OK\r\nroot::\r\n\r\nbody"));
        }
示例#4
0
        private TrafficViewerFile removeSimilar(TrafficViewerFile source)
        {
            TrafficViewerFile dest = new TrafficViewerFile();
            TVRequestInfo     info;
            int        id         = -1;
            List <int> _reqHashes = new List <int>();

            while ((info = source.GetNext(ref id)) != null)
            {
                byte[]          request = source.LoadRequestData(info.Id);
                HttpRequestInfo reqInfo = new HttpRequestInfo(request, true);
                int             hash    = reqInfo.GetHashCode(TrafficServerMode.BrowserFriendly);

                if (!_reqHashes.Contains(hash))
                {
                    byte[] response = source.LoadResponseData(info.Id);
                    dest.AddRequestResponse(request, response);
                    _reqHashes.Add(hash);
                }
            }

            //copy profile over
            dest.Profile = source.Profile;
            return(dest);
        }
示例#5
0
        public static TrafficViewerFile GenerateTestTvf()
        {
            TrafficViewerFile tvf  = new TrafficViewerFile();
            TempFile          temp = new TempFile(".tvf");

            temp.Write(Properties.Resources.altoro);
            tvf.Open(temp.Path);
            return(tvf);
        }
示例#6
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);
        }
        private static MockProxy SetupMockProxy(string testRequest, string testResponse, TrafficViewerFile dataStore)
        {
            MockProxy         mockProxy;
            TrafficViewerFile mockSite = new TrafficViewerFile();

            mockSite.AddRequestResponse(testRequest, testResponse);

            mockProxy = new MockProxy(dataStore, mockSite);
            return(mockProxy);
        }
        private static TrafficViewerFile GetCompareTVF(byte[] bytes)
        {
            TempFile compareTemp = new TempFile();

            compareTemp.Write(bytes);
            TrafficViewerFile compareTVF = new TrafficViewerFile();

            compareTVF.Open(compareTemp.Path);
            return(compareTVF);
        }
示例#9
0
        private static void ExportPart(int part, TrafficViewerFile currentPart)
        {
            string exportFileFormat = @"c:\_export\meexport_{0}.exd";
            //export the current part
            ASEExdExporter exporter = new ASEExdExporter();
            string         fName    = String.Format(exportFileFormat, part);
            FileStream     file     = new FileStream(fName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write);

            exporter.Export(currentPart, file);
            file.Close();
        }
示例#10
0
 public void NewTvf()
 {
     if (_trafficViewerFile != null)
     {
         //close the existing file
         _trafficViewerFile.Close(false);
     }
     _trafficViewerFile         = new TrafficViewerFile();
     _trafficViewerFile.Profile = Options.GetDefaultProfile();
     _trafficViewerFile.SaveUnpacked();
 }
示例#11
0
        private TrafficViewer()
        {
            LoadExtensions();

            //initialize traffic file
            _trafficViewerFile = new TrafficViewerFile();

            //ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);


            InitSdkSettings();
        }
示例#12
0
        public void TestHarImport()
        {
            TempFile temp = new TempFile(".har");

            temp.Write(Resources.demohar);
            TrafficViewerFile tvf = new TrafficViewerFile();
            var parser            = new HarParser();

            parser.Parse(temp.Path, tvf, ParsingOptions.GetDefaultProfile());
            Assert.AreEqual(3, tvf.RequestCount);
            tvf.Close(false);
        }
示例#13
0
        public void SaveAndOpen()
        {
            TrafficViewerFile tvf  = MakeDummyTrafficFile();
            TempFile          temp = new TempFile(".tvf");

            tvf.Save(temp.Path);
            tvf.Close(false);
            //verfiy that we can open
            tvf.Open(temp.Path);
            //run all validations
            ValidateASEFile(tvf);
            tvf.Close(false);
        }
示例#14
0
        public void EditTVF()
        {
            TrafficViewerFile tvf = UnitTestUtils.GenerateTestTvf();
            //check delete
            int initialCount = tvf.RequestCount;
            //get the first request id
            int           i      = -1;
            TVRequestInfo first  = tvf.GetNext(ref i);
            TVRequestInfo second = tvf.GetNext(ref i);

            HttpRequestInfo secondRequest = new HttpRequestInfo(tvf.LoadRequestData(second.Id));

            HttpResponseInfo secondResponse = new HttpResponseInfo();

            byte [] respBytes = tvf.LoadResponseData(second.Id);
            secondResponse.ProcessResponse(respBytes);
            int referenceResponseStatus = secondResponse.Status;

            int referenceHash = secondRequest.GetHashCode();

            Assert.IsTrue(tvf.RemoveRequest(first.Id));
            Assert.AreEqual(initialCount - 1, tvf.RequestCount);
            Assert.IsNull(tvf.GetPrevious(ref i));

            RequestDataCache.Instance.Clear();
            //check that

            //check add

            TVRequestInfo reqInfo = new TVRequestInfo();

            reqInfo.RequestLine = "GET /newrequest HTTP/1.1";
            string request  = "GET /newrequest HTTP/1.1\r\nHeader1:1\r\n\r\n";
            string response = "HTTP 200 OK\r\nHeader1:1\r\n\r\n<html><body>Added request</body></html>";

            RequestResponseBytes reqData = new RequestResponseBytes();

            reqData.AddToRequest(Constants.DefaultEncoding.GetBytes(request));
            reqData.AddToResponse(Constants.DefaultEncoding.GetBytes(response));

            tvf.AddRequestInfo(reqInfo);
            tvf.SaveRequest(reqInfo.Id, reqData);
            tvf.SaveResponse(reqInfo.Id, reqData);

            //Check that the request was added
            response = Constants.DefaultEncoding.GetString(tvf.LoadResponseData(reqInfo.Id));

            Assert.AreEqual(38, response.IndexOf("Added request"));
            Assert.AreEqual(65, response.Length);
            //modify the recently added request slightly
        }
示例#15
0
        public void TestBasicAuth()
        {
            TrafficViewerFile tvf = new TrafficViewerFile();

            tvf.AddRequestResponse("GET / HTTP/1.1", Resources.basicauthresponse);

            TrafficStoreProxy proxy = new TrafficStoreProxy(tvf);

            proxy.Start();

            TrafficViewerHttpClient client = new TrafficViewerHttpClient();

            client.SetProxySettings(proxy.Host, proxy.Port, null);
        }
示例#16
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: Har2Exd <HAR file path> <EXD file path>");
                Console.WriteLine("Exit codes: 1 - No args, 2 - Incorrect har path, 3 - Parsing error, 4 - Export error.");
                Environment.ExitCode = 1;
            }
            else
            {
                string harFilePath = args[0];
                string exdFilePath = args[1];
                if (!File.Exists(harFilePath))
                {
                    Console.WriteLine("Could not find har file: '{0}'", harFilePath);
                    Environment.ExitCode = 2;
                }
                else
                {
                    TrafficViewerFile tvf = new TrafficViewerFile();
                    try
                    {
                        Console.WriteLine("Importing from '{0}'...", harFilePath);
                        ITrafficParser harParser = new HarParser();

                        harParser.Parse(harFilePath, tvf, ParsingOptions.GetDefaultProfile());
                    }
                    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.");
                }
            }
        }
示例#17
0
        public void TestRemovingCachedHeaders()
        {
            //setup a mock web server

            TrafficViewerFile serverdataStore = new TrafficViewerFile();

            serverdataStore.Profile.SetExclusions(new string[0] {
            });
            TrafficViewerFile mockSiteData = new TrafficViewerFile();
            string            testRequest  = "GET /a HTTP/1.1\r\nIf-Modified-Since: 10-10-2012\r\nIf-None-Match: 123\r\nProxy-Connection: keep-alive\r\nAccept-Encoding: gzip\r\n\r\n";
            string            testResponse = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n";

            mockSiteData.AddRequestResponse(testRequest, testResponse);
            MockProxy mockServer = new MockProxy(serverdataStore, mockSiteData);

            mockServer.Start();

            //setup a mock proxy

            TrafficViewerFile proxyDataStore = new TrafficViewerFile();

            proxyDataStore.Profile.SetExclusions(new string[1] {
                @".*\.gif"
            });
            ManualExploreProxy meProxy = new ManualExploreProxy("127.0.0.1", 17777, proxyDataStore);

            meProxy.Start();

            IHttpClient httpClient = GetHttpClient(ClientType.TrafficViewerHttpClient, meProxy.Port);             //need to use the traffic viewer client here
            //the webrequestclient does not allow requests to localhost through a proxy on localhost
            HttpRequestInfo testRequestInfo = new HttpRequestInfo(testRequest);

            testRequestInfo.Host = mockServer.Host;
            testRequestInfo.Port = mockServer.Port;


            httpClient.SendRequest(testRequestInfo);


            HttpRequestInfo savedReqInfo = new HttpRequestInfo(serverdataStore.LoadRequestData(0));

            Assert.IsNull(savedReqInfo.Headers["If-Modified-Since"]);
            Assert.IsNull(savedReqInfo.Headers["If-None-Match"]);
            Assert.IsNull(savedReqInfo.Headers["Accept-Encoding"]);
            Assert.IsNull(savedReqInfo.Headers["Proxy-Connection"]);

            meProxy.Stop();
            mockServer.Stop();
        }
示例#18
0
        //[TestMethod]
        public void TestVariableDefinitions()
        {
            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 == "AppScan Login Files (.login)")
                {
                    loginExporter = exporter;
                }
            }

            Assert.IsNotNull(loginExporter);

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

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

            stream.Close();

            //import the exported file
            XmlDocument loginDoc = new XmlDocument();

            loginDoc.XmlResolver = null;

            loginDoc.Load(exportedFile.Path);

            XmlNode varDef = loginDoc.SelectSingleNode("//VariableDefinition[@Name='amSessionId']");

            Assert.IsNotNull(varDef);
            Assert.AreEqual("Cookie", varDef.SelectSingleNode("VariableType").InnerText);
            Assert.AreEqual("True", varDef.SelectSingleNode("SessionIDEnabled").InnerText);
        }
示例#19
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();
        }
示例#20
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);
        }
示例#21
0
        public void Execute(ITrafficDataAccessor curDataAccessor,
                            List <TVRequestInfo> selectedRequests,
                            IHttpClientFactory curHttpClientFactory)
        {
            _trafficFile = curDataAccessor as TrafficViewerFile;
            if (_trafficFile == null)
            {
                Log("Invalid Traffic File Given");
            }

            _selectedRequests  = selectedRequests;
            _httpClientFactory = curHttpClientFactory;

            SetupForm setupForm = new SetupForm(this, TrafficViewerOptions.TrafficViewerAppDataDir, _netSettings);

            setupForm.Show();
        }
示例#22
0
        public void CustomTester_TestScriptingRuleBasedOnComponent()
        {
            TrafficViewerFile mockSite = new TrafficViewerFile();
            CustomTestDef     def      = new CustomTestDef("BlindSQL", "BlindSQL",
                                                           "$js_code=function Callback(rawRequest, entityName, entityValue, requestLocation){if(requestLocation.indexOf('Query') > -1) return encodeURIComponent(\"' or '1'='1\");}", "");
            TestJob         job    = new TestJob("x", "y", RequestLocation.Query, def);
            CustomTestsFile file   = GetCustomTestFile();
            Tester          tester = new Tester(new MockTestController(mockSite), file);

            var list = tester.GeneratePayloadListFromMutation("GET /x=y HTTP/1.1\r\n", job, false, "don't care");

            Assert.IsNotNull(list);
            Assert.AreEqual(1, list.Count);
            string expected = "'%20or%20'1'%3D'1";

            Assert.AreEqual(expected, list[0]);
        }
示例#23
0
        public void Clear()
        {
            TrafficViewerFile tvf  = MakeDummyTrafficFile();
            TempFile          temp = new TempFile(".tvf");

            tvf.Save(temp.Path);
            Assert.AreNotSame(0, tvf.RequestCount);

            tvf.Clear(false);

            Assert.AreEqual(0, tvf.RequestCount);
            int i = -1;

            Assert.IsNull(tvf.GetNext(ref i));

            tvf.Close(false);
        }
示例#24
0
        public void TestExclusions()
        {
            TrafficViewerFile dataStore = new TrafficViewerFile();

            dataStore.Profile.SetExclusions(new string[1] {
                @".*\.gif"
            });

            TrafficViewerFile mockSite           = new TrafficViewerFile();
            string            nonExcludedRequest = "GET http://site.com/a HTTP/1.1\r\n\r\n";
            string            excludedRequest    = "GET http://site.com/image.gif HTTP/1.1\r\n\r\n";
            string            testResponse       = "HTTP/1.1 200 OK";

            mockSite.AddRequestResponse(nonExcludedRequest, testResponse);
            mockSite.AddRequestResponse(excludedRequest, testResponse);

            MockProxy proxy = new MockProxy(dataStore, mockSite);

            proxy.Start();

            IHttpClient httpClient = GetHttpClient(proxy.Port);

            HttpRequestInfo testRequestInfo = new HttpRequestInfo(excludedRequest);

            HttpResponseInfo respInfo = httpClient.SendRequest(testRequestInfo);

            Assert.AreEqual(200, respInfo.Status);
            //verify that nothing was added to the file
            Assert.AreEqual(0, dataStore.RequestCount);

            //verify that when sending a request that is not excluded the request is being added

            testRequestInfo = new HttpRequestInfo(nonExcludedRequest);
            respInfo        = httpClient.SendRequest(testRequestInfo);

            Assert.AreEqual(200, respInfo.Status);
            //verify that the request was added to the file
            Assert.AreEqual(1, dataStore.RequestCount);

            HttpRequestInfo savedReqInfo = new HttpRequestInfo(dataStore.LoadRequestData(0));

            Assert.AreEqual(testRequestInfo.FullUrl, savedReqInfo.FullUrl);

            proxy.Stop();
        }
示例#25
0
        private static void ValidateASEFile(TrafficViewerFile tvFile)
        {
            //after the import we should have 2 requests
            Assert.AreEqual(2, tvFile.RequestCount);
            int           i      = -1;
            TVRequestInfo first  = tvFile.GetNext(ref i);
            TVRequestInfo second = tvFile.GetNext(ref i);

            Assert.AreEqual("GET /index1 HTTP/1.1", first.RequestLine);
            Assert.AreEqual("[1000]", first.ThreadId);
            Assert.AreEqual("Stage::Purpose1", first.Description);

            Assert.AreEqual("POST /index2 HTTP/1.1", second.RequestLine);
            Assert.AreEqual("[2000]", second.ThreadId);
            Assert.AreEqual("Stage::Purpose2", second.Description);

            TimeSpan diff = second.RequestTime.Subtract(first.RequestTime);

            Assert.AreEqual(10, diff.Milliseconds);
            Assert.AreEqual("  0.03s", first.Duration);
            //check the requests
            HttpRequestInfo req1 = new HttpRequestInfo(tvFile.LoadRequestData(first.Id));
            HttpRequestInfo req2 = new HttpRequestInfo(tvFile.LoadRequestData(second.Id));

            Assert.AreEqual("demo.testfire.net", req1.Host);
            Assert.AreEqual("www.altoromutual.com", req2.Host);

            //check the responses
            Assert.AreEqual("200", first.ResponseStatus);
            Assert.AreEqual("302", second.ResponseStatus);

            HttpResponseInfo resp1 = new HttpResponseInfo();
            HttpResponseInfo resp2 = new HttpResponseInfo();

            resp1.ProcessResponse(tvFile.LoadResponseData(first.Id));
            resp2.ProcessResponse(tvFile.LoadResponseData(second.Id));

            string firstBody  = resp1.ResponseBody.ToString();
            string secondBody = resp2.ResponseBody.ToString();

            Assert.IsTrue(firstBody.Contains("interrupt"));
            Assert.IsFalse(firstBody.Contains("--function"));

            Assert.IsTrue(secondBody.Contains("inter\nrupt"));
        }
示例#26
0
        public void CustomTester_TestMultiPayloadsWithTicks()
        {
            TrafficViewerFile mockSite = new TrafficViewerFile();
            CustomTestDef     def      = new CustomTestDef("BlindSQLABC", "Blind SQL",
                                                           @"__dynamic_value__ticks__,__dynamic_value__ticks__,__dynamic_value__ticks__", "");
            TestJob         job           = new TestJob("x", "y", RequestLocation.Query, def);
            CustomTestsFile file          = GetCustomTestFile();
            Tester          tester        = new Tester(new MockTestController(mockSite), file);
            var             entity_string = tester.GetEntityString("GET /x=y HTTP/1.1\r\n", new Uri("http://localhost/x=y"), "x", "y");
            var             entity_id     = tester.GetEntityId(new Uri("http://localhost/x=y"), "x");
            var             list          = tester.GenerateMutatedRequestList("GET /x=y HTTP/1.1\r\n", job, entity_string, entity_id);

            Assert.IsNotNull(list);
            Assert.AreEqual(3, list.Count);

            Assert.AreNotEqual(list[0], list[1]);
            Assert.AreNotEqual(list[1], list[2]);
        }
示例#27
0
        public void CustomTester_TestMultiPayloads()
        {
            TrafficViewerFile mockSite = new TrafficViewerFile();
            CustomTestDef     def      = new CustomTestDef("BlindSQLABC", "Blind SQL",
                                                           @"a\,,b,c", "");
            TestJob         job    = new TestJob("x", "y", RequestLocation.Query, def);
            CustomTestsFile file   = GetCustomTestFile();
            Tester          tester = new Tester(new MockTestController(mockSite), file);

            var list = tester.GeneratePayloadListFromMutation("GET /x=y HTTP/1.1\r\n", job, false, "don't care");

            Assert.IsNotNull(list);
            Assert.AreEqual(3, list.Count);

            Assert.AreEqual("a,", list[0]);
            Assert.AreEqual("b", list[1]);
            Assert.AreEqual("c", list[2]);
        }
示例#28
0
        public void TestManualExploreImportExport()
        {
            //validate against existing TVF
            TrafficViewerFile compareTVF = GetCompareTVF(Resources.demoExploreFromTrafficImport);
            //export the tvf to exd
            ITrafficExporter exporter   = new ManualExploreExporter();
            TempFile         temp       = new TempFile(".exd");
            Stream           tempStream = temp.OpenStream();

            exporter.Export(compareTVF, tempStream);
            tempStream.Close();

            TrafficViewerFile importTVF = new TrafficViewerFile();
            ITrafficParser    parser    = new ConfigurationParser();

            parser.Parse(temp.Path, importTVF, new ParsingOptions());

            ValidateTrafficSourcesRequestsAreSame(compareTVF, importTVF, false);
        }
示例#29
0
        private void StartClick(object sender, EventArgs e)
        {
            if (_fuzzOn)
            {
                return;
            }

            _options.MatchPattern   = _textPattern.Text;
            _options.ReversePattern = _reversePattern.Checked;


            GenerateRequestsToFuzz();


            ErrorBox error = new ErrorBox();

            if (!String.IsNullOrWhiteSpace(_fileSelector.Text))
            {
                _outputFile = new TrafficViewerFile();
                _outputFile.Save(_fileSelector.Text);
                if (!File.Exists(_fileSelector.Text))
                {
                    error.Show("Invalid result file location");
                    return;
                }
                _options.OutputFile = _fileSelector.Text;
            }
            else
            {
                _outputFile = TrafficViewer.Instance.TrafficViewerFile;
                _outputFile.SetState(AccessorState.Tailing);
            }

            if (!int.TryParse(_textNumThreads.Text, out _numThreads))
            {
                error.Show("Invalid number of threads specified");

                return;
            }
            _options.NumberOfThreads = _numThreads;
            _options.Save();
            GenerateAndRunPayloads();
        }
        public void Test_NetworkSettings_ProxyUsesAProxy()
        {
            MockProxy mockProxy;
            string    testRequest  = "GET http://site.com/ HTTP/1.1\r\n\r\n";
            string    testResponse = "HTTP/1.1 200 OK\r\n\r\n";

            TrafficViewerFile dataStore = new TrafficViewerFile();

            mockProxy = SetupMockProxy(testRequest, testResponse, dataStore);


            mockProxy.Start();



            ManualExploreProxy meProxy = new ManualExploreProxy("127.0.0.1", 0, null);             //use a random port

            meProxy.NetworkSettings.WebProxy = new WebProxy(mockProxy.Host, mockProxy.Port);
            meProxy.Start();

            WebRequestClient client          = new WebRequestClient();
            INetworkSettings networkSettings = new DefaultNetworkSettings();

            networkSettings.WebProxy = new WebProxy(meProxy.Host, meProxy.Port);

            client.SetNetworkSettings(networkSettings);

            HttpRequestInfo testReqInfo = new HttpRequestInfo(testRequest);

            Assert.AreEqual(0, dataStore.RequestCount);

            HttpResponseInfo respInfo = client.SendRequest(testReqInfo);


            meProxy.Stop();
            mockProxy.Stop();

            //test that the request goes through the mock proxy by checking the data store

            Assert.AreEqual(200, respInfo.Status);
            Assert.AreEqual(1, dataStore.RequestCount);
        }