2022-05-30 07:15:50 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
"""
|
|
|
|
The Hosts Module
|
|
|
|
======================
|
|
|
|
|
|
|
|
This module is consuming the Redis-list created by the Global module.
|
|
|
|
|
|
|
|
It is looking for Hosts
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
##################################
|
|
|
|
# Import External packages
|
|
|
|
##################################
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
|
|
|
from modules.abstract_module import AbstractModule
|
|
|
|
from lib.ConfigLoader import ConfigLoader
|
2022-10-25 14:25:19 +00:00
|
|
|
from lib.objects.Items import Item
|
2022-05-30 07:15:50 +00:00
|
|
|
|
|
|
|
class Hosts(AbstractModule):
|
|
|
|
"""
|
|
|
|
Hosts module for AIL framework
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super(Hosts, self).__init__()
|
|
|
|
|
|
|
|
config_loader = ConfigLoader()
|
|
|
|
self.r_cache = config_loader.get_redis_conn("Redis_Cache")
|
|
|
|
|
|
|
|
# regex timeout
|
|
|
|
self.regex_timeout = 30
|
|
|
|
|
2022-10-25 14:25:19 +00:00
|
|
|
# Waiting time in seconds between to message processed
|
2022-05-30 07:15:50 +00:00
|
|
|
self.pending_seconds = 1
|
|
|
|
|
|
|
|
self.host_regex = r'\b([a-zA-Z\d-]{,63}(?:\.[a-zA-Z\d-]{,63})+)\b'
|
|
|
|
re.compile(self.host_regex)
|
|
|
|
|
2023-05-12 13:29:53 +00:00
|
|
|
self.logger.info(f"Module: {self.module_name} Launched")
|
2022-05-30 07:15:50 +00:00
|
|
|
|
|
|
|
def compute(self, message):
|
2023-06-22 13:38:04 +00:00
|
|
|
item = self.get_obj()
|
2022-05-30 07:15:50 +00:00
|
|
|
|
|
|
|
# mimetype = item_basic.get_item_mimetype(item.get_id())
|
|
|
|
# if mimetype.split('/')[0] == "text":
|
|
|
|
|
|
|
|
content = item.get_content()
|
2024-01-09 11:15:40 +00:00
|
|
|
hosts = self.regex_findall(self.host_regex, item.get_id(), content, r_set=True)
|
2022-07-08 07:47:47 +00:00
|
|
|
if hosts:
|
|
|
|
print(f'{len(hosts)} host {item.get_id()}')
|
|
|
|
for host in hosts:
|
2022-10-25 14:25:19 +00:00
|
|
|
# print(host)
|
2024-01-09 13:31:55 +00:00
|
|
|
if not host.endswith('.onion'):
|
|
|
|
self.add_message_to_queue(message=str(host), queue='Host')
|
2022-05-30 07:15:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
module = Hosts()
|
|
|
|
module.run()
|