Beispiel #1
0
        /// <summary>
        /// Start server
        /// </summary>
        public void Start()
        {
            _proxyServer.BeforeRequest             += OnRequest;
            _proxyServer.BeforeResponse            += OnResponse;
            _proxyServer.GetCustomUpStreamProxyFunc = GetCustomUpStreamProxy;

            // adding endpoints
            _thisEndPoint = new IPEndPoint(!string.IsNullOrEmpty(_proxyConfig.LocalAddress) ? IPAddress.Parse(_proxyConfig.LocalAddress) : Utils.LocalMachineIpAddress, _proxyConfig.LocalPort);
            _proxyServer.AddEndPoint(new ExplicitProxyEndPoint(_thisEndPoint.Address, _thisEndPoint.Port, true));

            // starting the server
            _proxyServer.Start();

            Logger.Log(ProxyType.HttpProxy, _thisEndPoint, _thisEndPoint, "Starting proxy server...");

            // registering external proxies
            foreach (var externalProxyRule in _proxyConfig.ExternalProxyRules)
            {
                var newProxy = new ExternalProxy {
                    HostName = externalProxyRule.ProxyHost,
                    Port     = externalProxyRule.ProxyPort
                };
                if (!string.IsNullOrEmpty(externalProxyRule.ProxyUsername))
                {
                    newProxy.UserName = externalProxyRule.ProxyUsername;
                    newProxy.Password = externalProxyRule.ProxyPassword;
                }

                if (!_externalProxies.ContainsKey(externalProxyRule.ProxyHost + ":" + externalProxyRule.ProxyPort))
                {
                    _externalProxies.Add(externalProxyRule.ProxyHost + ":" + externalProxyRule.ProxyPort, newProxy);
                }
            }
        }
Beispiel #2
0
        public void start()
        {
            //Set up & start Titanium proxy
            proxyServer = new ProxyServer();
            proxyServer.TrustRootCertificate = true;

            proxyServer.BeforeRequest  += OnRequest;
            proxyServer.BeforeResponse += OnResponse;

            var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8888, true);

            proxyServer.AddEndPoint(explicitEndPoint);
            proxyServer.Start();

            //Set proxy for Web Driver
            TOptions options = new TOptions();
            Proxy    proxy   = new Proxy();

            proxy.Kind      = ProxyKind.Manual;
            proxy.HttpProxy = "localhost:8888";
            options.Proxy   = proxy;

            driver = (TWebDriver)Activator.CreateInstance(typeof(TWebDriver), options);

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
        }
        /// <summary>
        /// 通信の受信を開始します。
        /// </summary>
        /// <param name="portID">受信に使用するポート番号。</param>
        /// <param name="UIControl">GUI スレッドで実行するためのオブジェクト。中身は何でもいい</param>
        /// <returns>実際に使用されるポート番号。</returns>
        public int Start(int portID, Control UIControl)
        {
            Utility.Configuration.ConfigurationData.ConfigConnection c = Utility.Configuration.Config.Connection;


            this.UIControl = UIControl;

            try {
                //if ( c.UseUpstreamProxy )
                //	HttpProxy.UpstreamProxyConfig = new ProxyConfig( ProxyConfigType.SpecificProxy, c.UpstreamProxyAddress, c.UpstreamProxyPort );
                //else if ( c.UseSystemProxy )
                //	HttpProxy.UpstreamProxyConfig = new ProxyConfig( ProxyConfigType.SystemProxy );
                //else
                //	HttpProxy.UpstreamProxyConfig = new ProxyConfig( ProxyConfigType.DirectAccess );

                //HttpProxy.Startup( portID, false, false );
                var endPoint = new ExplicitProxyEndPoint(System.Net.IPAddress.Any, portID, false);
                ProxyPort = portID;
                ProxyServer.AddEndPoint(endPoint);
                ProxyServer.Start();

                ProxyStarted();
                Utility.Logger.Add(2, string.Format(LoggerRes.APIObserverStarted, portID));
            } catch (Exception ex) {
                Utility.Logger.Add(3, LoggerRes.APIObserverFailed + ex.Message);
                ProxyPort = 0;
            }


            return(ProxyPort);
        }
