spf-dkim-dmarc-demo/attacker/scripts/spoof_templates/__init__.py

36 lines
972 B
Python

#!/usr/bin/env python
import email
import email.policy
import importlib.resources
SPOOF_TEMPLATES = None
class SpoofTemplate:
@staticmethod
def read_template(name):
path = importlib.resources.files(__package__).joinpath(f"{name}.eml")
with path.open('r', encoding='utf-8') as fh:
return email.message_from_file(fh)
def __init__(self, name, nice_name):
self.name = name
self.nice_name = nice_name
self.msg = SpoofTemplate.read_template(name)
def load_spoof_templates():
return [SpoofTemplate(res, desc)
for res, desc
in [('extorsion', 'Extorsion'),
('fake_order_confirm', 'Fausse confirmation de commande'),
('fake_newsletter', 'Fausse newsletter')]]
def spoof_templates():
global SPOOF_TEMPLATES
if not SPOOF_TEMPLATES:
SPOOF_TEMPLATES = load_spoof_templates()
return SPOOF_TEMPLATES