下午好,
我正在进行一项网络发现工作,需要获取域的所有记录。当我使用DNSJava时,它不是完整的集合。CNAME不存在,也不是所有TXT记录,或A记录。
有什么更好的办法吗?
这是我的密码:
package iMCDNS;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import org.xbill.DNS.Lookup;
import org.xbill.DNS.Record;
import org.xbill.DNS.Type;
public class iMCDNS {
public static void main(String[] args) {
System.out.println("Running iMCDNS");
try {
//this returned no records
// DirContext ctx = new InitialDirContext(env);
// Attributes atts = ctx.getAttributes("iditsecurity.com", new String[] {"CNAME"});
//
// System.out.println("Attributes size: " + atts.size());
//
// NamingEnumeration<? extends Attribute> e = atts.getAll();
//
//
// while(e.hasMore()) {
// System.out.println(e.next().get());
// }
//this also returns no CNAME records
Record[] rs = new Lookup("iditsecurity.com", Type.ANY).run();
if (rs!=null)
{
int javaDNSLen = rs.length;
for (int i = 0;i < javaDNSLen; i++)
{
System.out.println("record: " + rs[i].toString());
}
} else {
System.out.println("No records found");
}
} catch (Exception ex) {
System.out.println("Exception occurred: " + ex.toString());
}
}
}结果表明:应有2条A记录,4条CNAME和5条TXT记录.
Running iMCDNS
record: iditsecurity.com. 4503 IN TXT "google-site-verification=VvXfVc-hr0dK3pzjc3yiAaDsK-tlFAMX7Xt3soYXByc"
record: iditsecurity.com. 4503 IN TXT "google-site-verification=8W17El_6uLvJ0WLxEsgIKt9hKRPuz6yN9U_ke9l0i7E"
record: iditsecurity.com. 4360 IN MX 10 mx1.netsolmail.net.发布于 2018-11-13 22:42:11
首先,您应该更精确地定义“获取域的所有记录”。另外,如果您位于某个区域的顶点,则不可能有CNAME记录,因为它们不能与任何其他记录共存,而顶点通过设计已经拥有NS和SOA记录。
其次,不要使用ANY类型来执行DNS查询。不管出于什么原因,这被理解为ALL,但是它根本没有这个语义,也不会产生您期望的结果。对于递归缓存名称服务器的ANY将使您返回解析器缓存中的当前记录列表,即而不是与域相关的所有记录。实际上,要完全放弃这种(虚拟)类型,请参阅:https://datatracker.ietf.org/doc/draft-ietf-dnsop-refuse-any/ (以及在https://nelsonslog.wordpress.com/2016/09/07/dns-any-requests-are-deprecated/或https://blog.cloudflare.com/what-happened-next-the-deprecation-of-any/中用非技术术语进行的更多解释)。
所以你会问:这很好,但是怎么做呢?
然后循环回到第一点。您需要使用所需的记录类型(A、AAAA、TXT等)进行定义。然后对它们进行循环取回它们。它并不总是那么简单,至少有两个原因:* TXT正在成为当今的一种捕获和传输很多东西: SPF、DKIM、DMARC等等。特别是对于DKIM或SRV都是一样的,实际上,您需要查询具有特定结构的域(比如SRV的_service._transport.example.com ),这样您就不能“自动发现”所有记录,您需要知道您需要哪个记录(或以列表开始测试)。
我还建议您指定您正在使用的名称服务器,因为如果它是递归的,您将从它的缓存中获得结果,而关联的TTL可能是您想要的,也可能不是您所需要的。因此,您可以更好地查询域的(一个)权威名称服务器。
https://stackoverflow.com/questions/53286891
复制相似问题