コード例 #1
0
        public static async Task Main(string[] args)
        {
            var apiUrl = "https://api.blazor.ninja";

            // TODO Paste your app token below
            var appToken = "eyJ0eXAiOiJDU1AiLCAiZW5jIjoiUlNBX09BRVAifQ.AKlw3OJSfuEPNSzGT72CL0QQWhUQe2iLyMEv7F-q6j9M6_LLcXYNgA5b5Xl2p-6lOQUq-GAF3peBSyXR_f5ANpHinydE_MKROfrz39xiOXDO9duhVNJHUiQ6BoPzrop-nTATO5O331HDepU-pd1EzaLkUbtj8YRg2CIRhHKydaM.Q9pYG1eESeStPAq3.t1PGIguzLp7_j76FaTgR5bO4RUvslSk5eJYcGbxvLn9yj5sWqpAWYBOA_-26Xw.sJ9wUdLl8vS6uXwStXdbgA";

            var builder = WebAssemblyHostBuilder.CreateDefault(args);

            builder.RootComponents.Add <App>("app");

            builder.Services.AddScoped(sp => new HttpClient {
                BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)
            });

            builder.Services.AddStorage();

            var proxyFactory = new HttpProxyFactory(apiUrl, appToken);

            builder.Services.AddSingleton <IProxyFactory>(proxyFactory);

            var configurationProxy = new HttpConfigurationProxy(apiUrl, appToken);
            await Task.WhenAll(new List <Task>
            {
                Task.Run(async() => await configurationProxy.GetNamespaceAsync(UserNamespace.Label)),
                Task.Run(async() => await configurationProxy.GetFeatureAsync <OnboardingFeature>()),
                Task.Run(async() => await configurationProxy.GetFeatureAsync <PostboardingFeature>()),
                Task.Run(async() => await configurationProxy.GetFeatureAsync <ThemeFeature>())
            });

            builder.Services.AddSingleton <IConfigurationProxy>(configurationProxy);

            await builder.Build().RunAsync();
        }
コード例 #2
0
        /// <summary>
        /// Loads the Traffic Viewer extensions
        /// </summary>
        public void LoadExtensions()
        {
            SdkSettings.Instance.ExtensionInfoList = TrafficViewerOptions.Instance.GetExtensionInfo();

            //load modules
            TrafficParserFactory parserFactory = new TrafficParserFactory();

            _trafficParsers = parserFactory.GetExtensions();
            ExporterFactory exporterFactory = new ExporterFactory();

            _trafficExporters = exporterFactory.GetExtensions();
            AnalysisModulesFactory analysisModulesFactory = new AnalysisModulesFactory();

            _analysisModules = analysisModulesFactory.GetExtensions();
            ExploiterFactory exploitersFactory = new ExploiterFactory();

            _exploiters = exploitersFactory.GetExtensions();

            SenderFactory senderFactory = new SenderFactory();

            _senders = senderFactory.GetExtensions();
            HttpClientExtensionFactory clientFactoryLoader = new HttpClientExtensionFactory();

            _httpClientFactoryList = clientFactoryLoader.GetExtensions();
            _httpClientFactoryList.Add(new WebRequestClientFactory());
            _httpClientFactory = null;
            //find in the list of client factories the one with the name specified in options
            foreach (IHttpClientFactory clientFactory in _httpClientFactoryList)
            {
                if (String.Compare(clientFactory.ClientType, TrafficViewerOptions.Instance.HttpClientName) == 0)
                {
                    _httpClientFactory = clientFactory;
                    break;
                }
            }

            if (_httpClientFactory == null)
            {
                //if the factory was not found use the default
                _httpClientFactory = new TrafficViewerHttpClientFactory();
                //log a warning
                SdkSettings.Instance.Logger.Log(TraceLevel.Warning, "Could not find HTTP client factory for {0}", TrafficViewerOptions.Instance.HttpClientName);
                TrafficViewerOptions.Instance.HttpClientName = _httpClientFactory.ClientType;
            }

            HttpProxyFactory proxyFactory = new HttpProxyFactory();

            _httpProxyFactoryList = proxyFactory.GetExtensions();
        }
