This Python script provides a command-line interface (CLI) to automate the creation, scheduling, and management of large-scale, multi-day phishing campaigns in Gophish. It's designed to streamline the process of uploading numerous user groups from CSV files and scheduling a unique campaign for each group over a specified period.
- Bulk Group Creation: Automatically scans a directory for CSV files and uploads each as a separate user group in Gophish.
- Interactive Upload: Prompts the user to confirm, skip, or upload all groups, showing a preview of the data first.
- Automated Campaign Scheduling: Schedules campaigns for the created groups over a specified date range, with a configurable number of launches per day during business hours.
- Interactive Configuration: On the first run, interactively prompts you to select your Gophish email templates, landing pages, and SMTP profiles, saving them to a
campaign_config.jsonfile. - Campaign & Group Management: Includes utilities to list and delete campaigns or groups based on a common name prefix, making cleanup easy and safe.
- Debug Mode: An optional debug mode in the configuration to print API payloads before they are sent.
- Python 3.6+
- A running Gophish instance with API access enabled.
- Your Gophish API Key.
-
Clone the Repository
git clone <your-repo-url> cd <your-repo-directory>
-
Install Dependencies The script requires the
pandasandrequestslibraries.pip install pandas requests
-
Set Environment Variable The script securely reads your Gophish API key from an environment variable. Do not hardcode your key in the script.
On macOS/Linux:
export API_KEY="your_gophish_api_key"
(To make this permanent, add the line to your
~/.bashrc,~/.zshrc, or shell profile.)On Windows (Command Prompt):
setx API_KEY "your_gophish_api_key"(You may need to restart your terminal for this to take effect.)
-
Create the Input Folder The script reads user data from CSV files located in an
outputfolder.mkdir output
-
Configure Script Constants (Optional) Open the script and adjust the following constants at the top if your Gophish instance is not running on the default
https://127.0.0.1:3333:GOPHISH_URL: The URL for the Gophish API.GOPHISH_UI_BASE_URL: The base URL for generating clickable links to the UI.VERIFY_SSL: Set toTrueif you are using a valid, trusted SSL certificate.
β οΈ Security Warning: The defaultVERIFY_SSL = Falsedisables SSL certificate verification, which is convenient for local instances with self-signed certificates but is not secure. Set this toTruein a production environment.
For the script to correctly create user groups, your CSV files must follow a specific format and naming convention.
Place your CSV files inside the ./output/ directory. The script uses a regular expression to find and order them. The name must be:
output_day_<DAY_NUMBER>_chunk<CHUNK_NUMBER>.csv
<DAY_NUMBER>: The intended day of the campaign (e.g.,1,2,3).<CHUNK_NUMBER>: The sequence number for that day (e.g.,1,2,3).
Examples:
output_day_1_chunk1.csvoutput_day_1_chunk2.csvoutput_day_2_chunk1.csv
Each CSV file must contain the following header columns (case-insensitive):
firstnamelastnameemailposition
The script will automatically clean the data by stripping whitespace and handling missing values. Rows without an email address will be skipped.
Example output_day_1_chunk1.csv:
firstname,lastname,email,position
John,Doe,[email protected],Accountant
Jane,Smith,[email protected],Project Manager
Run the script from your terminal to bring up the main menu:
python main.pyπ Main Menu
βββββββββββββββββββββββββββββ
[1] β Groups - Add
[2] ποΈ Groups - Delete by prefix (e.g. K1)
[3] ποΈ Campaigns - Schedule
[4] βοΈ Campaigns - Update config
[5] ποΈ Campaigns - Delete by prefix (e.g. K1)
[6] π Campaigns - List by prefix
[q] β Quit
βββββββββββββββββββββββββββββ
-
[1] Add Groups:
- Prompts for a campaign prefix (e.g.,
Q4-Campaign). - Scans the
./outputfolder for valid CSV files. - For each file, it displays a preview and prompts you to [u]pload, [s]kip, [a]upload all, or [q]uit.
- Creates a Gophish group named
<Prefix>-Day<X>-<Y>.
- Prompts for a campaign prefix (e.g.,
-
[2] Delete Groups:
- Prompts for a campaign prefix.
- Finds and lists all groups whose names start with
<Prefix>-. - Requires a double confirmation (
DELETEthenYES) to prevent accidental deletion.
-
[3] Schedule Campaigns:
- This is the core scheduling function.
- It asks for:
- A campaign prefix (e.g.,
Q4-Campaign-) to find the relevant groups. - A start date and end date (YYYY-MM-DD).
- The number of campaigns to launch per day.
- A campaign prefix (e.g.,
- It then automatically creates and schedules a unique campaign for each group, spread randomly across business hours (07:00-09:30 UTC) on weekdays within your date range.
- Requires the
campaign_config.jsonto be set up (see option 4).
-
[4] Update Campaign Config:
- Loads the existing
campaign_config.jsonor creates a new one. - Connects to Gophish to fetch available Email Templates, Landing Pages, and SMTP Profiles.
- Interactively prompts you to choose which assets to use for the campaigns.
- Asks for the phishing URL (e.g.,
https://phish.yourdomain.com). - Saves your choices to
campaign_config.json.
- Loads the existing
-
[5] Delete Campaigns:
- Prompts for a campaign prefix.
- Finds and lists all campaigns matching the prefix.
- Requires confirmation to delete them.
-
[6] List Campaigns:
- Prompts for a prefix and lists all matching campaigns along with their current status and scheduled start time.
This project is licensed under the MIT License.