Skip to content

all-i-hop/gophish-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Gophish Campaign Automation Script πŸš€

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.


Key Features ✨

  • 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.json file.
  • 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.

Prerequisites

  • Python 3.6+
  • A running Gophish instance with API access enabled.
  • Your Gophish API Key.

βš™οΈ Installation & Setup

  1. Clone the Repository

    git clone <your-repo-url>
    cd <your-repo-directory>
  2. Install Dependencies The script requires the pandas and requests libraries.

    pip install pandas requests
  3. 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.)

  4. Create the Input Folder The script reads user data from CSV files located in an output folder.

    mkdir output
  5. 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 to True if you are using a valid, trusted SSL certificate.

    ⚠️ Security Warning: The default VERIFY_SSL = False disables SSL certificate verification, which is convenient for local instances with self-signed certificates but is not secure. Set this to True in a production environment.


πŸ“ Data Format: Input CSV Files

For the script to correctly create user groups, your CSV files must follow a specific format and naming convention.

File 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.csv
  • output_day_1_chunk2.csv
  • output_day_2_chunk1.csv

CSV Column Structure

Each CSV file must contain the following header columns (case-insensitive):

  • firstname
  • lastname
  • email
  • position

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

πŸš€ Usage

Run the script from your terminal to bring up the main menu:

python main.py

Main Menu Options

πŸ“‹ 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. [1] Add Groups:

    • Prompts for a campaign prefix (e.g., Q4-Campaign).
    • Scans the ./output folder 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>.
  2. [2] Delete Groups:

    • Prompts for a campaign prefix.
    • Finds and lists all groups whose names start with <Prefix>-.
    • Requires a double confirmation (DELETE then YES) to prevent accidental deletion.
  3. [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.
    • 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.json to be set up (see option 4).
  4. [4] Update Campaign Config:

    • Loads the existing campaign_config.json or 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.
  5. [5] Delete Campaigns:

    • Prompts for a campaign prefix.
    • Finds and lists all campaigns matching the prefix.
    • Requires confirmation to delete them.
  6. [6] List Campaigns:

    • Prompts for a prefix and lists all matching campaigns along with their current status and scheduled start time.

License

This project is licensed under the MIT License.

About

Managing GoPhish to get your campaigns, user lists, and config ready to deploy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages