コード例 #1
0
        /// <summary>
        /// Browser DOM access test implementation.
        /// </summary>
        /// <param name="browserType">The type of the browser being tested.</param>
        private void BrowserFindElementImplementation(BrowserType browserType)
        {
            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();

            var browserInstances = new Dictionary <BrowserType, int> {
                { browserType, 1 }
            };

            using (var manager = new BrowserManager(browserInstances))
            {
                var browser = manager.AcquireBrowser(browserType);
                browser.NavigateTo($"{Constants.VulnerabilitiesAddress}SimplePageWithForm.html");
                browser.WaitForPageLoad(10);
                var element = browser.FindWebElement(By.Id("textInputId"));
                element.ShouldNotBeNull();
                element.TagName.Equals("input").ShouldBeTrue();
                element.SendKeys("Hello");
                System.Threading.Thread.Sleep(1000);
                element.SendKeys(" world");
                element.GetAttribute("value").Equals("Hello world").ShouldBeTrue();

                element = browser.FindWebElement(By.Name("textInputName"));
                element.GetAttribute("value").Equals("Hello world").ShouldBeTrue();
            }
        }
コード例 #2
0
        /// <summary>
        /// Browser handles missing page implementation.
        /// </summary>
        /// <param name="browserType">
        /// Browser type.
        /// </param>
        private void BrowserHandlesMissingPageImplementation(BrowserType browserType)
        {
            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();

            var browserInstances = new Dictionary <BrowserType, int> {
                { browserType, 1 }
            };

            const int MaxWait = 10;

            using (var manager = new BrowserManager(browserInstances))
            {
                var browser   = manager.AcquireBrowser(browserType);
                var stopWatch = new Stopwatch();
                stopWatch.Start();

                // make the request, wait for up to 10 seconds.
                browser.NavigateTo(
                    "http://ieonline.microsoft.com/pinnedconfig?action=1&CurrentPage=1&itemId=1&nextQuestionId=1&nextQuestionUserId=1");
                browser.WaitForPageLoad(MaxWait);

                stopWatch.Stop();

                // expect a browser specific 404 message
                browser.PageSource.ShouldContain("Page not found");

                stopWatch.ElapsedMilliseconds.ShouldBeLessThan((MaxWait * 1000) + 1500);
            }
        }
コード例 #3
0
        /// <summary>
        /// Browser waits for XML document implementation.
        /// </summary>
        /// <param name="browserType">
        /// Browser type.
        /// </param>
        private void BrowserWaitsForXmlDocumentImplementation(BrowserType browserType)
        {
            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();

            var browserInstances = new Dictionary <BrowserType, int> {
                { browserType, 1 }
            };

            const int MaxWait = 10;

            using (var manager = new BrowserManager(browserInstances))
            {
                var browser   = manager.AcquireBrowser(browserType);
                var stopWatch = new Stopwatch();
                stopWatch.Start();

                // make the request, wait for up to 10 seconds.
                browser.NavigateTo($"{Constants.VulnerabilitiesAddress}XmlResponse.aspx");
                browser.WaitForPageLoad(MaxWait);

                stopWatch.Stop();

                // FF and Chrome will return the XML content, IE returns the XML with styles applied.
                browser.PageSource.ShouldContain("content");

                stopWatch.ElapsedMilliseconds.ShouldBeLessThan((MaxWait + 1) * 1000);
            }
        }
コード例 #4
0
        /// <summary>
        /// Browser proxy injects mandatory headers implementation.
        /// </summary>
        /// <param name="browserType">
        /// Browser type.
        /// </param>
        private void BrowserProxyInjectsMandatoryHeadersImplementation(BrowserType browserType)
        {
            /*
             * WARNING: Terminating this test while the proxy is running can lead to adverse side effects
             *          such as loss of web connectivity. Please allow the call to FiddlerProxy.Cleanup
             *          to complete.
             */

            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();

            var browserInstances = new Dictionary <BrowserType, int> {
                { browserType, 1 }
            };

            try
            {
                FiddlerProxy.Initialize(new[] { "TestKey:TestValue" }, Constants.FiddlerPort);

                using (var manager = new BrowserManager(browserInstances))
                {
                    var browser = manager.AcquireBrowser(browserType);

                    browser.NavigateTo($"{Constants.VulnerabilitiesAddress}dumpheaders.aspx");
                    browser.WaitForPageLoad(10);

                    // Then the expected request header should be present in the page
                    browser.PageSource.ShouldContain("TestKey : TestValue");
                }

                // turn off the proxy and make sure the header is not injected
                FiddlerProxy.Initialize(new string[0], 0);

                using (var manager = new BrowserManager(browserInstances))
                {
                    var browser = manager.AcquireBrowser(browserType);

                    browser.NavigateTo($"{Constants.VulnerabilitiesAddress}dumpheaders.aspx");
                    browser.WaitForPageLoad(10);

                    // Then the expected request header should be present in the page
                    browser.PageSource.ShouldNotContain("TestKey : TestValue");
                }
            }
            finally
            {
                FiddlerProxy.Cleanup(Constants.FiddlerPort);
                FiddlerProxy.Cleanup(0);
            }
        }
