2018-05-04 11:53:29 +00:00
|
|
|
#!/usr/bin/env python3
|
2016-02-05 15:03:37 +00:00
|
|
|
# -*-coding:UTF-8 -*
|
2017-05-09 09:13:16 +00:00
|
|
|
|
2016-02-05 15:03:37 +00:00
|
|
|
"""
|
2017-05-09 09:13:16 +00:00
|
|
|
The Keys Module
|
|
|
|
======================
|
|
|
|
|
|
|
|
This module is consuming the Redis-list created by the Global module.
|
|
|
|
|
2018-04-05 09:40:34 +00:00
|
|
|
It is looking for PGP, private and encrypted private,
|
|
|
|
RSA private key, certificate messages
|
2017-05-09 09:13:16 +00:00
|
|
|
|
2016-02-05 15:03:37 +00:00
|
|
|
"""
|
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
##################################
|
|
|
|
# Import External packages
|
|
|
|
##################################
|
2021-06-02 12:42:23 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2021-04-02 07:52:05 +00:00
|
|
|
from enum import Enum
|
2018-04-16 12:50:04 +00:00
|
|
|
|
2021-06-02 12:42:23 +00:00
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
2021-04-02 07:52:05 +00:00
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
2021-06-02 12:42:23 +00:00
|
|
|
from modules.abstract_module import AbstractModule
|
2022-10-25 14:25:19 +00:00
|
|
|
from lib.objects.Items import Item
|
2016-02-05 15:03:37 +00:00
|
|
|
|
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
class KeyEnum(Enum):
|
|
|
|
PGP_MESSAGE = '-----BEGIN PGP MESSAGE-----'
|
|
|
|
PGP_PUBLIC_KEY_BLOCK = '-----BEGIN PGP PUBLIC KEY BLOCK-----'
|
|
|
|
PGP_PRIVATE_KEY_BLOCK = '-----BEGIN PGP PRIVATE KEY BLOCK-----'
|
|
|
|
PGP_SIGNATURE = '-----BEGIN PGP SIGNATURE-----'
|
|
|
|
CERTIFICATE = '-----BEGIN CERTIFICATE-----'
|
|
|
|
PUBLIC_KEY = '-----BEGIN PUBLIC KEY-----'
|
|
|
|
PRIVATE_KEY = '-----BEGIN PRIVATE KEY-----'
|
|
|
|
ENCRYPTED_PRIVATE_KEY = '-----BEGIN ENCRYPTED PRIVATE KEY-----'
|
|
|
|
OPENSSH_PRIVATE_KEY = '-----BEGIN OPENSSH PRIVATE KEY-----'
|
|
|
|
SSH2_ENCRYPTED_PRIVATE_KEY = '---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----'
|
|
|
|
OPENVPN_STATIC_KEY_V1 = '-----BEGIN OpenVPN Static key V1-----'
|
|
|
|
RSA_PRIVATE_KEY = '-----BEGIN RSA PRIVATE KEY-----'
|
|
|
|
DSA_PRIVATE_KEY = '-----BEGIN DSA PRIVATE KEY-----'
|
|
|
|
EC_PRIVATE_KEY = '-----BEGIN EC PRIVATE KEY-----'
|
|
|
|
|
|
|
|
|
|
|
|
class Keys(AbstractModule):
|
|
|
|
"""
|
|
|
|
Keys module for AIL framework
|
|
|
|
"""
|
2021-05-28 15:23:51 +00:00
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
def __init__(self):
|
|
|
|
super(Keys, self).__init__()
|
|
|
|
|
2022-10-25 14:25:19 +00:00
|
|
|
# Waiting time in seconds between to message processed
|
2021-04-02 07:52:05 +00:00
|
|
|
self.pending_seconds = 1
|
|
|
|
|
|
|
|
def compute(self, message):
|
2023-06-22 13:38:04 +00:00
|
|
|
item = self.get_obj()
|
2021-05-28 15:23:51 +00:00
|
|
|
content = item.get_content()
|
2018-05-02 15:07:10 +00:00
|
|
|
|
2022-11-28 14:44:26 +00:00
|
|
|
# find = False
|
2021-04-02 07:52:05 +00:00
|
|
|
get_pgp_content = False
|
2018-04-05 09:40:34 +00:00
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
if KeyEnum.PGP_MESSAGE.value in content:
|
2024-03-13 10:58:40 +00:00
|
|
|
self.redis_logger.warning(f'{self.obj.get_global_id()} has a PGP enc message')
|
2019-05-20 09:57:49 +00:00
|
|
|
|
2023-06-22 13:38:04 +00:00
|
|
|
tag = 'infoleak:automatic-detection="pgp-message"'
|
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2021-04-02 07:52:05 +00:00
|
|
|
get_pgp_content = True
|
2022-11-28 14:44:26 +00:00
|
|
|
# find = True
|
2019-05-20 09:57:49 +00:00
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
if KeyEnum.PGP_PUBLIC_KEY_BLOCK.value in content:
|
2024-01-08 13:24:51 +00:00
|
|
|
tag = 'infoleak:automatic-detection="pgp-public-key-block"'
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2021-04-02 07:52:05 +00:00
|
|
|
get_pgp_content = True
|
2019-05-20 09:57:49 +00:00
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
if KeyEnum.PGP_SIGNATURE.value in content:
|
2024-01-08 13:24:51 +00:00
|
|
|
tag = 'infoleak:automatic-detection="pgp-signature"'
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2021-04-02 07:52:05 +00:00
|
|
|
get_pgp_content = True
|
2018-05-16 12:39:01 +00:00
|
|
|
|
2022-11-28 14:44:26 +00:00
|
|
|
if KeyEnum.PGP_PRIVATE_KEY_BLOCK.value in content:
|
2024-03-13 10:58:40 +00:00
|
|
|
self.redis_logger.warning(f'{self.obj.get_global_id()} has a pgp private key block message')
|
2022-11-28 14:44:26 +00:00
|
|
|
|
2024-01-08 13:24:51 +00:00
|
|
|
tag = 'infoleak:automatic-detection="pgp-private-key"'
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2022-11-28 14:44:26 +00:00
|
|
|
get_pgp_content = True
|
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
if KeyEnum.CERTIFICATE.value in content:
|
2024-03-13 10:58:40 +00:00
|
|
|
self.redis_logger.warning(f'{self.obj.get_global_id()} has a certificate message')
|
2018-04-05 09:40:34 +00:00
|
|
|
|
2024-01-08 13:24:51 +00:00
|
|
|
tag = 'infoleak:automatic-detection="certificate"'
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2022-11-28 14:44:26 +00:00
|
|
|
# find = True
|
2018-05-16 12:39:01 +00:00
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
if KeyEnum.RSA_PRIVATE_KEY.value in content:
|
2024-03-13 10:58:40 +00:00
|
|
|
self.redis_logger.warning(f'{self.obj.get_global_id()} has a RSA private key message')
|
2021-04-02 07:52:05 +00:00
|
|
|
print('rsa private key message found')
|
2018-04-05 09:40:34 +00:00
|
|
|
|
2024-01-08 13:24:51 +00:00
|
|
|
tag = 'infoleak:automatic-detection="rsa-private-key"'
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2022-11-28 14:44:26 +00:00
|
|
|
# find = True
|
2018-05-16 12:39:01 +00:00
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
if KeyEnum.PRIVATE_KEY.value in content:
|
2024-03-13 10:58:40 +00:00
|
|
|
self.redis_logger.warning(f'{self.obj.get_global_id()} has a private key message')
|
2021-04-02 07:52:05 +00:00
|
|
|
print('private key message found')
|
2018-04-05 09:40:34 +00:00
|
|
|
|
2024-01-08 13:24:51 +00:00
|
|
|
tag = 'infoleak:automatic-detection="private-key"'
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2022-11-28 14:44:26 +00:00
|
|
|
# find = True
|
2018-05-16 12:39:01 +00:00
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
if KeyEnum.ENCRYPTED_PRIVATE_KEY.value in content:
|
2024-03-13 10:58:40 +00:00
|
|
|
self.redis_logger.warning(f'{self.obj.get_global_id()} has an encrypted private key message')
|
2021-04-02 07:52:05 +00:00
|
|
|
print('encrypted private key message found')
|
2018-04-11 08:14:33 +00:00
|
|
|
|
2024-01-08 13:24:51 +00:00
|
|
|
tag = 'infoleak:automatic-detection="encrypted-private-key"'
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2022-11-28 14:44:26 +00:00
|
|
|
# find = True
|
2018-05-16 12:39:01 +00:00
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
if KeyEnum.OPENSSH_PRIVATE_KEY.value in content:
|
2024-03-13 10:58:40 +00:00
|
|
|
self.redis_logger.warning(f'{self.obj.get_global_id()} has an openssh private key message')
|
2021-04-02 07:52:05 +00:00
|
|
|
print('openssh private key message found')
|
2018-05-02 15:07:10 +00:00
|
|
|
|
2024-01-08 13:24:51 +00:00
|
|
|
tag = 'infoleak:automatic-detection="private-ssh-key"'
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2022-11-28 14:44:26 +00:00
|
|
|
# find = True
|
2018-08-01 14:04:06 +00:00
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
if KeyEnum.SSH2_ENCRYPTED_PRIVATE_KEY.value in content:
|
2024-03-13 10:58:40 +00:00
|
|
|
self.redis_logger.warning(f'{self.obj.get_global_id()} has an ssh2 private key message')
|
2021-04-02 07:52:05 +00:00
|
|
|
print('SSH2 private key message found')
|
2018-08-01 14:04:06 +00:00
|
|
|
|
2024-01-08 13:24:51 +00:00
|
|
|
tag = 'infoleak:automatic-detection="private-ssh-key"'
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2022-11-28 14:44:26 +00:00
|
|
|
# find = True
|
2018-05-16 12:39:01 +00:00
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
if KeyEnum.OPENVPN_STATIC_KEY_V1.value in content:
|
2024-03-13 10:58:40 +00:00
|
|
|
self.redis_logger.warning(f'{self.obj.get_global_id()} has an openssh private key message')
|
2021-04-02 07:52:05 +00:00
|
|
|
print('OpenVPN Static key message found')
|
2018-04-11 08:14:33 +00:00
|
|
|
|
2024-01-08 13:24:51 +00:00
|
|
|
tag = 'infoleak:automatic-detection="vpn-static-key"'
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2022-11-28 14:44:26 +00:00
|
|
|
# find = True
|
2018-05-16 12:39:01 +00:00
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
if KeyEnum.DSA_PRIVATE_KEY.value in content:
|
2024-03-13 10:58:40 +00:00
|
|
|
self.redis_logger.warning(f'{self.obj.get_global_id()} has a dsa private key message')
|
2018-04-11 08:14:33 +00:00
|
|
|
|
2024-01-08 13:24:51 +00:00
|
|
|
tag = 'infoleak:automatic-detection="dsa-private-key"'
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2022-11-28 14:44:26 +00:00
|
|
|
# find = True
|
2018-05-16 12:39:01 +00:00
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
if KeyEnum.EC_PRIVATE_KEY.value in content:
|
2024-03-13 10:58:40 +00:00
|
|
|
self.redis_logger.warning(f'{self.obj.get_global_id()} has an ec private key message')
|
2018-04-11 08:14:33 +00:00
|
|
|
|
2024-01-08 13:24:51 +00:00
|
|
|
tag = 'infoleak:automatic-detection="ec-private-key"'
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2022-11-28 14:44:26 +00:00
|
|
|
# find = True
|
2019-10-28 13:37:50 +00:00
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
if KeyEnum.PUBLIC_KEY.value in content:
|
2024-03-13 10:58:40 +00:00
|
|
|
self.redis_logger.warning(f'{self.obj.get_global_id()} has a public key message')
|
2019-10-28 13:37:50 +00:00
|
|
|
|
2024-01-08 13:24:51 +00:00
|
|
|
tag = 'infoleak:automatic-detection="public-key"'
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(message=tag, queue='Tags')
|
2022-11-28 14:44:26 +00:00
|
|
|
# find = True
|
2019-05-14 15:49:31 +00:00
|
|
|
|
2021-04-02 07:52:05 +00:00
|
|
|
# pgp content
|
|
|
|
if get_pgp_content:
|
2023-06-22 13:38:04 +00:00
|
|
|
self.add_message_to_queue(queue='PgpDump')
|
2018-04-05 09:40:34 +00:00
|
|
|
|
2022-10-25 14:25:19 +00:00
|
|
|
# if find :
|
|
|
|
# # Send to duplicate
|
2023-04-13 12:25:02 +00:00
|
|
|
# self.add_message_to_queue(item.get_id(), 'Duplicate')
|
2023-05-12 13:29:53 +00:00
|
|
|
# self.logger.debug(f'{item.get_id()} has key(s)')
|
2022-10-25 14:25:19 +00:00
|
|
|
# print(f'{item.get_id()} has key(s)')
|
|
|
|
|
2016-02-05 15:03:37 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-04-02 07:52:05 +00:00
|
|
|
module = Keys()
|
|
|
|
module.run()
|