private void LoadRuleList() { this.contraConfig = new CotraConfig(); //this.ProjectItemList = new List<ProjectItem>(); XmlDocument document = new XmlDocument(); document.Load(FiddlerPath.RuleFilePath); XmlNodeList allNode = document.DocumentElement.SelectNodes("//InjectionRules"); if (allNode.Count == 0) { return; } //XmlNodeList ruleNodes = document.DocumentElement.SelectNodes("//InjectionRules/Rule"); XmlNodeList ruleNodes = allNode[0].SelectNodes("Rule"); ProjectItem rule = null; this.contraConfig.Enabled = allNode[0].Attributes["Enabled"].Value; for (int i = 0, l = ruleNodes.Count; i < l; i++) { rule = new ProjectItem(); rule.ProName = ruleNodes[i].Attributes["ProName"].Value; rule.UserAgent = ruleNodes[i].Attributes["UserAgent"].Value; rule.Enabled = ruleNodes[i].Attributes["Enabled"].Value; rule.Order = ruleNodes[i].Attributes["Order"].Value; rule.InURL = ruleNodes[i].Attributes["InURL"].Value; rule.AttachedCookie = ruleNodes[i].Attributes["AttachedCookie"].Value; rule.CookieHost = ruleNodes[i].Attributes["CookieHost"].Value; rule.WhenEnabled = ruleNodes[i].Attributes["WhenEnabled"].Value; rule.WhenContents = ruleNodes[i].Attributes["WhenContents"].Value; rule.RequestCookies = ruleNodes[i].Attributes["RequestCookies"].Value; rule.IsNew = false; XmlNodeList outsNodes = ruleNodes[i].SelectNodes("Out"); rule.OutURLList = new List <OutSet>(); for (int j = 0, k = outsNodes.Count; j < k; j++) { OutSet set = new OutSet(); set.Enabled = outsNodes[j].Attributes["Enabled"].Value; set.Order = outsNodes[j].Attributes["Order"].Value; set.OutURL = outsNodes[j].Attributes["OutURL"].Value; rule.OutURLList.Add(set); } this.contraConfig.ProjectItemList.Add(rule); } }
public ConfigControl() { InitializeComponent(); this.flowLayoutPanel1.FlowDirection = FlowDirection.TopDown; this.contraConfig = ProjectItemManager.Instance().contraConfig; this.proList = this.contraConfig.ProjectItemList; this.allCheck.Checked = this.contraConfig.Enabled != null && Boolean.Parse(this.contraConfig.Enabled); for (int i = 0; i < this.proList.Count; i++) { ItemControl control = new ItemControl(this.proList[i], this); this.flowLayoutPanel1.Controls.Add(control); } ChangeLabelColor(); }
void IAutoTamper.AutoTamperResponseBefore(Session oSession) { //throw new NotImplementedException(); CotraConfig contraConfig = ProjectItemManager.Instance().contraConfig; bool flag = true; for (int i = 0, k = contraConfig.ProjectItemList.Count; i < k && flag; i++) { if (Boolean.Parse(contraConfig.Enabled) && Boolean.Parse(contraConfig.ProjectItemList[i].Enabled)) { if (!DoMatch(contraConfig.ProjectItemList[i].UserAgent, oSession.oRequest["User-Agent"])) { for (int j = 0, v = contraConfig.ProjectItemList[i].OutURLList.Count; j < v && flag; j++) { if (Boolean.Parse(contraConfig.ProjectItemList[i].OutURLList[j].Enabled) && DoMatch(contraConfig.ProjectItemList[i].OutURLList[j].OutURL, oSession.fullUrl)) { for (int m = 0, n = contraConfig.ProjectItemList[i].CookieList.Count; m < n && flag; m++) { oSession.oResponse.headers.Add("Set-Cookie", contraConfig.ProjectItemList[i].CookieList[m].Name + "=" + contraConfig.ProjectItemList[i].CookieList[m].Value + "; PATH=/; DOMAIN=" + contraConfig.ProjectItemList[i].CookieHost + ";"); } if (contraConfig.ProjectItemList[i].AttachedCookie.Length > 0) { var AttachedCookie = contraConfig.ProjectItemList[i].AttachedCookie.Split(';'); for (int x = 0, y = AttachedCookie.Length; x < y; x++) { if (AttachedCookie[x].Length > 0) { oSession.oResponse.headers.Add("Set-Cookie", AttachedCookie[x] + "; PATH=/; DOMAIN=" + contraConfig.ProjectItemList[i].CookieHost + ";"); } } } flag = false; } } } } } }
void IAutoTamper.AutoTamperRequestBefore(Session oSession) { CotraConfig contraConfig = ProjectItemManager.Instance().contraConfig; var sCookie = oSession.oRequest["Cookie"]; for (int i = 0, k = contraConfig.ProjectItemList.Count; i < k; i++) { if (Boolean.Parse(contraConfig.Enabled) && Boolean.Parse(contraConfig.ProjectItemList[i].Enabled)) { if (contraConfig.ProjectItemList[i].RequestCookies.Length > 0 && DoMatch(contraConfig.ProjectItemList[i].UserAgent, oSession.oRequest["User-Agent"]) && DoMatch(contraConfig.ProjectItemList[i].InURL, oSession.fullUrl)) { bool whenflag = true; if (Boolean.Parse(contraConfig.ProjectItemList[i].WhenEnabled) && contraConfig.ProjectItemList[i].WhenContents.Length > 0) { whenflag = false; try { Match whenmatch = new Regex("(^| )" + contraConfig.ProjectItemList[i].WhenContents + "(;|$)").Match(sCookie); if (whenmatch.Success) { whenflag = true; } } catch { } } if (whenflag) { List <CookieSet> setList = new List <CookieSet>(); var cookieStr = contraConfig.ProjectItemList[i].RequestCookies.Split(';'); for (int j = 0, v = cookieStr.Length; j < v; j++) { try { Match match = new Regex("(^| )" + cookieStr[j] + "(?:=([^;]*))?(;|$)").Match(sCookie); if (cookieStr[j].Length > 0 && match.Success) { CookieSet editItem = contraConfig.ProjectItemList[i].CookieList.Find(o => o.Name == cookieStr[j]); if (editItem != null) { editItem.Value = match.Groups[2].Value; } else { CookieSet tempset = new CookieSet(); tempset.Name = cookieStr[j]; tempset.Value = match.Groups[2].Value; contraConfig.ProjectItemList[i].CookieList.Add(tempset); } //CookieSet tempset = new CookieSet(); //tempset.Name = cookieStr[j]; //tempset.Value = match.Groups[2].Value; //setList.Add(); //contraConfig.ProjectItemList[i].CookieList.Add(tempset); } } catch { } } this.oConfigControl.RefleshCookieLabel(); } //if (setList.Count > 0) //{ // contraConfig.ProjectItemList[i].CookieList = setList; //} } } } //throw new NotImplementedException(); }