ail-framework/bin/trackers/Tracker_Typo_Squatting.py

95 lines
3 KiB
Python
Raw Normal View History

2022-06-07 14:18:52 +00:00
#!/usr/bin/env python3
# -*-coding:UTF-8 -*
2022-07-08 08:55:19 +00:00
2022-06-07 14:18:52 +00:00
"""
2022-06-15 13:28:34 +00:00
The Tracker_Typo_Squatting Module
2022-06-07 14:18:52 +00:00
===================
"""
##################################
# Import External packages
##################################
import os
import sys
import time
sys.path.append(os.environ['AIL_BIN'])
##################################
# Import Project packages
##################################
from modules.abstract_module import AbstractModule
2023-03-16 15:49:53 +00:00
from lib.objects.Items import Item
2022-06-07 14:18:52 +00:00
from lib import Tracker
2023-03-16 15:49:53 +00:00
from exporter.MailExporter import MailExporterTracker
from exporter.WebHookExporter import WebHookExporterTracker
2022-06-15 13:28:34 +00:00
class Tracker_Typo_Squatting(AbstractModule):
2022-06-07 14:18:52 +00:00
"""
2022-06-15 13:28:34 +00:00
Tracker_Typo_Squatting module for AIL framework
2022-06-07 14:18:52 +00:00
"""
def __init__(self):
2022-06-15 13:28:34 +00:00
super(Tracker_Typo_Squatting, self).__init__()
2022-06-07 14:18:52 +00:00
self.pending_seconds = 5
2023-03-16 15:49:53 +00:00
# Refresh typo squatting
2022-06-07 14:18:52 +00:00
self.typosquat_tracked_words_list = Tracker.get_typosquatting_tracked_words_list()
self.last_refresh_typosquat = time.time()
2023-03-16 15:49:53 +00:00
# Exporter
self.exporters = {'mail': MailExporterTracker(),
'webhook': WebHookExporterTracker()}
2022-06-07 14:18:52 +00:00
self.redis_logger.info(f"Module: {self.module_name} Launched")
def compute(self, message):
# refresh Tracked typo
2022-07-08 08:55:19 +00:00
if self.last_refresh_typosquat < Tracker.get_tracker_last_updated_by_type('typosquatting'):
2022-06-07 14:18:52 +00:00
self.typosquat_tracked_words_list = Tracker.get_typosquatting_tracked_words_list()
self.last_refresh_typosquat = time.time()
self.redis_logger.debug('Tracked typosquatting refreshed')
print('Tracked typosquatting refreshed')
2023-03-16 15:49:53 +00:00
host, item_id = message.split()
2022-07-08 08:55:19 +00:00
2022-06-07 14:18:52 +00:00
# Cast message as Item
2022-07-08 09:27:04 +00:00
for tracker in self.typosquat_tracked_words_list:
if host in self.typosquat_tracked_words_list[tracker]:
2023-03-16 15:49:53 +00:00
item = Item(item_id)
2022-07-08 09:27:04 +00:00
self.new_tracker_found(tracker, 'typosquatting', item)
2022-06-07 14:18:52 +00:00
2022-07-08 08:55:19 +00:00
def new_tracker_found(self, tracker, tracker_type, item):
2022-06-07 14:18:52 +00:00
item_id = item.get_id()
item_source = item.get_source()
2022-07-08 08:55:19 +00:00
print(f'new tracked typosquatting found: {tracker} in {item_id}')
2022-09-09 09:25:51 +00:00
self.redis_logger.warning(f'tracker typosquatting: {tracker} in {item_id}')
2022-07-08 08:55:19 +00:00
for tracker_uuid in Tracker.get_tracker_uuid_list(tracker, tracker_type):
2023-03-16 15:49:53 +00:00
tracker = Tracker.Tracker(tracker_uuid)
2022-07-08 08:55:19 +00:00
# Source Filtering
2023-03-16 15:49:53 +00:00
tracker_sources = tracker.get_sources()
2022-07-08 08:55:19 +00:00
if tracker_sources and item_source not in tracker_sources:
continue
Tracker.add_tracked_item(tracker_uuid, item_id)
2023-03-16 15:49:53 +00:00
for tag in tracker.get_tags():
2022-07-08 08:55:19 +00:00
msg = f'{tag};{item_id}'
self.add_message_to_queue(msg, 'Tags')
2022-07-08 08:55:19 +00:00
2023-03-16 15:49:53 +00:00
if tracker.mail_export():
self.exporters['mail'].export(tracker, item)
2022-06-07 14:18:52 +00:00
2023-03-16 15:49:53 +00:00
if tracker.webhook_export():
self.exporters['webhook'].export(tracker, item)
2022-06-07 14:18:52 +00:00
if __name__ == '__main__':
2022-06-15 13:28:34 +00:00
module = Tracker_Typo_Squatting()
2022-06-07 14:18:52 +00:00
module.run()
2022-07-08 08:55:19 +00:00
#module.compute('g00gle.com tests/2020/01/01/test.gz')