Beispiel #4
0
        public MainWindow()
        {
            proxyServer = new ProxyServer();
            //proxyServer.CertificateEngine = CertificateEngine.BouncyCastle;
            proxyServer.TrustRootCertificate = true;
            proxyServer.CertificateManager.TrustRootCertificateAsAdministrator();
            proxyServer.ForwardToUpstreamGateway = true;

            var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true)
            {
                //IncludedHttpsHostNameRegex = new string[0],
            };

            proxyServer.AddEndPoint(explicitEndPoint);
            //proxyServer.UpStreamHttpProxy = new ExternalProxy
            //{
            //    HostName = "158.69.115.45",
            //    Port = 3128,
            //    UserName = "******",
            //    Password = "******",
            //};

            proxyServer.BeforeRequest                += ProxyServer_BeforeRequest;
            proxyServer.BeforeResponse               += ProxyServer_BeforeResponse;
            proxyServer.TunnelConnectRequest         += ProxyServer_TunnelConnectRequest;
            proxyServer.TunnelConnectResponse        += ProxyServer_TunnelConnectResponse;
            proxyServer.ClientConnectionCountChanged += delegate { Dispatcher.Invoke(() => { ClientConnectionCount = proxyServer.ClientConnectionCount; }); };
            proxyServer.ServerConnectionCountChanged += delegate { Dispatcher.Invoke(() => { ServerConnectionCount = proxyServer.ServerConnectionCount; }); };
            proxyServer.Start();

            proxyServer.SetAsSystemProxy(explicitEndPoint, ProxyProtocolType.AllHttp);

            InitializeComponent();
        }
Beispiel #5
0
        GivenOneEndpointIsAlreadyAddedToAddress_WhenAddingNewEndpointToExistingAddress_ThenTwoEndpointsExists()
        {
            // Arrange
            var       proxy           = new ProxyServer();
            const int port            = 9999;
            var       firstIpAddress  = IPAddress.Parse("127.0.0.1");
            var       secondIpAddress = IPAddress.Parse("192.168.1.1");

            proxy.AddEndPoint(new ExplicitProxyEndPoint(firstIpAddress, port, false));

            // Act
            proxy.AddEndPoint(new ExplicitProxyEndPoint(secondIpAddress, port, false));

            // Assert
            Assert.AreEqual(2, proxy.ProxyEndPoints.Count);
        }
        public TitaniumEngine()
        {
            cmdModel = new CommandModel();

            myProxy = new ProxyServer(true, false, false);

            myProxy.CertificateManager.CreateRootCertificate(true);

            myProxy.BeforeRequest  += MyProxy_BeforeRequest;
            myProxy.BeforeResponse += MyProxy_BeforeResponse;
            var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true)
            {
                //      GenericCertificate = new X509Certificate2(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Certs", "root.pfx"), "Kennwort1!")
            };

            var certificate = explicitEndPoint.GenericCertificate;



            explicitEndPoint.BeforeTunnelConnectRequest += OnBeforeTunnelConnect;

            myProxy.AddEndPoint(explicitEndPoint);

            WriteCertificate();
        }
Beispiel #7
0
        void StartProxy()
        {
            this.Visible = false;
            this.Hide();
            this.notifyIcon1.Visible = true;
            this.notifyIcon1.ShowBalloonTip(10000, "아즈레아 산소호흡기", "종료하시려면 더블클릭하세요.", ToolTipIcon.Info);

            var sr = new ProxyServer();

            sr.TrustRootCertificate = true;
            sr.BeforeRequest       += OnRequest;
            sr.ServerCertificateValidationCallback += (s, e) => { e.IsValid = true; return(Task.FromResult(0)); };
            sr.ClientCertificateSelectionCallback  += (s, e) => Task.FromResult(0);

            var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Loopback, 8080, true);

            sr.AddEndPoint(explicitEndPoint);

#if DEBUG
            sr.UpStreamHttpProxy = sr.UpStreamHttpsProxy = new ExternalProxy {
                HostName = "localhost", Port = 8888
            };
#endif
            sr.Start();
        }
