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-05-04 14:35:56 +00:00
|
|
|
from lib.objects import ail_objects
|
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
|
2023-05-04 14:35:56 +00:00
|
|
|
self.tracked_typosquattings = Tracker.get_tracked_typosquatting()
|
|
|
|
self.last_refresh_typosquatting = time.time()
|
2022-06-07 14:18:52 +00:00
|
|
|
|
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")
|
|
|
|
|
2023-06-22 13:38:04 +00:00
|
|
|
def compute(self, message):
|
2022-06-07 14:18:52 +00:00
|
|
|
# refresh Tracked typo
|
2023-05-04 14:35:56 +00:00
|
|
|
if self.last_refresh_typosquatting < Tracker.get_tracker_last_updated_by_type('typosquatting'):
|
|
|
|
self.tracked_typosquattings = Tracker.get_tracked_typosquatting()
|
|
|
|
self.last_refresh_typosquatting = time.time()
|
2022-06-07 14:18:52 +00:00
|
|
|
self.redis_logger.debug('Tracked typosquatting refreshed')
|
|
|
|
print('Tracked typosquatting refreshed')
|
|
|
|
|
2023-06-22 13:38:04 +00:00
|
|
|
host = message
|
|
|
|
obj = self.get_obj()
|
2023-05-04 14:35:56 +00:00
|
|
|
obj_type = obj.get_type()
|
2022-07-08 08:55:19 +00:00
|
|
|
|
2023-05-04 14:35:56 +00:00
|
|
|
# Object Filter
|
|
|
|
if obj_type not in self.tracked_typosquattings:
|
|
|
|
return None
|
2022-06-07 14:18:52 +00:00
|
|
|
|
2023-05-04 14:35:56 +00:00
|
|
|
for typo in self.tracked_typosquattings[obj_type]:
|
|
|
|
if host in typo['domains']:
|
|
|
|
self.new_tracker_found(typo['tracked'], 'typosquatting', obj)
|
2022-07-08 08:55:19 +00:00
|
|
|
|
2023-05-04 14:35:56 +00:00
|
|
|
def new_tracker_found(self, tracked, tracker_type, obj):
|
|
|
|
obj_id = obj.get_id()
|
|
|
|
for tracker_uuid in Tracker.get_trackers_by_tracked_obj_type(tracker_type, obj.get_type(), tracked):
|
2023-03-16 15:49:53 +00:00
|
|
|
tracker = Tracker.Tracker(tracker_uuid)
|
|
|
|
|
2023-05-04 14:35:56 +00:00
|
|
|
# Filter Object
|
|
|
|
filters = tracker.get_filters()
|
|
|
|
if ail_objects.is_filtered(obj, filters):
|
2022-07-08 08:55:19 +00:00
|
|
|
continue
|
|
|
|
|
2024-03-13 10:58:40 +00:00
|
|
|
print(f'new tracked typosquatting found: {tracked} in {self.obj.get_global_id()}')
|
|
|
|
self.redis_logger.warning(f'tracker typosquatting: {tracked} in {self.obj.get_global_id()}')
|
2022-07-08 08:55:19 +00:00
|
|
|
|
2023-05-11 14:21:43 +00:00
|
|
|
tracker.add(obj.get_type(), obj.get_subtype(r_str=True), obj_id)
|
2023-05-04 14:35:56 +00:00
|
|
|
|
|
|
|
# Tags
|
2023-03-16 15:49:53 +00:00
|
|
|
for tag in tracker.get_tags():
|
2023-05-04 14:35:56 +00:00
|
|
|
if obj.get_type() == 'item':
|
|
|
|
msg = f'{tag};{obj_id}'
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2023-05-04 14:35:56 +00:00
|
|
|
else:
|
|
|
|
obj.add_tag(tag)
|
2022-07-08 08:55:19 +00:00
|
|
|
|
2023-03-16 15:49:53 +00:00
|
|
|
if tracker.mail_export():
|
2023-05-04 14:35:56 +00:00
|
|
|
self.exporters['mail'].export(tracker, obj)
|
2022-06-07 14:18:52 +00:00
|
|
|
|
2023-03-16 15:49:53 +00:00
|
|
|
if tracker.webhook_export():
|
2023-05-04 14:35:56 +00:00
|
|
|
self.exporters['webhook'].export(tracker, obj)
|
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()
|
2023-05-04 14:35:56 +00:00
|
|
|
# module.compute('g00gle.com tests/2020/01/01/test.gz')
|