コード例 #3
0
        public void AfterSessionCompleteTest()
        {
            var server = new TestTcpServer();
            var engine = new DefaultEngine(server);

            var proxy       = HttpProxyFactory.Create(engine);
            var tcsComplete = new TaskCompletionSource <IReadOnlySession>();

            proxy.HttpResponseSent += (_, s) => tcsComplete.TrySetResult(s.Session);

            var clientTcp = new TestTcpClient();

            server.AcceptTcp(clientTcp);
            var connection = engine.connections.Last();

            connection.CreateTcpClientForServer = (host, port) => new TestTcpClient(host, port);

            var request =
                @"CONNECT www.example.com:443 HTTP/1.1
Host: www.example.com:443
Proxy-Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36

";

            clientTcp.WriteToInput(request);

            var expectedResponse =
                @"HTTP/1.1 200 Connection Established
Date: Mon, 01 Jan 2018 01:00:00 GMT

";

            var session = tcsComplete.GetResult();

            session.Request.ToString().Is(request);
            session.Response.ToString().Is(expectedResponse);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: veigr/Nekoxy2
        private static void StartTitanium()
        {
            var engine = new TitaniumEngine();
            var proxy  = HttpProxyFactory.Create(engine);

            proxy.HttpRequestReceived += (_, args) =>
            {
                Console.WriteLine($"HttpRequestReceived: {args.Request.GetHost()} {args.Request.RequestLine.Method} {args.Request.RequestLine.RequestTarget}");
                args.Request.Headers.SetValue("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0");
            };

            proxy.HttpResponseReceived += (_, args) =>
            {
                Console.WriteLine($"HttpResponseReceived: {args.Session.Response.StatusLine.StatusCode}");
                args.Session.Response.Headers.SetValue("X-Hoge", "hogeee");
            };

            proxy.HttpResponseSent += (_, args)
                                      => Console.WriteLine($"HttpResponseSent: {args.Session.Response.StatusLine.StatusCode}, Body: {args.Session.Response.Body?.Count.ToString() ?? "?"} bytes");

            //proxy.FatalException += (_, args)
            //    => Console.WriteLine(args.Exception);

            try
            {
                proxy.Start();
                while (true)
                {
                    Task.Delay(1000).Wait();
                }
            }
            finally
            {
                proxy.Stop();
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: veigr/Nekoxy2
        private static void StartDefault()
        {
            if (CertificateUtil.FindRootCertificate() == default)
            {
                CertificateUtil.InstallNewRootCertificate();
            }
            //CertificateUtil.UninstallRootCertificates();
            //CertificateUtil.UninstallAllServerCertificatesByIssuer();
            //var ca = CertificateUtil.FindRootCertificate();
            //CertificateUtil.UninstallFromRootStore(ca);

            var engine = DefaultEngine.Create(new ListeningConfig(8080));

            engine.DecryptConfig.IsDecrypt = true;
            //engine.DecryptConfig.HostFilterHandler = host
            //    => host.EndsWith("cat-ears.net");
            // engine.DecryptConfig.RootCertificateResolver = store => store.FindRootCertificate("Titanium Root Certificate Authority");
            engine.DecryptConfig.CacheLocations
                = new[] {   // 定義順が読み取り優先順
                CertificateCacheLocation.Memory,
                CertificateCacheLocation.Custom,
                CertificateCacheLocation.Store,
                };
            engine.DecryptConfig.ServerCertificateCacheResolver = host =>
            {
                Console.WriteLine($"### ServerCertificateCacheResolver: {host}");
                return(null);
                //var path = host.Replace("*", "$x$") + ".pfx";
                //if (!File.Exists(path)) return null;
                //var bytes = File.ReadAllBytes(path);
                //return new X509Certificate2(bytes);
            };
            engine.ServerCertificateCreated += (_, c) =>
            {
                Console.WriteLine($"### ServerCertificateCreated: {c.Certificate.Subject}");
                //var path = c.Certificate.Subject.Replace("CN=", "").Replace("*", "$x$") + ".pfx";
                //if (!File.Exists(path))
                //    File.WriteAllBytes(path, c.Certificate.RawData);
            };

            engine.UpstreamProxyConfig = null;
            engine.ConnectionAdded    += (_, c) => Console.WriteLine($"### Connection Added. Connections Count: {c.Count}");
            engine.ConnectionRemoved  += (_, c) => Console.WriteLine($"### Connection Removed. Connections Count: {c.Count}");


            var proxy = HttpProxyFactory.Create(engine);

            proxy.FatalException   += (_, e) => Console.WriteLine(e.Exception);
            proxy.HttpResponseSent += (_, s) =>
            {
                if (IsOutputHeaders(s.Session))
                {
                    Console.WriteLine($"{s.Session.GetHost()}: {s.Session.Request}\r\n" +
                                      $"{s.Session.Response.StatusLine }{s.Session.Response.Headers}");
                }
                else if (s.Session.Request.RequestLine.Method.Method != "CONNECT")
                {
                    Console.WriteLine($"{s.Session.GetHost()}: {s.Session.Request.RequestLine}" +
                                      $"{s.Session.Response.StatusLine}");
                }
            };
            proxy.ClientWebSocketMessageSent += (_, m) =>
            {
                var host = m.Message.HandshakeSession.GetHost();
                if (m.Message.Opcode == WebSocketOpcode.Text)
                {
                    Console.WriteLine(
                        $@"ClientWebSocketMessage: {host}
Text: {Encoding.UTF8.GetString(m.Message.PayloadData.ToArray())}");
                }
                else
                {
                    //                    Console.WriteLine(
                    //$@"ClientWebSocketMessage: {host}
                    //{m.Message.Opcode}: {m.Message.PayloadData.Count} bytes.");
                }
            };
            proxy.ServerWebSocketMessageSent += (_, m) =>
            {
                var host = m.Message.HandshakeSession.GetHost();
                if (m.Message.Opcode == WebSocketOpcode.Text)
                {
                    Console.WriteLine(
                        $@"ServerWebSocketMessage: {host}
Text: {Encoding.UTF8.GetString(m.Message.PayloadData.ToArray())}");
                }
                else
                {
                    //                    Console.WriteLine(
                    //$@"ServerWebSocketMessage: {host}
                    //{m.Message.Opcode}: {m.Message.PayloadData.Count} bytes.");
                }
            };

            try
            {
                proxy.Start();
                while (true)
                {
                    Task.Delay(1000).Wait();
                }
            }
            finally
            {
                proxy.Stop();
            }
        }