Beispiel #8
0
        public TestProxyServer(bool isReverseProxy, ProxyServer upStreamProxy = null)
        {
            ProxyServer = new ProxyServer();
            var explicitEndPoint = isReverseProxy ?
                                   (ProxyEndPoint) new TransparentProxyEndPoint(IPAddress.Any, 0, true) :
                                   new ExplicitProxyEndPoint(IPAddress.Any, 0, true);

            ProxyServer.AddEndPoint(explicitEndPoint);

            if (upStreamProxy != null)
            {
                ProxyServer.UpStreamHttpProxy = new ExternalProxy
                {
                    HostName = "localhost",
                    Port     = upStreamProxy.ProxyEndPoints[0].Port
                };

                ProxyServer.UpStreamHttpsProxy = new ExternalProxy
                {
                    HostName = "localhost",
                    Port     = upStreamProxy.ProxyEndPoints[0].Port
                };
            }

            ProxyServer.Start();
        }
        public void StartProxy()
        {
            ProxyTestController();

            proxyServer.BeforeRequest  += OnRequest;
            proxyServer.BeforeResponse += OnResponse;

            proxyServer.ServerCertificateValidationCallback += OnCertificateValidation;
            proxyServer.ClientCertificateSelectionCallback  += OnCertificateSelection;

            AppndText("Opening port: " + Properties.Settings.Default.port, Color.Black);

            explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, Properties.Settings.Default.port);

            explicitEndPoint.BeforeTunnelConnectRequest  += OnBeforeTunnelConnectRequest;
            explicitEndPoint.BeforeTunnelConnectResponse += OnBeforeTunnelConnectResponse;

            proxyServer.AddEndPoint(explicitEndPoint);
            try
            {
                proxyServer.Start();
                foreach (var endPoint in proxyServer.ProxyEndPoints)
                {
                    AppndText("Listening on " + endPoint.GetType().Name + " endpoint at Ip " + endPoint.IpAddress + " and port: " + endPoint.Port, Color.Black);
                }
                proxyServer.SetAsSystemProxy(explicitEndPoint, ProxyProtocolType.AllHttp);
                proxyStarted = true;
                sTARTToolStripMenuItem.Enabled = false;
                sTOPToolStripMenuItem.Enabled  = true;
            }
            catch
            {
                AppndText("Proxy is already running. Port is in use.", Color.Red);
            }
        }
Beispiel #10
0
        public void StartProxy()
        {
            proxyServer.BeforeRequest  += OnRequest;
            proxyServer.BeforeResponse += OnResponse;
            proxyServer.ServerCertificateValidationCallback += OnCertificateValidation;
            proxyServer.ClientCertificateSelectionCallback  += OnCertificateSelection;

            //Exclude Https addresses you don't want to proxy
            //Usefull for clients that use certificate pinning
            //for example dropbox.com
            var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true)
            {
                // ExcludedHttpsHostNameRegex = new List<string>() { "google.com", "dropbox.com" }
            };

            //An explicit endpoint is where the client knows about the existance of a proxy
            //So client sends request in a proxy friendly manner
            proxyServer.AddEndPoint(explicitEndPoint);
            proxyServer.Start();


            //Transparent endpoint is usefull for reverse proxying (client is not aware of the existance of proxy)
            //A transparent endpoint usually requires a network router port forwarding HTTP(S) packets to this endpoint
            //Currently do not support Server Name Indication (It is not currently supported by SslStream class)
            //That means that the transparent endpoint will always provide the same Generic Certificate to all HTTPS requests
            //In this example only google.com will work for HTTPS requests
            //Other sites will receive a certificate mismatch warning on browser
            var transparentEndPoint = new TransparentProxyEndPoint(IPAddress.Any, 8001, true)
            {
                GenericCertificateName = "google.com"
            };

            proxyServer.AddEndPoint(transparentEndPoint);

            //ProxyServer.UpStreamHttpProxy = new ExternalProxy() { HostName = "localhost", Port = 8888 };
            //ProxyServer.UpStreamHttpsProxy = new ExternalProxy() { HostName = "localhost", Port = 8888 };

            foreach (var endPoint in proxyServer.ProxyEndPoints)
            {
                Console.WriteLine("Listening on '{0}' endpoint at Ip {1} and port: {2} ",
                                  endPoint.GetType().Name, endPoint.IpAddress, endPoint.Port);
            }

            //Only explicit proxies can be set as system proxy!
            proxyServer.SetAsSystemHttpProxy(explicitEndPoint);
            proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
        }
