2021-03-31 11:25:09 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
"""
|
|
|
|
The D4_Client Module
|
|
|
|
============================
|
|
|
|
|
|
|
|
The D4_Client modules send all DNS records to a D4 Server.
|
|
|
|
Data produced by D4 sensors are ingested into
|
|
|
|
a Passive DNS server which can be queried later to search for the Passive DNS records.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
2022-11-28 15:44:26 +01:00
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
#################################
|
|
|
|
from modules.abstract_module import AbstractModule
|
|
|
|
from lib import d4
|
2021-03-31 11:25:09 +02:00
|
|
|
|
2022-11-28 15:44:26 +01:00
|
|
|
# # TODO: launch me in core screen
|
2021-03-31 11:25:09 +02:00
|
|
|
# # TODO: check if already launched in core screen
|
|
|
|
|
2022-11-28 15:44:26 +01:00
|
|
|
class D4Client(AbstractModule):
|
|
|
|
"""
|
|
|
|
D4Client module for AIL framework
|
|
|
|
"""
|
2021-03-31 11:25:09 +02:00
|
|
|
|
2022-11-28 15:44:26 +01:00
|
|
|
def __init__(self):
|
|
|
|
super(D4Client, self).__init__()
|
2021-03-31 11:25:09 +02:00
|
|
|
|
2022-11-28 15:44:26 +01:00
|
|
|
self.d4_client = d4.create_d4_client()
|
|
|
|
self.last_refresh = time.time()
|
2024-01-30 14:31:09 +01:00
|
|
|
self.last_config_check = time.time()
|
2021-03-31 11:25:09 +02:00
|
|
|
|
2022-11-28 15:44:26 +01:00
|
|
|
# Send module state to logs
|
2023-05-12 15:29:53 +02:00
|
|
|
self.logger.info(f'Module {self.module_name} initialized')
|
2021-03-31 11:25:09 +02:00
|
|
|
|
2022-11-28 15:44:26 +01:00
|
|
|
def compute(self, dns_record):
|
|
|
|
# Refresh D4 Client
|
2024-01-30 14:31:09 +01:00
|
|
|
if self.last_config_check < int(time.time()) - 30:
|
|
|
|
print('refresh rrrr')
|
|
|
|
if self.last_refresh < d4.get_config_last_update_time():
|
|
|
|
self.d4_client = d4.create_d4_client()
|
|
|
|
self.last_refresh = time.time()
|
|
|
|
print('D4 Client: config updated')
|
|
|
|
self.last_config_check = time.time()
|
2021-03-31 11:25:09 +02:00
|
|
|
|
2022-11-28 15:44:26 +01:00
|
|
|
if self.d4_client:
|
2021-03-31 11:25:09 +02:00
|
|
|
# Send DNS Record to D4Server
|
2022-11-28 15:44:26 +01:00
|
|
|
self.d4_client.send_manual_data(dns_record)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
module = D4Client()
|
|
|
|
module.run()
|