2018-05-04 11:53:29 +00:00
|
|
|
#!/usr/bin/env python3
|
2014-09-05 08:41:00 +00:00
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
"""
|
|
|
|
The DomClassifier Module
|
|
|
|
============================
|
|
|
|
|
2018-04-16 12:50:04 +00:00
|
|
|
The DomClassifier modules extract and classify Internet domains/hostnames/IP addresses from
|
2017-05-09 09:13:16 +00:00
|
|
|
the out output of the Global module.
|
2014-09-05 08:41:00 +00:00
|
|
|
|
|
|
|
"""
|
2021-04-28 13:24:33 +00:00
|
|
|
|
|
|
|
##################################
|
|
|
|
# Import External packages
|
|
|
|
##################################
|
2021-03-31 09:25:09 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2014-09-05 08:41:00 +00:00
|
|
|
import DomainClassifier.domainclassifier
|
2021-04-28 13:24:33 +00:00
|
|
|
|
2021-06-02 12:42:23 +00:00
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
2021-04-28 13:24:33 +00:00
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
2021-06-02 12:42:23 +00:00
|
|
|
from modules.abstract_module import AbstractModule
|
2022-10-25 14:25:19 +00:00
|
|
|
from lib.objects.Items import Item
|
2023-04-13 12:25:02 +00:00
|
|
|
from lib.ConfigLoader import ConfigLoader
|
2022-10-25 14:25:19 +00:00
|
|
|
from lib import d4
|
2021-03-31 09:25:09 +00:00
|
|
|
|
2014-09-05 08:41:00 +00:00
|
|
|
|
2021-04-28 13:24:33 +00:00
|
|
|
class DomClassifier(AbstractModule):
|
|
|
|
"""
|
|
|
|
DomClassifier module for AIL framework
|
|
|
|
"""
|
2014-09-05 08:41:00 +00:00
|
|
|
|
2021-04-28 13:24:33 +00:00
|
|
|
def __init__(self):
|
|
|
|
super(DomClassifier, self).__init__()
|
2014-09-05 08:41:00 +00:00
|
|
|
|
2023-04-13 12:25:02 +00:00
|
|
|
config_loader = ConfigLoader()
|
|
|
|
|
2022-10-25 14:25:19 +00:00
|
|
|
# Waiting time in seconds between to message processed
|
2021-04-28 13:24:33 +00:00
|
|
|
self.pending_seconds = 1
|
2014-09-05 08:41:00 +00:00
|
|
|
|
2023-04-13 12:25:02 +00:00
|
|
|
addr_dns = config_loader.get_config_str("DomClassifier", "dns")
|
2014-09-05 08:41:00 +00:00
|
|
|
|
2021-04-28 13:24:33 +00:00
|
|
|
self.c = DomainClassifier.domainclassifier.Extract(rawtext="", nameservers=[addr_dns])
|
2014-09-17 15:19:03 +00:00
|
|
|
|
2023-04-13 12:25:02 +00:00
|
|
|
self.cc = config_loader.get_config_str("DomClassifier", "cc")
|
|
|
|
self.cc_tld = config_loader.get_config_str("DomClassifier", "cc_tld")
|
2014-09-05 08:41:00 +00:00
|
|
|
|
2021-04-28 13:24:33 +00:00
|
|
|
# Send module state to logs
|
2023-05-12 13:29:53 +00:00
|
|
|
self.logger.info(f"Module: {self.module_name} Launched")
|
2021-05-27 15:28:20 +00:00
|
|
|
|
|
|
|
def compute(self, message, r_result=False):
|
2023-06-22 13:38:04 +00:00
|
|
|
host = message
|
2021-04-28 13:24:33 +00:00
|
|
|
|
2023-06-22 13:38:04 +00:00
|
|
|
item = self.get_obj()
|
2021-05-27 15:28:20 +00:00
|
|
|
item_basename = item.get_basename()
|
|
|
|
item_date = item.get_date()
|
|
|
|
item_source = item.get_source()
|
2021-04-28 13:24:33 +00:00
|
|
|
try:
|
2022-05-30 07:03:27 +00:00
|
|
|
|
|
|
|
self.c.text(rawtext=host)
|
|
|
|
print(self.c.domain)
|
2024-01-09 10:24:54 +00:00
|
|
|
if not self.c.domain:
|
|
|
|
return
|
2022-05-30 07:03:27 +00:00
|
|
|
self.c.validdomain(passive_dns=True, extended=False)
|
2023-05-12 13:29:53 +00:00
|
|
|
# self.logger.debug(self.c.vdomain)
|
2022-05-30 07:03:27 +00:00
|
|
|
|
|
|
|
print(self.c.vdomain)
|
|
|
|
print()
|
|
|
|
|
|
|
|
if self.c.vdomain and d4.is_passive_dns_enabled():
|
|
|
|
for dns_record in self.c.vdomain:
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(obj=None, message=dns_record)
|
2022-05-30 07:03:27 +00:00
|
|
|
|
|
|
|
localizeddomains = self.c.include(expression=self.cc_tld)
|
|
|
|
if localizeddomains:
|
|
|
|
print(localizeddomains)
|
|
|
|
self.redis_logger.warning(f"DomainC;{item_source};{item_date};{item_basename};Checked {localizeddomains} located in {self.cc_tld};{item.get_id()}")
|
|
|
|
|
|
|
|
localizeddomains = self.c.localizedomain(cc=self.cc)
|
|
|
|
if localizeddomains:
|
|
|
|
print(localizeddomains)
|
|
|
|
self.redis_logger.warning(f"DomainC;{item_source};{item_date};{item_basename};Checked {localizeddomains} located in {self.cc};{item.get_id()}")
|
|
|
|
|
|
|
|
if r_result:
|
|
|
|
return self.c.vdomain
|
2021-04-28 13:24:33 +00:00
|
|
|
|
|
|
|
except IOError as err:
|
|
|
|
self.redis_logger.error(f"Duplicate;{item_source};{item_date};{item_basename};CRC Checksum Failed")
|
2021-05-27 15:28:20 +00:00
|
|
|
raise Exception(f"CRC Checksum Failed on: {item.get_id()}")
|
2021-03-31 09:25:09 +00:00
|
|
|
|
2014-09-05 08:41:00 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-04-28 13:24:33 +00:00
|
|
|
module = DomClassifier()
|
|
|
|
module.run()
|