Beispiel #11
0
        public MainWindow()
        {
            proxyServer = new ProxyServer();
            //proxyServer.CertificateManager.CertificateEngine = CertificateEngine.DefaultWindows;

            ////Set a password for the .pfx file
            //proxyServer.CertificateManager.PfxPassword = "******";

            ////Set Name(path) of the Root certificate file
            //proxyServer.CertificateManager.PfxFilePath = @"C:\NameFolder\rootCert.pfx";

            ////do you want Replace an existing Root certificate file(.pfx) if password is incorrect(RootCertificate=null)?  yes====>true
            //proxyServer.CertificateManager.OverwritePfxFile = true;

            ////save all fake certificates in folder "crts"(will be created in proxy dll directory)
            ////if create new Root certificate file(.pfx) ====> delete folder "crts"
            //proxyServer.CertificateManager.SaveFakeCertificates = true;

            proxyServer.ForwardToUpstreamGateway = true;

            ////if you need Load or Create Certificate now. ////// "true" if you need Enable===> Trust the RootCertificate used by this proxy server
            //proxyServer.CertificateManager.EnsureRootCertificate(true);

            ////or load directly certificate(As Administrator if need this)
            ////and At the same time chose path and password
            ////if password is incorrect and (overwriteRootCert=true)(RootCertificate=null) ====> replace an existing .pfx file
            ////note : load now (if existed)
            //proxyServer.CertificateManager.LoadRootCertificate(@"C:\NameFolder\rootCert.pfx", "PfxPassword");

            var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true);

            proxyServer.AddEndPoint(explicitEndPoint);
            //proxyServer.UpStreamHttpProxy = new ExternalProxy
            //{
            //    HostName = "158.69.115.45",
            //    Port = 3128,
            //    UserName = "******",
            //    Password = "******",
            //};

            proxyServer.BeforeRequest  += ProxyServer_BeforeRequest;
            proxyServer.BeforeResponse += ProxyServer_BeforeResponse;
            proxyServer.AfterResponse  += ProxyServer_AfterResponse;
            explicitEndPoint.BeforeTunnelConnectRequest  += ProxyServer_BeforeTunnelConnectRequest;
            explicitEndPoint.BeforeTunnelConnectResponse += ProxyServer_BeforeTunnelConnectResponse;
            proxyServer.ClientConnectionCountChanged     += delegate
            {
                Dispatcher.Invoke(() => { ClientConnectionCount = proxyServer.ClientConnectionCount; });
            };
            proxyServer.ServerConnectionCountChanged += delegate
            {
                Dispatcher.Invoke(() => { ServerConnectionCount = proxyServer.ServerConnectionCount; });
            };
            proxyServer.Start();

            proxyServer.SetAsSystemProxy(explicitEndPoint, ProxyProtocolType.AllHttp);

            InitializeComponent();
        }
        public void StartProxy()
        {
            proxyServer.BeforeRequest  += OnRequest;
            proxyServer.BeforeResponse += OnResponse;

            proxyServer.ServerCertificateValidationCallback += OnCertificateValidation;
            proxyServer.ClientCertificateSelectionCallback  += OnCertificateSelection;

            //proxyServer.EnableWinAuth = true;

            explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8000, true)
            {
                //You can set only one of the ExcludedHttpsHostNameRegex and IncludedHttpsHostNameRegex properties, otherwise ArgumentException will be thrown

                //Use self-issued generic certificate on all https requests
                //Optimizes performance by not creating a certificate for each https-enabled domain
                //Useful when certificate trust is not required by proxy clients
                //GenericCertificate = new X509Certificate2(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "genericcert.pfx"), "password")
            };

            //Fired when a CONNECT request is received
            explicitEndPoint.BeforeTunnelConnectRequest  += OnBeforeTunnelConnectRequest;
            explicitEndPoint.BeforeTunnelConnectResponse += OnBeforeTunnelConnectResponse;

            //An explicit endpoint is where the client knows about the existence of a proxy
            //So client sends request in a proxy friendly manner
            proxyServer.AddEndPoint(explicitEndPoint);
            proxyServer.Start();

            //Transparent endpoint is useful for reverse proxy (client is not aware of the existence of proxy)
            //A transparent endpoint usually requires a network router port forwarding HTTP(S) packets or DNS
            //to send data to this endPoint
            //var transparentEndPoint = new TransparentProxyEndPoint(IPAddress.Any, 443, true)
            //{
            //    //Generic Certificate hostname to use
            //    //When SNI is disabled by client
            //    GenericCertificateName = "google.com"
            //};

            //proxyServer.AddEndPoint(transparentEndPoint);

            //proxyServer.UpStreamHttpProxy = new ExternalProxy() { HostName = "localhost", Port = 8888 };
            //proxyServer.UpStreamHttpsProxy = new ExternalProxy() { HostName = "localhost", Port = 8888 };

            foreach (var endPoint in proxyServer.ProxyEndPoints)
            {
                Console.WriteLine("Listening on '{0}' endpoint at Ip {1} and port: {2} ", endPoint.GetType().Name, endPoint.IpAddress, endPoint.Port);
            }

