2018-05-04 11:53:29 +00:00
|
|
|
#!/usr/bin/env python3
|
2016-06-30 12:38:28 +00:00
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
"""
|
2017-05-09 09:13:16 +00:00
|
|
|
The CVE Module
|
|
|
|
======================
|
|
|
|
|
|
|
|
This module is consuming the Redis-list created by the Categ module.
|
|
|
|
|
|
|
|
It apply CVE regexes on paste content and warn if a reference to a CVE is spotted.
|
|
|
|
|
2016-06-30 12:38:28 +00:00
|
|
|
"""
|
|
|
|
|
2021-09-08 08:32:47 +00:00
|
|
|
##################################
|
|
|
|
# Import External packages
|
|
|
|
##################################
|
2022-09-20 14:11:48 +00:00
|
|
|
import os
|
2016-06-30 12:38:28 +00:00
|
|
|
import re
|
2022-09-20 14:11:48 +00:00
|
|
|
import sys
|
2021-09-08 08:32:47 +00:00
|
|
|
|
2022-09-20 14:11:48 +00:00
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
2021-09-08 08:32:47 +00:00
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
|
|
|
from modules.abstract_module import AbstractModule
|
2022-10-25 14:25:19 +00:00
|
|
|
from lib.objects import Cves
|
2022-09-20 14:11:48 +00:00
|
|
|
from lib.objects.Items import Item
|
2016-06-30 12:38:28 +00:00
|
|
|
|
|
|
|
|
2022-12-19 15:38:20 +00:00
|
|
|
class CveModule(AbstractModule):
|
2021-09-08 08:32:47 +00:00
|
|
|
"""
|
2022-12-19 15:38:20 +00:00
|
|
|
CveModule for AIL framework
|
2021-09-08 08:32:47 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
2022-12-19 15:38:20 +00:00
|
|
|
super(CveModule, self).__init__()
|
2021-09-08 08:32:47 +00:00
|
|
|
|
|
|
|
# regex to find CVE
|
2022-09-20 14:11:48 +00:00
|
|
|
self.reg_cve = re.compile(r'CVE-[1-2]\d{1,4}-\d{1,5}')
|
2021-09-08 08:32:47 +00:00
|
|
|
|
2022-10-25 14:25:19 +00:00
|
|
|
# Waiting time in seconds between to message processed
|
2021-09-08 08:32:47 +00:00
|
|
|
self.pending_seconds = 1
|
|
|
|
|
|
|
|
# Send module state to logs
|
2023-05-12 13:29:53 +00:00
|
|
|
self.logger.info(f'Module {self.module_name} initialized')
|
2021-09-08 08:32:47 +00:00
|
|
|
|
|
|
|
def compute(self, message):
|
|
|
|
|
2022-09-20 14:11:48 +00:00
|
|
|
item_id, count = message.split()
|
|
|
|
item = Item(item_id)
|
|
|
|
item_id = item.get_id()
|
2021-09-08 08:32:47 +00:00
|
|
|
|
2022-09-20 14:11:48 +00:00
|
|
|
cves = self.regex_findall(self.reg_cve, item_id, item.get_content())
|
|
|
|
if cves:
|
2022-12-21 13:20:13 +00:00
|
|
|
# print(cves)
|
2022-10-25 14:25:19 +00:00
|
|
|
date = item.get_date()
|
|
|
|
for cve_id in cves:
|
|
|
|
cve = Cves.Cve(cve_id)
|
|
|
|
cve.add(date, item_id)
|
|
|
|
|
2022-09-20 14:11:48 +00:00
|
|
|
warning = f'{item_id} contains CVEs {cves}'
|
2021-09-08 08:32:47 +00:00
|
|
|
print(warning)
|
|
|
|
self.redis_logger.warning(warning)
|
2022-10-25 14:25:19 +00:00
|
|
|
|
2022-09-20 14:11:48 +00:00
|
|
|
msg = f'infoleak:automatic-detection="cve";{item_id}'
|
2021-09-08 08:32:47 +00:00
|
|
|
# Send to Tags Queue
|
2023-04-13 12:25:02 +00:00
|
|
|
self.add_message_to_queue(msg, 'Tags')
|
2022-09-20 14:11:48 +00:00
|
|
|
|
|
|
|
|
2016-06-30 12:38:28 +00:00
|
|
|
if __name__ == '__main__':
|
2021-09-08 08:32:47 +00:00
|
|
|
|
2022-12-19 15:38:20 +00:00
|
|
|
module = CveModule()
|
2023-04-04 12:12:23 +00:00
|
|
|
module.run()
|