Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        protected void PlayClick(object sender, EventArgs e)
        {
            ButtonPlay.Enabled  = false;
            ButtonPause.Enabled = true;
            ButtonStop.Enabled  = true;

            if (Proxy == null)
            {
                Proxy = new TrafficStoreProxy(Source);
            }

            if (!Proxy.IsListening)
            {
                Proxy.Start();
                SetIEProxySettings(String.Format("{0}:{1}", Proxy.Host, Proxy.Port));
            }

            OnPlayClick();
        }
Exemplo n.º 3
0
        //[TestMethod]
        public void TestSendingMultiPartRequest()
        {
            TrafficViewer.Instance.NewTvf();

            TrafficViewer.Instance.TrafficViewerFile.AddRequestResponse(Resources.MultipartRequest, "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n");

            TrafficStoreProxy httpProxy = new TrafficStoreProxy(TrafficViewer.Instance.TrafficViewerFile);

            httpProxy.Start();

            HttpRequestInfo         reqInfo = new HttpRequestInfo(Resources.MultipartRequest);
            TrafficViewerHttpClient client  = new TrafficViewerHttpClient();

            client.SetProxySettings("127.0.0.1", httpProxy.Port, null);


            HttpResponseInfo respInfo = client.SendRequest(reqInfo);

            Assert.AreEqual(200, respInfo.Status);

            TrafficViewer.Instance.CloseTvf(false);
        }
Exemplo n.º 4
0
        public void TestTrafficLogProxy()
        {
            TrafficViewer.Instance.HttpClientFactory = new TrafficViewerHttpClientFactory();

            TrafficViewerFile tvf   = UnitTestUtils.GenerateTestTvf();
            TrafficStoreProxy proxy = new TrafficStoreProxy(tvf);

            proxy.Start();

            HttpClientRequest request = new HttpClientRequest();

            HttpRequestInfo reqInfo = new HttpRequestInfo(Properties.Resources.AltoroLoginPageRequest);

            //change the host and port to the proxy

            reqInfo.Host = proxy.Host;
            reqInfo.Port = proxy.Port;

            //test http
            request.SendRequest(reqInfo, false);

            request.RequestCompleteEvent.WaitOne();

            ValidateResponse(request);

            //test https
            proxy.Stop();
            proxy.Start();

            request.SendRequest(reqInfo, true);

            request.RequestCompleteEvent.WaitOne(2 * 1000);

            ValidateResponse(request);

            proxy.Stop();
        }
        public IHttpProxy MakeProxy(string type)
        {
            HttpServerConsole.Instance.WriteLine(LogMessageType.Information, "Created proxy '{0}'", type);
            string host       = TrafficViewerOptions.Instance.TrafficServerIp;
            int    port       = TrafficViewerOptions.Instance.TrafficServerPort;
            int    securePort = TrafficViewerOptions.Instance.TrafficServerPortSecure;
            ITrafficDataAccessor dataStore = TrafficViewer.Instance.TrafficViewerFile;
            var        exploiter           = new CustomTestsExploiter();
            IHttpProxy result = null;

            if (type.Equals(Resources.CaptureProxy))
            {
                result = new AdvancedExploreProxy(host, port, dataStore);
            }
            else if (type.Equals(Resources.DriveByAttackProxy))
            {
                result = new DriveByAttackProxy(exploiter, dataStore, host, port);
            }
            else if (type.Equals(Resources.SequentialAttackProxy))
            {
                result = new SequentialAttackProxy(exploiter, dataStore, host, port);
            }
            else if (type.Equals(Resources.ReverseProxy))
            {
                result = new ReverseProxy(host, port, securePort, dataStore);
            }
            else if (type.Equals(Resources.TrafficFileProxy))
            {
                result = new TrafficStoreProxy(dataStore, dataStore, host, port, securePort);
            }
            else if (type.Equals(Resources.BinaryReverseProxy))
            {
                result = new BinaryReverseProxy(host, port, securePort, dataStore);
            }
            else if (type.Equals(Resources.TrackingProxy))
            {
                result = new TrackingReverseProxy(host, port, securePort, dataStore);
            }


            if (result != null)
            {
                if (!(result is TrafficStoreProxy))
                {
                    if (TrafficViewerOptions.Instance.UseProxy)
                    {
                        WebProxy proxy = new WebProxy(TrafficViewerOptions.Instance.HttpProxyServer, TrafficViewerOptions.Instance.HttpProxyPort);
                        result.NetworkSettings.WebProxy = proxy;
                    }
                    result.NetworkSettings.CertificateValidationCallback = new RemoteCertificateValidationCallback(SSLValidationCallback.ValidateRemoteCertificate);
                }


                if (result is BaseAttackProxy)
                {
                    result.ExtraOptions[BaseAttackProxy.TEST_FILE_PATH] = Path.Combine(TrafficViewerOptions.TrafficViewerAppDataDir, "CustomTests.xml");
                }

                if (result is ReverseProxy || result is BinaryReverseProxy)
                {
                    result.ExtraOptions[ReverseProxy.FORWARDING_HOST_OPT] = TrafficViewerOptions.Instance.ForwardingHost;
                    result.ExtraOptions[ReverseProxy.FORWARDING_PORT_OPT] = TrafficViewerOptions.Instance.ForwardingPort.ToString();
                }
            }
            return(result);
        }