#if NETSTANDARD2_0
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
#endif
            {
                //Only explicit proxies can be set as system proxy!
                //proxyServer.SetAsSystemHttpProxy(explicitEndPoint);
                //proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
                proxyServer.SetAsSystemProxy(explicitEndPoint, ProxyProtocolType.AllHttp);
            }
        }
            public ProxyTestController()
            {
                proxyServer = new ProxyServer();
                var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 0, true);

                proxyServer.AddEndPoint(explicitEndPoint);
                proxyServer.Start();
            }
Beispiel #14
0
        public void Start()
        {
            var endpoint = new ExplicitProxyEndPoint(IPAddress.Loopback, 8080);

            proxy.AddEndPoint(endpoint);

            proxy.Start();
        }
Beispiel #15
0
        void InitProxy()
        {
            var proxy = new ProxyServer();

            proxy.AddEndPoint(new ExplicitProxyEndPoint(IPAddress.Any, 8881, true));
            proxy.BeforeResponse += Proxy_BeforeResponse;
            proxy.Start();
        }
Beispiel #16
0
        public MusicProxy()
        {
            server = new ProxyServer(false, false, false);
            server.BeforeRequest += OnRequest;
            var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Loopback, 0, false);

            server.AddEndPoint(explicitEndPoint);
        }
Beispiel #17
0
        public async Task WhenProxyAuthenticationIsRequired()
        {
            using var proxyServer = new ProxyServer();
            const int port = 12312;

            var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, port, false);

            proxyServer.AddEndPoint(explicitEndPoint);
            // Fake authentication failure for proxy
            proxyServer.ProxySchemeAuthenticateFunc = (d, s, arg3) => Task.FromResult(new ProxyAuthenticationContext {
                Result = ProxyAuthenticationResult.Failure
            });
            proxyServer.ProxyAuthenticationSchemes = new[] { "basic" };
            proxyServer.Start();
            var baseUrl = "http://notexistingdomain.dddd.ttt";

            httpClientFactory.CreateClient()
            .Returns(
                _ =>
            {
                var httpClient = new HttpClient(new HttpClientHandler {
                    Proxy = new WebProxy("127.0.0.1", port)
                })
                {
                    BaseAddress = new Uri(baseUrl)
                };

                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                    "Basic",
                    Convert.ToBase64String(Encoding.UTF8.GetBytes("username:authToken")));

                return(httpClient);
            });

            var installationIdProvider = Substitute.For <IInstallationIdProvider>();

            installationIdProvider.GetInstallationId().Returns(Guid.NewGuid());

            store.GetConnectAppUrl().Returns(baseUrl);

            var action      = new JiraConnectAppConnectivityCheckAction(log, store, installationIdProvider, new JiraConnectAppClient(installationIdProvider, store, httpClientFactory), httpClientFactory);
            var octoRequest = Substitute.For <IOctoRequest>();

            octoRequest.GetBody(Arg.Any <RequestBodyRegistration <JiraConnectAppConnectionCheckData> >())
            .Returns(
                new JiraConnectAppConnectionCheckData
            {
                BaseUrl = baseUrl, Password = "******"
            });

            var response = await action.ExecuteAsync(octoRequest);

            var connectivityCheckResponse = (ConnectivityCheckResponse)((OctoDataResponse)response.Response).Model;

            connectivityCheckResponse.Messages.ShouldNotBeEmpty();
            connectivityCheckResponse.Messages.First().Message.ShouldBe("Failed to get authentication token from Jira Connect App.");
        }
