public override void GetVersion() { try { System.Net.IPAddress[] ips = System.Net.Dns.GetHostAddresses(Host); if (ips.Length == 0) { return; } // Hace la query como 'TXT'. Es mejor hacerla como 'ALL', pero no veo la opción en la lista de QTypes. ¿Quizas ANY? Heijden.DNS.Resolver r = new Heijden.DNS.Resolver(ips[0], base.Port); r.TimeOut = 1000; Heijden.DNS.Response response = r.Query("version.bind", Heijden.DNS.QType.TXT, Heijden.DNS.QClass.CH); if (response.RecordsTXT.Length > 0) { Version = response.RecordsTXT[0].TXT; this.os = AnalyzeBanner(Version); } if (this.FingerPrintingFinished != null) { FingerPrintingFinished(this, null); } } catch { if (FingerPrintingError != null) { FingerPrintingError(this, null); } } }
/// <summary> /// Perform a DNS lookup for a Minecraft Service using the specified domain name /// </summary> /// <param name="domain">Input domain name, updated with target host if any, else left untouched</param> /// <param name="port">Updated with target port if any, else left untouched</param> /// <returns>TRUE if a Minecraft Service was found.</returns> public static bool MinecraftServiceLookup(ref string domain, ref ushort port) { if (!String.IsNullOrEmpty(domain) && domain.Any(c => char.IsLetter(c))) { try { Console.WriteLine("Resolving {0}...", domain); Heijden.DNS.Response response = new Heijden.DNS.Resolver().Query("_minecraft._tcp." + domain, Heijden.DNS.QType.SRV); Heijden.DNS.RecordSRV[] srvRecords = response.RecordsSRV; if (srvRecords != null && srvRecords.Any()) { //Order SRV records by priority and weight, then randomly Heijden.DNS.RecordSRV result = srvRecords .OrderBy(record => record.PRIORITY) .ThenByDescending(record => record.WEIGHT) .ThenBy(record => Guid.NewGuid()) .First(); string target = result.TARGET.Trim('.'); ConsoleIO.WriteLineFormatted(String.Format("§8Found server {0}:{1} for domain {2}", target, result.PORT, domain)); domain = target; port = result.PORT; return(true); } } catch (Exception e) { ConsoleIO.WriteLineFormatted(String.Format("§8Failed to perform SRV lookup for {0}\n{1}: {2}", domain, e.GetType().FullName, e.Message)); } } return(false); }
public static bool MinecraftServiceLookup(ref string domain, ref ushort port) { if (!String.IsNullOrEmpty(domain) && domain.Any(c => char.IsLetter(c))) { try { Console.WriteLine("Resolving {0}...", domain); Heijden.DNS.Response response = new Heijden.DNS.Resolver().Query("_minecraft._tcp." + domain, Heijden.DNS.QType.SRV); Heijden.DNS.RecordSRV[] srvRecords = response.RecordsSRV; if (srvRecords != null && srvRecords.Any()) { //Order SRV records by priority and weight, then randomly Heijden.DNS.RecordSRV result = srvRecords .OrderBy(record => record.PRIORITY) .ThenByDescending(record => record.WEIGHT) .ThenBy(record => Guid.NewGuid()) .First(); string target = result.TARGET.Trim('.'); domain = target; port = result.PORT; Console.WriteLine("检测到SRV记录地址:" + domain + ":" + port); return(true); } } catch (Exception e) { Console.WriteLine("未能成功解析..." + e.Message); } } return(false); }
public List <Heijden.DNS.RecordSOA> ResolveSOA2(string name) { var res = new Heijden.DNS.Resolver("8.8.8.8"); var es = res.Query(name, Heijden.DNS.QType.SOA, Heijden.DNS.QClass.IN); var ans = es.Answers.OfType <Heijden.DNS.RecordSOA>(); return(ans.ToList()); }
public static Heijden.DNS.Resolver Clone(this Heijden.DNS.Resolver resolver) { return(new Heijden.DNS.Resolver(resolver.DnsServers) { TimeOut = resolver.TimeOut, Recursion = resolver.Recursion, Retries = resolver.Retries, TransportType = resolver.TransportType, UseCache = resolver.UseCache, }); }
/// <summary> /// Checks if a domain exists in the DNS server's cache /// </summary> /// <params> /// <param name="dnsIp">DNS server's IP address</param> /// <param name="query">Query to be executed</param> /// </params> /// <returns>True if it exists</returns> private bool ExistsInDnsServerCache(string dnsIp, string query) { var r = new Heijden.DNS.Resolver(dnsIp) { Recursion = false }; if (r.Query(query, Heijden.DNS.QType.A, Heijden.DNS.QClass.IN).Answers.Count > 0) { Found?.Invoke(query, null); return(true); } return(false); }
/// <summary> /// Returns the DNS servers list of a domain /// </summary> /// <param name="domain"></param> /// <returns></returns> public static List <string> GetDnsList(string domain) { var r = new Heijden.DNS.Resolver("8.8.8.8"); var servers = new List <string>(); var respuesta = r.Query(domain, Heijden.DNS.QType.NS); int nDnSs = respuesta.Answers.Count; for (var i = 0; i < nDnSs; i++) { servers.Add(r.Query(domain, Heijden.DNS.QType.NS).Answers[i].RECORD.ToString().Trim('.')); } return(servers); }
/// <summary> /// Perform a DNS lookup for a Minecraft Service using the specified domain name /// </summary> /// <param name="domain">Input domain name, updated with target host if any, else left untouched</param> /// <param name="port">Updated with target port if any, else left untouched</param> /// <returns>TRUE if a Minecraft Service was found.</returns> public static bool MinecraftServiceLookup(ref string domain, ref ushort port) { bool foundService = false; string domainVal = domain; ushort portVal = port; if (!String.IsNullOrEmpty(domain) && domain.Any(c => char.IsLetter(c))) { AutoTimeout.Perform(() => { try { Translations.WriteLine("mcc.resolve", domainVal); Heijden.DNS.Response response = new Heijden.DNS.Resolver().Query("_minecraft._tcp." + domainVal, Heijden.DNS.QType.SRV); Heijden.DNS.RecordSRV[] srvRecords = response.RecordsSRV; if (srvRecords != null && srvRecords.Any()) { //Order SRV records by priority and weight, then randomly Heijden.DNS.RecordSRV result = srvRecords .OrderBy(record => record.PRIORITY) .ThenByDescending(record => record.WEIGHT) .ThenBy(record => Guid.NewGuid()) .First(); string target = result.TARGET.Trim('.'); ConsoleIO.WriteLineFormatted(Translations.Get("mcc.found", target, result.PORT, domainVal)); domainVal = target; portVal = result.PORT; foundService = true; } } catch (Exception e) { ConsoleIO.WriteLineFormatted(Translations.Get("mcc.not_found", domainVal, e.GetType().FullName, e.Message)); } }, TimeSpan.FromSeconds(Settings.ResolveSrvRecordsShortTimeout ? 10 : 30)); } domain = domainVal; port = portVal; return(foundService); }
public override void GetVersion() { try { System.Net.IPAddress[] ips = System.Net.Dns.GetHostAddresses(Host); if (ips.Length == 0) { return; } Heijden.DNS.Resolver r = new Heijden.DNS.Resolver(ips[0], base.Port); r.TimeOut = 10; Heijden.DNS.Response response = r.Query("version.bind", Heijden.DNS.QType.TXT, Heijden.DNS.QClass.CH); if (response.RecordsTXT.Length > 0) { OperatingSystem.OS os = OperatingSystem.OS.Unknown; Version = response.RecordsTXT.SelectMany(p => p.TXT.Where(q => !String.IsNullOrEmpty(q))) .FirstOrDefault(p => { os = AnalyzeBanner(p); return(os != OperatingSystem.OS.Unknown); } ); this.os = os; } if (this.FingerPrintingFinished != null) { FingerPrintingFinished(this, null); } } catch { if (FingerPrintingError != null) { FingerPrintingError(this, null); } } }