private void LoadFile(string path) { bool loaded = true; _testFile = new CustomTestsFile(); if (File.Exists(path)) { loaded = _testFile.Load(path); } if (!loaded) { ErrorBox.ShowDialog("Could not load file"); return; } _grid.SetValues((List <string>)_testFile.GetOption(CUSTOM_TESTS)); runAutomaticallyToolStripMenuItem.Checked = _testFile.AutoRunTests; _testRunner.SetTestFile(_testFile); }
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)); }