Exemplo n.º 6
0
        //[TestMethod]
        public void Test_ReverseProxy()
        {
            string testRequest   = "GET / HTTP/1.1\r\n";
            string site1Response = "HTTP/1.1 200 OK\r\n\r\nThis is site1";
            string site2Response = "HTTP/1.1 200 OK\r\n\r\nThis is site2";
            //create two mock sites each on a different port and a http client that send a request to the first but in fact gets redirected to the other
            TrafficViewerFile site1Source = new TrafficViewerFile();

            site1Source.AddRequestResponse(testRequest, site1Response);
            TrafficViewerFile site2Source = new TrafficViewerFile();

            site2Source.AddRequestResponse(testRequest, site2Response);

            TrafficStoreProxy mockSite1 = new TrafficStoreProxy(
                site1Source, null, "127.0.0.1", 0, 0);

            mockSite1.Start();

            TrafficStoreProxy mockSite2 = new TrafficStoreProxy(
                site2Source, null, "127.0.0.1", 0, 0);

            mockSite2.Start();

            HttpRequestInfo reqInfo = new HttpRequestInfo(testRequest);

            //request will be sent to site 1
            reqInfo.Host = mockSite1.Host;
            reqInfo.Port = mockSite1.Port;

            ReverseProxy revProxy = new ReverseProxy("127.0.0.1", 0, 0, null);

            revProxy.ExtraOptions[ReverseProxy.FORWARDING_HOST_OPT] = mockSite2.Host;
            revProxy.ExtraOptions[ReverseProxy.FORWARDING_PORT_OPT] = mockSite2.Port.ToString();
            revProxy.Start();

            //make an http client
            IHttpClient            client   = new WebRequestClient();
            DefaultNetworkSettings settings = new DefaultNetworkSettings();

            settings.WebProxy = new WebProxy(revProxy.Host, revProxy.Port);

            client.SetNetworkSettings(settings);

            //send the request Http and verify the target site received it

            HttpResponseInfo respInfo = client.SendRequest(reqInfo);
            string           respBody = respInfo.ResponseBody.ToString();


            Assert.IsTrue(respBody.Contains("This is site2"));

            //check over ssl

            reqInfo.IsSecure = true;
            respInfo         = client.SendRequest(reqInfo);
            respBody         = respInfo.ResponseBody.ToString();
            Assert.IsTrue(respBody.Contains("This is site2"));

            mockSite1.Stop();
            mockSite2.Stop();
            revProxy.Stop();
        }