Beispiel #1
0
 public void Stop()
 {
     foreach (var endpoint in proxy.ProxyEndPoints.ToArray())
     {
         proxy.RemoveEndPoint(endpoint);
     }
     proxy.Stop();
 }
Beispiel #2
0
        private void SetProxyEndPoint(ExplicitProxyEndPoint endPoint)
        {
            if (explicitEndPoint != null)
            {
                _proxyServer.RemoveEndPoint(explicitEndPoint);
            }

            explicitEndPoint = endPoint;

            _proxyServer.AddEndPoint(explicitEndPoint);
        }
Beispiel #3
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");
        }
Beispiel #4
0
        public void StartProxy()
        {
            ProxyServer.BeforeRequest  += OnRequest;
            ProxyServer.BeforeResponse += OnResponse;

            //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>()
                {
                    "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
            //Please read about it before asking questions!
            var transparentEndPoint = new TransparentProxyEndPoint(IPAddress.Any, 8001, true)
            {
                GenericCertificateName = "google.com"
            };

            ProxyServer.AddEndPoint(transparentEndPoint);


            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);
            }

            //You can also add/remove end points after proxy has been started
            ProxyServer.RemoveEndPoint(transparentEndPoint);

            //Only explicit proxies can be set as system proxy!
            ProxyServer.SetAsSystemHttpProxy(explicitEndPoint);
            ProxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
        }