Skip to content

Instantly share code, notes, and snippets.

@resource-not-found
Created May 9, 2024 06:50
Show Gist options
  • Save resource-not-found/f9986f037e094eef762b79f9cac5cfc6 to your computer and use it in GitHub Desktop.
Save resource-not-found/f9986f037e094eef762b79f9cac5cfc6 to your computer and use it in GitHub Desktop.
Appendix 2: gophish_create_groups.py
import sys
import re
from gophish import Gophish
from gophish.models import Group, Page, Template, SMTP, Campaign, User
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def parse_parameters(param_str):
param_str = param_str.strip()
pattern = re.compile(r'(\w+)="([^"]*)"')
matches = pattern.findall(param_str)
result_dict = dict(matches)
return result_dict
key = '[GOPHISH_API_KEY]'
api = Gophish(key, host='https://127.0.0.1:3333', verify=False)
groups = api.groups.get()
file_name = sys.argv[2]
with open(file_name, 'r') as file:
for line in file:
line = line.rstrip()
params = line.split(' ; ')[1]
params = parse_parameters(params)
if params['email'] not in [g.name for g in groups]:
targets = [
User(
first_name=params['first_name'],
last_name=params['last_name'],
email=params['email'],
position=params['position']),
]
group = Group(name=params['email'], targets=targets)
api.groups.post(group)
print('Created: {} {} ({})'.format(params['first_name'], params['last_name'], params['position']))
# Example run: python3 gophish_create_groups.py urls_1.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment