public void UpdateSummarizedData(List <HijackingTestResultDto> summarizedData) { foreach (var data in summarizedData) { data.Summarized = true; hijackingTestResultService.AddOrEdit(data); } }
public void VerifyAndSaveData(List <ResultsReturned> returnResults, DateTime executionTime) { var dmnRegIp = hijackingDomainService.GetAll(); var tfcdnServer = _TFCDNserversService.GetAll(); foreach (var result in returnResults) { try { if (!result.ErrMsg.Equals("NIL")) { result.Verified = $"Connection Error - {result.ErrMsg}"; } else { var multipleRecords = dmnRegIp.Any(s => (s.Protocol + s.Domain).Equals(result.DomainName) && s.DestinationIp.Contains(",")); var verifying = false; if (multipleRecords) { var records = dmnRegIp.FirstOrDefault(s => (s.Protocol + s.Domain).Equals(result.DomainName)).DestinationIp.Split(','); foreach (var record in records) { if (verifying == true) { break; } if (record.Equals("TFCDNservers")) { verifying = tfcdnServer.Any(s => s.ServerIp.Equals(result.ResolutionIp)); } else { verifying = record.Equals(result.ResolutionIp); } } } else { verifying = dmnRegIp.Any(s => s.Domain.Equals(result.DomainName) && s.DestinationIp.Equals(result.ResolutionIp)); } if (verifying) { result.Verified = "Normal"; } else { result.Verified = "Caution - Dns Hijacked"; } if (result.Verified.Equals("Normal") && !string.IsNullOrEmpty(result.Redirection) && !result.Redirection.Equals("NIL")) { var domainParser = new DomainParser(new WebTldRuleProvider()); var regRedirection = new DomainParser(new WebTldRuleProvider()); var redirectionList = new List <string>(); if (!result.Redirection.Contains(",")) { redirectionList.Add(result.Redirection); } else { redirectionList = result.Redirection.Split(',').ToList(); } var domainName = domainParser.Get(redirectionList.LastOrDefault()); verifying = dmnRegIp.Any(p => p.Domain.Equals(result.DomainName) && !string.IsNullOrEmpty(p.Redirection)) ? dmnRegIp.Any(z => z.Domain.Equals(result.DomainName) && regRedirection.Get(z.Redirection).Domain.Equals(domainName.Domain)) : true; if (!verifying) { result.Verified = "Caution - Http Hijacked"; } } } } catch (Exception ex) { BackendFunction.log.Error(ex); } } foreach (var record in returnResults) { var newRecord = new HijackingTestResultDto() { Domain = record.DomainName, Province = record.Province, Location = record.City, Isp = record.Isp, DestinationIp = record.ResolutionIp, Destination = record.IpFrom, Redirection = record.Redirection, Verified = record.Verified, Summarized = false, ExecutionDate = executionTime, ErrMsg = record.ErrMsg, NsLookupTime = Math.Round(record.NsLookupTime, 4), ConnectionTime = Math.Round(record.ConnectionTime, 4), TimeToFirstByte = Math.Round(record.TimeToFirstByte, 4), DownloadTime = Math.Round(record.DownloadTime, 4), TotalTime = Math.Round(record.TotalTime, 4) }; hijackingTestResultService.AddOrEdit(newRecord); } }