diff --git a/dns.py b/dns.py index c579bf3..8efb94f 100644 --- a/dns.py +++ b/dns.py @@ -42,6 +42,7 @@ class Dns(Base): """Log table for DNS entries.""" __tablename__ = "dns" id = Column(Integer, primary_key=True) + transport = Column(String) src = Column(String) src_port = Column(Integer) dns_name = Column(String) @@ -63,8 +64,14 @@ class HoneyDNSServerFactory(server.DNSServerFactory): def messageReceived(self, message, proto, address=None): # Log info. entry = {} - entry["src_ip"] = address[0] - entry["src_port"] = address[1] + if address != None: + entry["transport"] = "UDP" + entry["src_ip"] = address[0] + entry["src_port"] = address[1] + else: + entry["transport"] = "TCP" + entry["src_ip"] = proto.transport.getPeer().host + entry["src_port"] = proto.transport.getPeer().port entry["dns_name"] = message.queries[0].name.name entry["dns_type"] = dns.QUERY_TYPES.get(message.queries[0].type, dns.EXT_QUERIES.get(message.queries[0].type, "UNKNOWN (%d)" % message.queries[0].type)) entry["dns_cls"] = dns.QUERY_CLASSES.get(message.queries[0].cls, "UNKNOWN (%d)" % message.queries[0].cls) @@ -87,7 +94,7 @@ def messageReceived(self, message, proto, address=None): def log(self, data): if opts.verbose: print(data) - record = Dns(src=data["src_ip"], src_port=data["src_port"], dns_name=data["dns_name"], dns_type=data["dns_type"], dns_cls=data["dns_cls"]) + record = Dns(transport=data["transport"], src=data["src_ip"], src_port=data["src_port"], dns_name=data["dns_name"], dns_type=data["dns_type"], dns_cls=data["dns_cls"]) session.add(record) session.commit() diff --git a/requirements.txt b/requirements.txt index 7901b29..cbf362e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ SQLAlchemy==1.4.35 Twisted==23.10.0 -