internal void SetFinalCopyLocalState(AssemblyNameExtension assemblyName, string[] frameworkPaths, ProcessorArchitecture targetProcessorArchitecture, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVersion, Microsoft.Build.Shared.FileExists fileExists, bool copyLocalDependenciesWhenParentReferenceInGac, ReferenceTable referenceTable, CheckIfAssemblyInGac checkIfAssemblyInGac) { if (this.IsUnresolvable) { this.copyLocalState = CopyLocalState.NoBecauseUnresolved; } else if (this.EmbedInteropTypes) { this.copyLocalState = CopyLocalState.NoBecauseEmbedded; } else if (this.IsConflictVictim) { this.copyLocalState = CopyLocalState.NoBecauseConflictVictim; } else { if (this.IsPrimary) { bool flag; bool flag2 = MetadataConversionUtilities.TryConvertItemMetadataToBool(this.PrimarySourceItem, "Private", out flag); if (flag) { if (flag2) { this.copyLocalState = CopyLocalState.YesBecauseReferenceItemHadMetadata; return; } this.copyLocalState = CopyLocalState.NoBecauseReferenceItemHadMetadata; return; } } else { bool flag3 = false; bool flag4 = false; foreach (DictionaryEntry entry in this.sourceItems) { bool flag5; bool flag6 = MetadataConversionUtilities.TryConvertItemMetadataToBool((ITaskItem)entry.Value, "Private", out flag5); if (flag5) { if (flag6) { flag3 = true; break; } flag4 = true; } } if (flag4 && !flag3) { this.copyLocalState = CopyLocalState.NoBecauseReferenceItemHadMetadata; return; } } if (this.IsPrerequisite && !this.UserRequestedSpecificFile) { this.copyLocalState = CopyLocalState.NoBecausePrerequisite; } else if (IsFrameworkFile(this.fullPath, frameworkPaths)) { this.copyLocalState = CopyLocalState.NoBecauseFrameworkFile; } else { if (!this.FoundInGac.HasValue) { bool flag7 = checkIfAssemblyInGac(assemblyName, targetProcessorArchitecture, getRuntimeVersion, targetedRuntimeVersion, fileExists); this.FoundInGac = new bool?(flag7); } if (this.FoundInGac.Value) { this.copyLocalState = CopyLocalState.NoBecauseReferenceFoundInGAC; } else { if (!this.IsPrimary && !copyLocalDependenciesWhenParentReferenceInGac) { bool flag8 = false; foreach (DictionaryEntry entry2 in this.sourceItems) { AssemblyNameExtension referenceFromItemSpec = referenceTable.GetReferenceFromItemSpec((string)entry2.Key); Reference reference = referenceTable.GetReference(referenceFromItemSpec); bool flag9 = false; if (!reference.FoundInGac.HasValue) { flag9 = checkIfAssemblyInGac(referenceFromItemSpec, targetProcessorArchitecture, getRuntimeVersion, targetedRuntimeVersion, fileExists); reference.FoundInGac = new bool?(flag9); } else { flag9 = reference.FoundInGac.Value; } if (!flag9) { flag8 = true; break; } } if (!flag8) { this.copyLocalState = CopyLocalState.NoBecauseParentReferencesFoundInGAC; return; } } this.copyLocalState = CopyLocalState.YesBecauseOfHeuristic; } } } }
internal void SetFinalCopyLocalState ( AssemblyNameExtension assemblyName, string[] frameworkPaths, ProcessorArchitecture targetProcessorArchitecture, GetAssemblyRuntimeVersion getRuntimeVersion, Version targetedRuntimeVersion, FileExists fileExists, GetAssemblyPathInGac getAssemblyPathInGac, bool copyLocalDependenciesWhenParentReferenceInGac, bool doNotCopyLocalIfInGac, ReferenceTable referenceTable ) { // If this item was unresolvable, then copy-local is false. if (IsUnresolvable) { CopyLocal = CopyLocalState.NoBecauseUnresolved; return; } if (EmbedInteropTypes) { CopyLocal = CopyLocalState.NoBecauseEmbedded; return; } // If this item was a conflict victim, then it should not be copy-local. if (IsConflictVictim) { CopyLocal = CopyLocalState.NoBecauseConflictVictim; return; } // If this is a primary reference then see if there's a Private metadata on the source item if (IsPrimary) { bool found; bool result = MetadataConversionUtilities.TryConvertItemMetadataToBool ( PrimarySourceItem, ItemMetadataNames.privateMetadata, out found ); if (found) { CopyLocal = result ? CopyLocalState.YesBecauseReferenceItemHadMetadata : CopyLocalState.NoBecauseReferenceItemHadMetadata; return; } } else { // This is a dependency. If any primary reference that lead to this dependency // has Private=false, then this dependency should false too. bool privateTrueFound = false; bool privateFalseFound = false; foreach (ITaskItem item in _sourceItems.Values) { bool found; bool result = MetadataConversionUtilities.TryConvertItemMetadataToBool ( item, ItemMetadataNames.privateMetadata, out found ); if (found) { if (result) { privateTrueFound = true; // Once we hit this once we know there will be no modification to CopyLocal state. // so we can immediately... break; } else { privateFalseFound = true; } } } if (privateFalseFound && !privateTrueFound) { CopyLocal = CopyLocalState.NoBecauseReferenceItemHadMetadata; return; } } // If the item was determined to be an prereq assembly. if (IsPrerequisite && !UserRequestedSpecificFile) { CopyLocal = CopyLocalState.NoBecausePrerequisite; return; } // Items in the frameworks directory shouldn't be copy-local if (IsFrameworkFile(_fullPath, frameworkPaths)) { CopyLocal = CopyLocalState.NoBecauseFrameworkFile; return; } // We are a dependency, check to see if all of our parent references have come from the GAC if (!IsPrimary && !copyLocalDependenciesWhenParentReferenceInGac) { // Did we discover a parent reference which was not found in the GAC bool foundSourceItemNotInGac = false; // Go through all of the parent source items and check to see if they were found in the GAC foreach (string key in _sourceItems.Keys) { AssemblyNameExtension primaryAssemblyName = referenceTable.GetReferenceFromItemSpec(key); Reference primaryReference = referenceTable.GetReference(primaryAssemblyName); if (doNotCopyLocalIfInGac) { // Legacy behavior, don't copy local if the assembly is in the GAC at all if (!primaryReference.FoundInGac.HasValue) { primaryReference.FoundInGac = !string.IsNullOrEmpty(getAssemblyPathInGac(primaryAssemblyName, targetProcessorArchitecture, getRuntimeVersion, targetedRuntimeVersion, fileExists, true, false)); } if (!primaryReference.FoundInGac.Value) { foundSourceItemNotInGac = true; break; } } else { if (!primaryReference.ResolvedFromGac) { foundSourceItemNotInGac = true; break; } } } // All parent source items were found in the GAC. if (!foundSourceItemNotInGac) { CopyLocal = CopyLocalState.NoBecauseParentReferencesFoundInGAC; return; } } if (doNotCopyLocalIfInGac) { // Legacy behavior, don't copy local if the assembly is in the GAC at all if (!FoundInGac.HasValue) { FoundInGac = !string.IsNullOrEmpty(getAssemblyPathInGac(assemblyName, targetProcessorArchitecture, getRuntimeVersion, targetedRuntimeVersion, fileExists, true, false)); } if (FoundInGac.Value) { CopyLocal = CopyLocalState.NoBecauseReferenceFoundInGAC; return; } } if (ResolvedFromGac) { CopyLocal = CopyLocalState.NoBecauseReferenceResolvedFromGAC; return; } // It was resolved locally, so copy it. CopyLocal = CopyLocalState.YesBecauseOfHeuristic; }
public void OnGet() { try { cid = Convert.ToInt32(HttpContext.Request.Query["cid"].ToString()); sid = Convert.ToInt32(HttpContext.Request.Query["sid"].ToString()); } catch (Exception) { errors = new List <string>(); errors.Add("How did you get here? Invalid url."); //errors.Add(e.Message); return; } SnortContext db = HttpContext.RequestServices.GetService(typeof(SnortContext)) as SnortContext; if (StaticData.alerts == null) { StaticData.alerts = AlertMapper.ResolveAlerts(0, ref StaticData.signatureStrings, db.GetConnection()); } //Check for new alerts else { } if (StaticData.ref_classes == null) { StaticData.ref_classes = Reference_systemTable.GetRefClasses(db.GetConnection()); } if (StaticData.class_names == null) { StaticData.class_names = Sig_classTable.GetClassNames(db.GetConnection()); } if (StaticData.protocols == null) { StaticData.protocols = XmlUtils.GetProcotols(); //StaticData.protocols = db.GetProtocols(); } if (StaticData.trprotocols == null) { StaticData.trprotocols = XmlUtils.GetTransportProcotols(); } alerts.Add(StaticData.alerts.Where(x => x.cid == cid && x.sid == sid).FirstOrDefault()); //SessionExtensions.Set<List<Alert>>(HttpContext.Session,"alert", alerts); eve = EventTable.GetEvent(cid, sid, db.GetConnection()); if (eve.cid == 0) { errors = new List <string>(); errors.Add("How did you get here? Event not found."); //errors.Add(e.Message); return; } //SIGNATURE Signature signature = SignatureTable.GetSignature(eve.signature, db.GetConnection()); if (signature.sig_class_id > 0) { StaticData.class_names.TryGetValue(signature.sig_class_id, out className); signature.class_name = className; signatures.Add(signature); } sigrefs = ReferenceTable.GetReference(signature.sig_id, db.GetConnection()); if (sigrefs != null) { foreach (snortdb.Ref sigref in sigrefs) { string ref_url = StaticData.ref_classes.GetValueOrDefault(sigref.ref_system_id) + sigref.ref_tag; if (!ref_url.StartsWith("http")) { signature.ref_url += "<a href=http://" + ref_url + " target=\"_blank\">" + ref_url + "</a></br>"; } else { signature.ref_url += "<a href=" + ref_url + " target=\"_blank\">" + ref_url + "</a></br>"; } } } else { signature.ref_url = "-"; } //IP HEADER Iphdr iphdr = IphdrTable.GetIphdr(cid, sid, db.GetConnection()); if (iphdr.source == null) { iphdr.source = AlertMapper.ResolveIP(iphdr.ip_src); } if (iphdr.destination == null) { iphdr.destination = AlertMapper.ResolveIP(iphdr.ip_dst); } string protocol = StaticData.protocols.Where(x => x.pid == iphdr.ip_proto).Select(x => x.name).FirstOrDefault(); string proto_ref = StaticData.protocols.Where(x => x.pid == iphdr.ip_proto).Select(x => x.reference).FirstOrDefault(); if (protocol != null) { if (proto_ref == null) { iphdr.protocol = protocol; } else { iphdr.protocol = "<a href=\"" + proto_ref + "\" target=\"_blank\">" + protocol + "</a>"; } } else { iphdr.protocol = iphdr.ip_proto.ToString(); } iphdrs.Add(iphdr); switch (iphdr.ip_proto) { case 1: //ICMP HEADER { Icmphdr icmphdr = IcmphdrTable.GetIcmphdr(cid, sid, db.GetConnection()); //icmphdr.icmp_type_text = Utils.Bash("cat " + path + " | grep '#" + icmphdr.icmp_type + " –'"); icmphdr.icmp_type_text = Utils.GetICMPType(icmphdr.icmp_type.ToString()); icmphdrs.Add(icmphdr); break; } case 6: //TCP HEADER { Tcphdr tcphdr = TcphdrTable.GetTcphdr(cid, sid, db.GetConnection()); //var output = Utils.Bash("cat /etc/services | grep [[:space:]]" + tcphdr.tcp_sport + "/tcp"); //var output2 = Utils.Bash("cat /etc/services | grep [[:space:]]" + tcphdr.tcp_dport + "/tcp"); TransportProtocol trp = StaticData.trprotocols.Where(x => x.number == tcphdr.tcp_sport && x.protocol == "tcp").FirstOrDefault(); TransportProtocol trp2 = StaticData.trprotocols.Where(x => x.number == tcphdr.tcp_dport && x.protocol == "tcp").FirstOrDefault(); /*if(output != "") */ if (trp != null) { if (trp.xref != null) { tcphdr.tcp_protocol = "<a href=\"" + trp.xref + "\" target=\"_blank\">" + trp.name + "</a>"; } else { tcphdr.tcp_protocol = trp.name; } // tcphdr.tcp_protocol = tcphdr.tcp_sport + " ("+ output.Split('\t')[0] + ")"; // if(output.Split('#').Count() > 1) tcphdr.tcp_protocol += " – " + output.Split('#')[1]; } else { tcphdr.tcp_protocol = tcphdr.tcp_sport.ToString(); } /*if(output2 != "") */ if (trp2 != null) { if (trp2.xref != null) { tcphdr.tcp_protocol2 = "<a href=\"" + trp2.xref + "\" target=\"_blank\">" + trp2.name + "</a>"; } else { tcphdr.tcp_protocol2 = trp2.name; } // tcphdr.tcp_protocol2 = tcphdr.tcp_dport + " ("+ output2.Split('\t')[0] + ")"; // if(output2.Split('#').Count() > 1) tcphdr.tcp_protocol2 += " – " + output2.Split('#')[1]; } else { tcphdr.tcp_protocol2 = tcphdr.tcp_dport.ToString(); } tcphdrs.Add(tcphdr); break; } case 17: //UDP HEADER { Udphdr udphdr = UdphdrTable.GetUdphdr(cid, sid, db.GetConnection()); //var output = Utils.Bash("cat /etc/services | grep [[:space:]]" + udphdr.udp_sport + "/udp"); //var output2 = Utils.Bash("cat /etc/services | grep [[:space:]]" + udphdr.udp_dport + "/udp"); TransportProtocol trp = StaticData.trprotocols.Where(x => x.number == udphdr.udp_sport && x.protocol == "udp").FirstOrDefault(); TransportProtocol trp2 = StaticData.trprotocols.Where(x => x.number == udphdr.udp_dport && x.protocol == "udp").FirstOrDefault(); /*if(output != "") */ if (trp != null) { // udphdr.udp_protocol = udphdr.udp_sport + " ("+ output.Split('\t')[0] + ")"; // if(output.Split('#').Count() > 1) udphdr.udp_protocol += " – " + output.Split('#')[1]; if (trp.xref != null) { udphdr.udp_protocol = "<a href=\"" + trp.xref + "\" target=\"_blank\">" + trp.name + "</a>"; } else { udphdr.udp_protocol = trp.name; } } else { udphdr.udp_protocol = udphdr.udp_sport.ToString(); } /*if(output2 != "") */ if (trp2 != null) { //udphdr.udp_protocol2 = udphdr.udp_dport + " ("+ output2.Split('\t')[0] + ")"; //if(output2.Split('#').Count() > 1) udphdr.udp_protocol2 += " – " + output2.Split('#')[1]; if (trp2.xref != null) { udphdr.udp_protocol2 = "<a href=\"" + trp2.xref + "\" target=\"_blank\">" + trp2.name + "</a>"; } else { udphdr.udp_protocol2 = trp2.name; } } else { udphdr.udp_protocol2 = udphdr.udp_dport.ToString(); } udphdrs.Add(udphdr); break; } default: { break; } } //WHOIS - RIPE using (WebClient wc = new WebClient()) { snortdb.Attributes attList = new snortdb.Attributes(); try //SOURCE { string url = "https://rest.db.ripe.net/search.xml?query-string=" + iphdr.source + "&flags=no-filtering&source=RIPE"; var json = wc.DownloadString(url); XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(json); XmlNode root = xdoc.DocumentElement; attList.attributes = new List <snortdb.Attribute>(); foreach (XmlNode record in root.SelectNodes("objects/object")) { if (record.Attributes["type"].Value == "inetnum" || record.Attributes["type"].Value == "inet6num" || record.Attributes["type"].Value == "person" || record.Attributes["type"].Value == "route") { foreach (XmlNode att in record.SelectNodes(@"attributes/attribute")) { if (att.Attributes["name"].Value == "remarks") { continue; } attList.attributes.Add(new snortdb.Attribute(att.Attributes["name"].Value, att.Attributes["value"].Value)); } } } if (attList.attributes.Count() > 0) { whoisURL = "https://apps.db.ripe.net/db-web-ui/#/query?searchtext=" + iphdr.source + "&source=RIPE&bflag=true"; attList.attributes.Add(new snortdb.Attribute("source url", "<a href=\"" + whoisURL + "\" target=\"_blank\">" + whoisURL + "<a>")); whoisData.Add(new AttributeOutput(String.Join("<br>", attList.attributes.Select(x => x.name)), String.Join("<br>", attList.attributes.Select(x => x.value)))); } } catch (Exception) { } attList.attributes.Clear(); try //DESTINATION { string url = "https://rest.db.ripe.net/search.xml?query-string=" + iphdr.destination + "&flags=no-filtering&source=RIPE"; var json = wc.DownloadString(url); XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(json); XmlNode root = xdoc.DocumentElement; attList.attributes = new List <snortdb.Attribute>(); foreach (XmlNode record in root.SelectNodes("objects/object")) { if (record.Attributes["type"].Value == "inetnum" || record.Attributes["type"].Value == "inet6num" || record.Attributes["type"].Value == "person" || record.Attributes["type"].Value == "route") { foreach (XmlNode att in record.SelectNodes(@"attributes/attribute")) { if (att.Attributes["name"].Value == "remarks") { continue; } attList.attributes.Add(new snortdb.Attribute(att.Attributes["name"].Value, att.Attributes["value"].Value)); } } } if (attList.attributes.Count() > 0) { whoisURL2 = "https://apps.db.ripe.net/db-web-ui/#/query?searchtext=" + iphdr.destination + "&source=RIPE&bflag=true"; attList.attributes.Add(new snortdb.Attribute("source url", "<a href=\"" + whoisURL2 + "\" target=\"_blank\">" + whoisURL2 + "<a>")); whoisData2.Add(new AttributeOutput(String.Join("<br>", attList.attributes.Select(x => x.name)), String.Join("<br>", attList.attributes.Select(x => x.value)))); } } catch (Exception) { } } //SessionExtensions.Set<List<Data>>(HttpContext.Session,"datas", datas); }