Beispiel #18
0
        public void Start(string host, int port)
        {
            _proxyServer.BeforeRequest += OnBeforeRequest;
            var proxySettings = new ExplicitProxyEndPoint(IPAddress.Parse(host), port);

            _proxyServer.AddEndPoint(proxySettings);
            _proxyServer.Start();
            _proxyServer.SetAsSystemProxy(proxySettings, ProxyProtocolType.AllHttp);
        }
Beispiel #19
0
 public void StartProxyServer()
 {
     _proxyServer.AddEndPoint(_explicitProxy);
     _proxyServer.ProxyBasicAuthenticateFunc = BasicAuthenticate;
     _proxyServer.BeforeRequest  += BeforeRequest;
     _proxyServer.BeforeResponse += BeforeResponse;
     _proxyServer.Start();
     Debug.WriteLine(nameof(StartProxyServer));
 }
Beispiel #20
0
        public BuildProxy(string filesDir)
        {
            this.filesDir = filesDir;
            proxy         = new ProxyServer();
            proxy.AddEndPoint(new ExplicitProxyEndPoint(IPAddress.Any, 8000, decryptSsl: true));

            proxy.BeforeRequest  += ProxyOnBeforeRequest;
            proxy.BeforeResponse += ProxyOnBeforeResponse;
        }
Beispiel #21
0
 public RProxyServer(int port)
 {
     _server = new ProxyServer(false);
     _ep     = new ExplicitProxyEndPoint(IPAddress.Any, port == 0 ? NetworkUtils.GetAvailablePort() : port, false);
     Port    = _ep.Port;
     _server.AddEndPoint(_ep);
     _server.CertificateManager.RootCertificate = new X509Certificate2();
     _server.BeforeRequest  += _server_BeforeRequest;
     _server.BeforeResponse += _server_BeforeResponse;
 }
        /// <summary>
        /// Starts a local proxy
        /// </summary>
        private static void StartProxy()
        {
            proxyServer = new ProxyServer();
            var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, 8002, true);

            proxyServer.AddEndPoint(explicitEndPoint);
            proxyServer.Start();
            proxyServer.BeforeRequest  += OnRequestCaptureTrafficEventHandler;
            proxyServer.BeforeResponse += OnResponseCaptureTrafficEventHandler;
        }
Beispiel #23
0
        public void NewProxy(int usePort)
        {
            ProxyServer = new ProxyServer();

            var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, usePort, true);

            ProxyServer.AddEndPoint(explicitEndPoint);

            ProxyServer.ForwardToUpstreamGateway = true;
        }
Beispiel #24
0
        static void Main(string[] args)
        {
            var proxyServer = new ProxyServer();

            var httpEP  = new ExplicitProxyEndPoint(IPAddress.Any, 14300, false);
            var httpsEP = new ExplicitProxyEndPoint(IPAddress.Any, 14301, true);

            proxyServer.AddEndPoint(httpEP);
            proxyServer.AddEndPoint(httpsEP);

            proxyServer.BeforeRequest += OnRequest;

            proxyServer.Start();

            Console.WriteLine("Press a key when you're done.");
            Console.Read();

            proxyServer.BeforeRequest -= OnRequest;
            proxyServer.Stop();
        }
