public ManualExploreBrowser(ITrafficDataAccessor source, string url) //:base(source) { //Start the internal proxy _proxy = new AdvancedExploreProxy(TrafficViewer.Instance.Options.TrafficServerIp, TrafficViewer.Instance.Options.TrafficServerPort, source); if (TrafficViewerOptions.Instance.UseProxy) { WebProxy proxy = new WebProxy(TrafficViewerOptions.Instance.HttpProxyServer, TrafficViewerOptions.Instance.HttpProxyPort); proxy.Credentials = CredentialCache.DefaultNetworkCredentials; _proxy.NetworkSettings.WebProxy = proxy; } _proxy.NetworkSettings.CertificateValidationCallback = new RemoteCertificateValidationCallback(SSLValidationCallback.ValidateRemoteCertificate); _proxy.Start(); //add logic to stop the proxy on closing this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(ManualExploreBrowser_FormClosing); //set the browser to use the internal proxy WebBrowser.SetProxySettings(_proxy.Host, _proxy.Port); //enable the request trap menu //TrapMenu.Visible = true; Text = Resources.ManualExploreBrowser; //CheckTrap.Visible = true; //CheckTrap.Checked = RequestTrap.Instance.Enabled; //CheckTrap.CheckedChanged += new EventHandler(CheckTrap_CheckedChanged); //Slider.Visible = false;//hide the progress slider and the buttons //ButtonPause.Visible = ButtonPlay.Visible = ButtonStop.Visible = false; //this.Text = Resources.ManualExploreBrowser; ////start the proxy //PlayClick(null, null); ////navigate //if (url != null) //{ // WebBrowser.Navigate(url); //} }
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); }
private HttpResponseInfo StartProxy(HttpRequestInfo requestInfo) { IHttpProxy proxy; //get the port from the url string portString = null; requestInfo.QueryVariables.TryGetValue("port", out portString); //optional secret to protect the recording session string secret = null; requestInfo.QueryVariables.TryGetValue("secret", out secret); //the host to record traffic for string targetHost = null; requestInfo.QueryVariables.TryGetValue("targetHost", out targetHost); //whether to execute inline tests string test = null; requestInfo.QueryVariables.TryGetValue("test", out test); int port; if (int.TryParse(portString, out port) && port >= 0 && port <= 65535) { if (CollectorProxyList.Instance.ProxyList.ContainsKey(port)) { return(GetResponse(400, "Bad Request", "Port in use.")); } if (targetHost == null) { return(GetResponse(400, "Bad Request", "'targetHost' parameter is not specified.")); } if (!Utils.IsMatch(targetHost, "^[\\w._-]+$") || !Utils.IsMatch(targetHost, TrafficCollectorSettings.Instance.AllowedHostsPattern)) { return(GetResponse(400, "Bad Request", "Invalid target host!")); } try { TrafficViewerFile trafficFile = new TrafficViewerFile(); trafficFile.Profile = ParsingOptions.GetRawProfile(); //optional secret to prevent others stopping the recording if (!String.IsNullOrWhiteSpace(secret)) { trafficFile.Profile.SetSingleValueOption("secret", secret); } trafficFile.Profile.SetSingleValueOption("targetHost", targetHost); if (test != null && test.Equals("true")) { CustomTestsFile testsFile = new CustomTestsFile(); testsFile.Load(TrafficCollectorSettings.Instance.TestFile); Dictionary <string, AttackTarget> targetDef = new Dictionary <string, AttackTarget>(); targetDef.Add("targetHost", new AttackTarget("targetHost", "Enabled", String.Format("Host:\\s*{0}", targetHost))); testsFile.SetAttackTargetList(targetDef); proxy = new DriveByAttackProxy(new TestController(trafficFile), testsFile, trafficFile, TrafficCollectorSettings.Instance.Ip, port); } else { proxy = new AdvancedExploreProxy(TrafficCollectorSettings.Instance.Ip, port, trafficFile); } proxy.NetworkSettings.CertificateValidationCallback = new RemoteCertificateValidationCallback(CollectorAPIController.ValidateServerCertificate); proxy.NetworkSettings.WebProxy = HttpWebRequest.GetSystemWebProxy(); proxy.Start(); CollectorProxyList.Instance.ProxyList.Add(proxy.Port, proxy); } catch (Exception ex) { return(GetResponse(500, "Unexpected error.", ex.Message)); } } else { return(GetResponse(400, "Bad Request", "Invalid 'port' parameter.")); } return(GetResponse(200, "OK", "Proxy is listening on port: {0}.", proxy.Port)); }