示例#1
0
        /// <summary>
        /// 启动服务
        /// </summary>
        /// <param name="hostControl"></param>
        /// <returns></returns>
        public bool Start(HostControl hostControl)
        {
            KingProcesser.Init();
            CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");

            // 请求前
            FiddlerApplication.BeforeRequest += (session) =>
            {
                session.bBufferResponse = true;
                var uri = new Uri(session.fullUrl);

                if (uri.Port == AppConfig.ProxyPort || uri.Port == AppConfig.WsPort)
                {
                    session.RequestHeaders["ClientIpAddress"] = session.clientIP;
                    session.host = $"{uri.Host}:{ AppConfig.WsPort}";
                }
                else if (AppConfig.AllowProxy(uri.Host) == false)
                {
                    session.Abort();
                    Console.WriteLine($"拒绝代理:{session.clientIP}->{session.fullUrl}");
                }
                else
                {
                    Console.WriteLine($"转发代理:{session.clientIP}->{session.fullUrl}");
                }
            };

            // 收到服务端的回复
            FiddlerApplication.BeforeResponse += (session) =>
            {
                try
                {
                    KingProcesser.ProcessSession(session);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            };

            // 配置代理服务器
            Cert.SetRootCertificate();
            CONFIG.IgnoreServerCertErrors = true;

            FiddlerApplication.Prefs.SetBoolPref("fiddler.network.streaming.abortifclientaborts", true);
            FiddlerApplication.Startup(AppConfig.ProxyPort, FiddlerCoreStartupFlags.AllowRemoteClients | FiddlerCoreStartupFlags.DecryptSSL);

            return(true);
        }
示例#2
0
        /// <summary>
        /// 启动服务
        /// </summary>
        /// <param name="hostControl"></param>
        /// <returns></returns>
        public bool Start(HostControl hostControl)
        {
            KingProcesser.Init();
            CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");

            FiddlerApplication.BeforeRequest += (session) =>
            {
                session.bBufferResponse = true;
                AllSessions.Add(session);

                if ((session.oRequest.pipeClient.LocalPort == sslAddress.Port) && (session.hostname == sslAddress.Host))
                {
                    session.utilCreateResponseAndBypassServer();
                    session.oResponse.headers.SetStatus(200, "Ok");
                    session.utilSetResponseBody("SSL Proxy OK ..");
                }
            };

            // 收到服务端的回复
            FiddlerApplication.BeforeResponse += (session) =>
            {
                KingProcesser.ProcessSessionAsync(session);
            };

            // 配置代理服务器
            CONFIG.IgnoreServerCertErrors = true;
            FiddlerApplication.Prefs.SetBoolPref("fiddler.network.streaming.abortifclientaborts", true);
            FiddlerApplication.Startup(proxyPort, FiddlerCoreStartupFlags.AllowRemoteClients | FiddlerCoreStartupFlags.DecryptSSL);

            sslProxyServer = FiddlerApplication.CreateProxyEndpoint(sslAddress.Port, true, sslAddress.Host);
            if (sslProxyServer == null)
            {
                Console.WriteLine("创建SSL监听失败");
            }
            return(true);
        }