Beispiel #25
0
        private void SetProxyEndPoint(ExplicitProxyEndPoint endPoint)
        {
            if (explicitEndPoint != null)
            {
                _proxyServer.RemoveEndPoint(explicitEndPoint);
            }

            explicitEndPoint = endPoint;

            _proxyServer.AddEndPoint(explicitEndPoint);
        }
        public void Start()
        {
            proxyServer.BeforeRequest += OnRequest;
            proxyServer.AddEndPoint(new ExplicitProxyEndPoint(IPAddress.Any, 15213, true));
            proxyServer.Start();

            foreach (var endPoint in proxyServer.ProxyEndPoints)
            {
                Console.WriteLine("Started proxy on IP {0} and port {1}", endPoint.IpAddress, endPoint.Port);
            }
        }
        public void StartProxy()
        {
            _proxyServer = new ProxyServer();
            _proxyServer.AddEndPoint(_explicitEndPoint);
            _proxyServer.Start();

            _proxyServer.CertificateManager.TrustRootCertificate(true);
            _proxyServer.BeforeRequest  += OnRequest;
            _proxyServer.BeforeRequest  += OnRequestBlock;
            _proxyServer.BeforeResponse += OnResponse;
        }
        public ProxyService(ProxySettings settings)
        {
            this.settings = settings;

            proxyServer = new ProxyServer();

            explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, settings.ListenPort, false);

            explicitEndPoint.BeforeTunnelConnectRequest += OnBeforeTunnelConnect;

            proxyServer.AddEndPoint(explicitEndPoint);
        }
Beispiel #29
0
        /// <summary>
        /// 初始化代理
        /// </summary>
        private Proxy()
        {
            proxyServer = new ProxyServer(false);

            proxyServer.BeforeRequest  += OnRequest;
            proxyServer.BeforeResponse += OnResponse;

            Port = GetFirstAvailablePort();
            var explicitEndPoint = new ExplicitProxyEndPoint(IPAddress.Any, Port, true);

            proxyServer.AddEndPoint(explicitEndPoint);
        }
Beispiel #30
0
        public void Start(IEnumerable <IServiceConfig> serviceConfig = null)
        {
            LogState("Start");

            if (_state == ServiceState.Halted)
            {
                if (serviceConfig != null)
                {
                    SetConfig(serviceConfig);
                }


                // Stop proxy server if it's somehow internally running due to a mismatched state (due to errors on a previous startup)
                if (_proxyServer.ProxyRunning)
                {
                    _logger.LogWarning("HTTPProxy: Engine's state and ours do not match. This is not supposed to happen! Attempting to fix...");
                    _proxyServer.Stop();
                }

                // Remove all old endpoints, if they exist, prior to startup.
                // Everything else will be reset anyway.
                var existingEndPoints = _proxyServer.ProxyEndPoints.ToArray();
                foreach (var endPoint in existingEndPoints)
                {
                    _proxyServer.RemoveEndPoint(endPoint);
                }

                //Loop through and listen on all defined IP <-> port pairs
                foreach (var listener in _proxyConfig.listeners)
                {
                    var endpoint = new ExplicitProxyEndPoint(IPAddress.Parse(listener.Item1), listener.Item2,
                                                             false);

                    endpoint.BeforeTunnelConnectRequest  += OnTunnelConnectRequest;
                    endpoint.BeforeTunnelConnectResponse += OnTunnelConnectResponse;

                    _proxyServer.AddEndPoint(endpoint);
                    _logger.LogDebug($"HTTPProxy: Now listening on {listener.Item1}:{listener.Item2}");
                }

                _proxyServer.ProxyAuthenticationRealm    = "Spectero";
                _proxyServer.ProxyBasicAuthenticateFunc += _authenticator.AuthenticateHttpProxy;
                _proxyServer.BeforeRequest  += OnRequest;
                _proxyServer.BeforeResponse += OnResponse;
                _proxyServer.ExceptionFunc   = HandleInternalProxyError;


                _proxyServer.Start();
                _state = ServiceState.Running;
                _logger.LogInformation($"HTTPProxy: now listening on {_proxyConfig.listeners.Count} endpoints.");
            }
            LogState("Start");
        }