fix: [DomClassifier] fix redis cache

This commit is contained in:
terrtia 2024-01-15 15:14:46 +01:00
parent 6c9d8b5350
commit 1aa700642e
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0

View file

@ -217,45 +217,45 @@ class Extract:
self.vdomain.append(out) self.vdomain.append(out)
else: else:
self.vdomain.add(out) self.vdomain.add(out)
else: continue
for dnstype in rtype: for dnstype in rtype:
try: try:
answers = self.presolver.query(domain, dnstype) answers = self.presolver.query(domain, dnstype)
except: except:
pass pass
else: else:
# Passive DNS output # Passive DNS output
# timestamp||dns-client ||dns-server||RR class||Query||Query Type||Answer||TTL||Count # timestamp||dns-client ||dns-server||RR class||Query||Query Type||Answer||TTL||Count
if passive_dns: if passive_dns:
rrset = answers.rrset.to_text().splitlines() rrset = answers.rrset.to_text().splitlines()
for dns_resp in rrset: for dns_resp in rrset:
dns_resp = dns_resp.split() dns_resp = dns_resp.split()
passive_dns_out = ( passive_dns_out = (
'{}||127.0.0.1||{}||{}||{}||{}||{}||{}||1\n'.format( '{}||127.0.0.1||{}||{}||{}||{}||{}||{}||1\n'.format(
time.time(), time.time(),
self.presolver.nameservers[0], self.presolver.nameservers[0],
dns_resp[2], dns_resp[2],
domain, domain,
dnstype, dnstype,
dns_resp[4], dns_resp[4],
answers.ttl, answers.ttl,
)
) )
self.vdomain.add((passive_dns_out)) )
if self.redis: self.vdomain.add((passive_dns_out))
self.redis.sadd('dom_class:cache:{}'.format(domain), passive_dns_out)
self.redis.expire('dom_class:cache:{}'.format(domain), self.expire_time)
elif extended:
self.vdomain.append((domain, dnstype, answers[0]))
if self.redis: if self.redis:
self.redis.sadd('dom_class:cache:{}'.format(domain), '{}[^]{}[^]{}'.format(domain, dnstype, answers[0])) self.redis.sadd('dom_class:cache:{}'.format(domain), passive_dns_out)
self.redis.expire('dom_class:cache:{}'.format(domain), self.expire_time)
else:
self.vdomain.add((domain))
if self.redis:
self.redis.sadd('dom_class:cache:{}'.format(domain), domain)
self.redis.expire('dom_class:cache:{}'.format(domain), self.expire_time) self.redis.expire('dom_class:cache:{}'.format(domain), self.expire_time)
elif extended:
self.vdomain.append((domain, dnstype, answers[0]))
if self.redis:
self.redis.sadd('dom_class:cache:{}'.format(domain), '{}[^]{}[^]{}'.format(domain, dnstype, answers[0]))
self.redis.expire('dom_class:cache:{}'.format(domain), self.expire_time)
else:
self.vdomain.add((domain))
if self.redis:
self.redis.sadd('dom_class:cache:{}'.format(domain), domain)
self.redis.expire('dom_class:cache:{}'.format(domain), self.expire_time)
return self.vdomain return self.vdomain
"""ipaddress method extracts from the domain list the valid IPv4 addresses""" """ipaddress method extracts from the domain list the valid IPv4 addresses"""