コード例 #5
0
        public void BrowserReportsTheCorrectProcessIdentifiersChrome()
        {
            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();
            using (var manager = new BrowserManager(this.chromeOnly))
            {
                var browser = manager.AcquireBrowser(BrowserType.Chrome);

                var browserProcesses =
                    Process.GetProcessesByName("chrome").Select(p => p.Id);
                var driverprocess =
                    Process.GetProcessesByName("chromedriver").First();

                // Chrome opens separate processes for the rendering engine, plugins and each tab.
                browserProcesses.ShouldContain(browser.ProcessId);
                browser.ParentProcessId.ShouldEqual(driverprocess.Id);
            }
        }
コード例 #6
0
        public void TestFiddlerProxySessionFingerprint()
        {
            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();
            const BrowserType BrowserType = BrowserType.Chrome;

            var browserInstances = new Dictionary <BrowserType, int> {
                { BrowserType, 1 }
            };

            try
            {
                FiddlerProxy.Initialize(new string[0], Constants.FiddlerPort);
                using (var manager = new BrowserManager(browserInstances))
                {
                    var browser = manager.AcquireBrowser(BrowserType);

                    // expected headers for this browser process
                    FiddlerProxy.RegisterInstanceHeaders(
                        browser.ProcessId,
                        "My User Agent 1.0",
                        "TestKey: Process" + browser.ProcessId);

                    browser.NavigateTo($"{Constants.VulnerabilitiesAddress}dumpheaders.aspx");
                    browser.WaitForPageLoad(10);

                    // Then the expected request header should be present in the page
                    browser.PageSource.ShouldContain("User-Agent : My User Agent 1.0");
                    browser.PageSource.ShouldContain("TestKey : Process" + browser.ProcessId);

                    var fiddlerResponseSessionKey = Library.Constants.FiddlerResponseSessionKey.FormatIc(
                        browser.ProcessId,
                        browser.Url);

                    // validate the proxy session fingerprint
                    var fiddlerSession = FiddlerProxy.ResponseSession[fiddlerResponseSessionKey];
                    fiddlerSession.bHasResponse.ShouldBeTrue();
                    fiddlerSession.ResponseBody.Length.ShouldBeGreaterThan(0);
                    fiddlerSession.oResponse.headers.Count().ShouldBeGreaterThan(0);
                }
            }
            finally
            {
                FiddlerProxy.Cleanup(Constants.FiddlerPort);
            }
        }
コード例 #7
0
        /// <summary>
        /// Fiddler reporting the wrong
        /// browser process Id when more than one instance of Chrome was present. Here we test explicitly
        /// for that circumstance across all browsers.
        /// </summary>
        /// <param name="browserType">
        /// Browser type.
        /// </param>
        private void BrowserProxyInjectsPerRequestHeadersMultipleImplementation(
            BrowserType browserType)
        {
            /*
             * WARNING: Terminating this test while the proxy is running can lead to adverse side effects
             *          such as loss of web connectivity. Please allow the call to FiddlerProxy.Cleanup
             *          to complete.
             */

            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();

            var browserInstances = new Dictionary <BrowserType, int> {
                { browserType, 3 }
            };

            try
            {
                FiddlerProxy.Initialize(new string[0], Constants.FiddlerPort);
                using (var manager = new BrowserManager(browserInstances))
                {
                    for (int i = 0; i < 3; i++)
                    {
                        var browser = manager.AcquireBrowser(browserType);

                        // expected headers for this browser process
                        FiddlerProxy.RegisterInstanceHeaders(
                            browser.ProcessId,
                            "My User Agent 1.0",
                            "TestKey: Process" + browser.ProcessId);

                        browser.NavigateTo($"{Constants.VulnerabilitiesAddress}dumpheaders.aspx");
                        browser.WaitForPageLoad(10);

                        // Then the expected request header should be present in the page
                        browser.PageSource.ShouldContain("User-Agent : My User Agent 1.0");
                        browser.PageSource.ShouldContain("TestKey : Process" + browser.ProcessId);
                    }
                }
            }
            finally
            {
                FiddlerProxy.Cleanup(Constants.FiddlerPort);
            }
        }
