2018-05-04 13:53:29 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-02-05 16:03:37 +01:00
|
|
|
# -*-coding:UTF-8 -*
|
2017-05-09 11:13:16 +02:00
|
|
|
|
2016-02-05 16:03:37 +01:00
|
|
|
"""
|
2017-05-09 11:13:16 +02:00
|
|
|
The Keys Module
|
|
|
|
======================
|
|
|
|
|
|
|
|
This module is consuming the Redis-list created by the Global module.
|
|
|
|
|
2018-04-05 11:40:34 +02:00
|
|
|
It is looking for PGP, private and encrypted private,
|
|
|
|
RSA private key, certificate messages
|
2017-05-09 11:13:16 +02:00
|
|
|
|
2016-02-05 16:03:37 +01:00
|
|
|
"""
|
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
##################################
|
|
|
|
# Import External packages
|
|
|
|
##################################
|
2016-02-05 16:03:37 +01:00
|
|
|
import time
|
2021-04-02 09:52:05 +02:00
|
|
|
from enum import Enum
|
2016-02-05 16:03:37 +01:00
|
|
|
from pubsublogger import publisher
|
|
|
|
|
2018-04-16 14:50:04 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
|
|
|
from module.abstract_module import AbstractModule
|
2018-04-16 14:50:04 +02:00
|
|
|
from packages import Paste
|
|
|
|
from Helper import Process
|
2016-02-05 16:03:37 +01:00
|
|
|
|
|
|
|
|
2021-04-02 09:52:05 +02: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
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super(Keys, self).__init__()
|
|
|
|
|
|
|
|
# Waiting time in secondes between to message proccessed
|
|
|
|
self.pending_seconds = 1
|
|
|
|
|
|
|
|
|
|
|
|
def compute(self, message):
|
|
|
|
paste = Paste.Paste(message)
|
|
|
|
content = paste.get_p_content()
|
2018-05-02 17:07:10 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
find = False
|
|
|
|
get_pgp_content = False
|
2018-04-05 11:40:34 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
if KeyEnum.PGP_MESSAGE.value in content:
|
|
|
|
self.redis_logger.warning('{} has a PGP enc message'.format(paste.p_name))
|
2019-05-20 11:57:49 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
msg = 'infoleak:automatic-detection="pgp-message";{}'.format(message)
|
|
|
|
self.process.populate_set_out(msg, 'Tags')
|
|
|
|
get_pgp_content = True
|
|
|
|
find = True
|
2019-05-20 11:57:49 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
if KeyEnum.PGP_PUBLIC_KEY_BLOCK.value in content:
|
|
|
|
msg = 'infoleak:automatic-detection="pgp-public-key-block";{}'.format(message)
|
|
|
|
self.process.populate_set_out(msg, 'Tags')
|
|
|
|
get_pgp_content = True
|
2019-05-20 11:57:49 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
if KeyEnum.PGP_SIGNATURE.value in content:
|
|
|
|
msg = 'infoleak:automatic-detection="pgp-signature";{}'.format(message)
|
|
|
|
self.process.populate_set_out(msg, 'Tags')
|
|
|
|
get_pgp_content = True
|
2018-05-16 14:39:01 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
if KeyEnum.CERTIFICATE.value in content:
|
|
|
|
self.redis_logger.warning('{} has a certificate message'.format(paste.p_name))
|
2018-04-05 11:40:34 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
msg = 'infoleak:automatic-detection="certificate";{}'.format(message)
|
|
|
|
self.process.populate_set_out(msg, 'Tags')
|
|
|
|
find = True
|
2018-05-16 14:39:01 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
if KeyEnum.RSA_PRIVATE_KEY.value in content:
|
|
|
|
self.redis_logger.warning('{} has a RSA private key message'.format(paste.p_name))
|
|
|
|
print('rsa private key message found')
|
2018-04-05 11:40:34 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
msg = 'infoleak:automatic-detection="rsa-private-key";{}'.format(message)
|
|
|
|
self.process.populate_set_out(msg, 'Tags')
|
|
|
|
find = True
|
2018-05-16 14:39:01 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
if KeyEnum.PRIVATE_KEY.value in content:
|
|
|
|
self.redis_logger.warning('{} has a private key message'.format(paste.p_name))
|
|
|
|
print('private key message found')
|
2018-04-05 11:40:34 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
msg = 'infoleak:automatic-detection="private-key";{}'.format(message)
|
|
|
|
self.process.populate_set_out(msg, 'Tags')
|
|
|
|
find = True
|
2018-05-16 14:39:01 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
if KeyEnum.ENCRYPTED_PRIVATE_KEY.value in content:
|
|
|
|
self.redis_logger.warning('{} has an encrypted private key message'.format(paste.p_name))
|
|
|
|
print('encrypted private key message found')
|
2018-04-11 10:14:33 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
msg = 'infoleak:automatic-detection="encrypted-private-key";{}'.format(message)
|
|
|
|
self.process.populate_set_out(msg, 'Tags')
|
|
|
|
find = True
|
2018-05-16 14:39:01 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
if KeyEnum.OPENSSH_PRIVATE_KEY.value in content:
|
|
|
|
self.redis_logger.warning('{} has an openssh private key message'.format(paste.p_name))
|
|
|
|
print('openssh private key message found')
|
2018-05-02 17:07:10 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
msg = 'infoleak:automatic-detection="private-ssh-key";{}'.format(message)
|
|
|
|
self.process.populate_set_out(msg, 'Tags')
|
|
|
|
find = True
|
2018-08-01 16:04:06 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
if KeyEnum.SSH2_ENCRYPTED_PRIVATE_KEY.value in content:
|
|
|
|
self.redis_logger.warning('{} has an ssh2 private key message'.format(paste.p_name))
|
|
|
|
print('SSH2 private key message found')
|
2018-08-01 16:04:06 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
msg = 'infoleak:automatic-detection="private-ssh-key";{}'.format(message)
|
|
|
|
self.process.populate_set_out(msg, 'Tags')
|
|
|
|
find = True
|
2018-05-16 14:39:01 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
if KeyEnum.OPENVPN_STATIC_KEY_V1.value in content:
|
|
|
|
self.redis_logger.warning('{} has an openssh private key message'.format(paste.p_name))
|
|
|
|
print('OpenVPN Static key message found')
|
2018-04-11 10:14:33 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
msg = 'infoleak:automatic-detection="vpn-static-key";{}'.format(message)
|
|
|
|
self.process.populate_set_out(msg, 'Tags')
|
|
|
|
find = True
|
2018-05-16 14:39:01 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
if KeyEnum.DSA_PRIVATE_KEY.value in content:
|
|
|
|
self.redis_logger.warning('{} has a dsa private key message'.format(paste.p_name))
|
2018-04-11 10:14:33 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
msg = 'infoleak:automatic-detection="dsa-private-key";{}'.format(message)
|
|
|
|
self.process.populate_set_out(msg, 'Tags')
|
|
|
|
find = True
|
2018-05-16 14:39:01 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
if KeyEnum.EC_PRIVATE_KEY.value in content:
|
|
|
|
self.redis_logger.warning('{} has an ec private key message'.format(paste.p_name))
|
2018-04-11 10:14:33 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
msg = 'infoleak:automatic-detection="ec-private-key";{}'.format(message)
|
|
|
|
self.process.populate_set_out(msg, 'Tags')
|
|
|
|
find = True
|
2018-05-16 14:39:01 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
if KeyEnum.PGP_PRIVATE_KEY_BLOCK.value in content:
|
|
|
|
self.redis_logger.warning('{} has a pgp private key block message'.format(paste.p_name))
|
2018-04-05 11:40:34 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
msg = 'infoleak:automatic-detection="pgp-private-key";{}'.format(message)
|
|
|
|
self.process.populate_set_out(msg, 'Tags')
|
|
|
|
find = True
|
2019-10-28 14:37:50 +01:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
if KeyEnum.PUBLIC_KEY.value in content:
|
|
|
|
self.redis_logger.warning('{} has a public key message'.format(paste.p_name))
|
2019-10-28 14:37:50 +01:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
msg = 'infoleak:automatic-detection="public-key";{}'.format(message)
|
|
|
|
self.process.populate_set_out(msg, 'Tags')
|
|
|
|
find = True
|
2019-05-14 17:49:31 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
# pgp content
|
|
|
|
if get_pgp_content:
|
|
|
|
self.process.populate_set_out(message, 'PgpDump')
|
2018-04-05 11:40:34 +02:00
|
|
|
|
2021-04-02 09:52:05 +02:00
|
|
|
if find :
|
|
|
|
#Send to duplicate
|
|
|
|
self.process.populate_set_out(message, 'Duplicate')
|
|
|
|
self.redis_logger.debug(message)
|
2016-02-05 16:03:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-04-02 09:52:05 +02:00
|
|
|
|
|
|
|
module = Keys()
|
|
|
|
module.run()
|