コード例 #8
0
        /// <summary>
        /// Browser can add and remove cookies implementation.
        /// </summary>
        private void BrowserCanAddAndRemoveCookiesImplementation()
        {
            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();

            var browserInstances = new Dictionary <BrowserType, int> {
                { BrowserType.Chrome, 1 }
            };
            var expiry = DateTime.Now.AddDays(1);

            using (var manager = new BrowserManager(browserInstances))
            {
                var browser = manager.AcquireBrowser(BrowserType.Chrome);

                // a new browser should have no cookies
                browser.AllCookies.Count.ShouldEqual(0);

                // adding a cookie without first loading the page should have no effect
                browser.AddCookie("TEST", "Hello", ".bing.com", "/", expiry);
                browser.AllCookies.Count.ShouldEqual(0);

                // navigating to a page should return some cookies
                // NOTE - this uses bing.com since adding cookies to localhost is problematic.
                browser.NavigateTo("http://bing.com");
                browser.WaitForPageLoad(2000);
                browser.AllCookies.Count.ShouldBeGreaterThan(0);

                // we should be able to add and retrieve a new cookie
                browser.AddCookie("TEST", "Hello", ".bing.com", "/", expiry);
                var cookies = browser.AllCookies;
                var cookie  = cookies["TEST"];
                cookie.ShouldNotBeNull();
                cookie.Value.ShouldEqual("Hello");
                cookie.Path.ShouldEqual("/");
                cookie.Domain.ShouldEqual(".bing.com");

                // we should be able to remove all cookies
                browser.DeleteAllCookies();
                browser.AllCookies.Count.ShouldEqual(0);
            }
        }
コード例 #9
0
        /// <summary>
        /// The browser_does_not_wait_for_ajax_requests_to_complete_ implementation.
        /// </summary>
        /// <param name="browserType">
        /// The browser type.
        /// </param>
        private void BrowserDoesNotWaitForAjaxRequestsToCompleteImplementation(BrowserType browserType)
        {
            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();

            var browserInstances = new Dictionary <BrowserType, int> {
                { browserType, 1 }
            };

            // the request will take 5 seconds to complete
            const int Delay = 5;

            using (var manager = new BrowserManager(browserInstances))
            {
                var browser = manager.AcquireBrowser(browserType);

                // make the request, wait for up to 3 seconds.
                browser.NavigateTo($"{Constants.VulnerabilitiesAddress}delayajax.html?a=" + Delay);
                browser.WaitForPageLoad(3);

                // Then the AJAX response should not be present in the page
                browser.PageSource.ShouldNotContain("Done!");
            }
        }
コード例 #10
0
        /// <summary>
        /// The browser_waits_for_a_page_with_a_slow_load_time_ implementation.
        /// </summary>
        /// <param name="browserType">
        /// The browser type.
        /// </param>
        private void BrowserWaitsForAPageWithASlowLoadTimeImplementation(BrowserType browserType)
        {
            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();

            var browserInstances = new Dictionary <BrowserType, int> {
                { browserType, 1 }
            };

            // the request will take 5 seconds to complete
            const int Delay = 5;

            using (var manager = new BrowserManager(browserInstances))
            {
                var browser = manager.AcquireBrowser(browserType);

                // make the request, wait for up to 10 seconds.
                browser.NavigateTo($"{Constants.VulnerabilitiesAddress}delay.html?a=" + Delay);
                browser.WaitForPageLoad(Constants.BrowserWaitForPageLoadInMilliseconds);

                // Then the page complete response should be present in the page
                browser.PageSource.ShouldContain("Done!");
            }
        }
コード例 #11
0
        /// <summary>
        /// Browser does not download files implementation.
        /// </summary>
        private void BrowserDoesNotDownloadFilesImplementation()
        {
            ObjectResolver.RegisterType <IProcessManager, ProcessManager>();

            var browserInstances = new Dictionary <BrowserType, int> {
                { BrowserType.Chrome, 1 }
            };

            using (var manager = new BrowserManager(browserInstances))
            {
                const int MaxWait = 10;
                var       browser = manager.AcquireBrowser(BrowserType.Chrome);

                var stopWatch = new Stopwatch();
                stopWatch.Start();

                browser.NavigateTo($"{Constants.VulnerabilitiesAddress}file.js");
                browser.WaitForPageLoad(MaxWait);

                stopWatch.Stop();

                stopWatch.ElapsedMilliseconds.ShouldBeLessThan((MaxWait + 1) * 1000);
            }
        }