Skip to content

Commit

Permalink
Merging changes in develop branch into this feature branch prior to m…
Browse files Browse the repository at this point in the history
…erger.

Merge branch 'develop' of github.com:cisagov/gophish-tools into Issue_11_AssessmentID_match_fix
  • Loading branch information
JCantu248 committed Oct 22, 2021
2 parents 9c83ccb + bc24ff9 commit 8095e00
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 93 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
![Docker Image Size](https://img.shields.io/docker/image-size/cisagov/gophish-tools)

This repository contains a set of scripts that can be used by phishing
campaign assessors to simplify the process of managing GoPhish campaigns.
campaign assessors to simplify the process of managing Gophish campaigns.

## Scripts ##

- `gophish-cleaner` - Removes an assessment or elements of an assessment
in GoPhish.
- `gophish-complete` - Completes a campaign in GoPhish and/or outputs a
GoPhish campaign summary.
- `gophish-export` - Exports all the data from an assessment within GoPhish
in Gophish.
- `gophish-complete` - Completes a campaign in Gophish and/or outputs a
Gophish campaign summary.
- `gophish-export` - Exports all the data from an assessment within Gophish
into a single JSON file. In addition, user report JSONs for each campaign in
an assessment will also be generated.
- `gophish-import` - Imports an assessment JSON file into GoPhish.
- `gophish-test` - Sends a duplicate assessment from GoPhish to custom
- `gophish-import` - Imports an assessment JSON file into Gophish.
- `gophish-test` - Sends a duplicate assessment from Gophish to custom
targets as a test.
- `pca-wizard` - Creates an assessment JSON file via an interactive "wizard".
- `pca-wizard-templates` - Generates templates for files needed when creating
Expand Down Expand Up @@ -96,14 +96,14 @@ An example assessment JSON can be found [here](src/assessment/sample_assessment.
|------|-------------|:----:|:-------:|:--------:|
| id | Assessment identifier. (e.g. "RV0000") | string | | yes |
| timezone | Timezone name based on [pytz](http://pytz.sourceforge.net/) timezones. (e.g. "US/Eastern") | string | | yes |
| domain | Assessment domain for GoPhish public interface. (e.g. "domain.tld") | string | | yes |
| domain | Assessment domain for Gophish public interface. (e.g. "domain.tld") | string | | yes |
| target_domain | Approved target domains where all email recipients must reside. (e.g. ["target1.tld", "target2.tld"]) | list(string) | | yes |
| start_date | Assessment start date in 24-hr ISO format with offset. (e.g. "2020-01-01T14:00:00-04:00") | string | | yes |
| end_date | Assessment end date in 24-hr ISO format with offset. (e.g. "2020-01-06T15:30:00-04:00") | string | | yes |
| reschedule | Indicates if the assessment json is a rescheduled assessment. | boolean | | yes |
| start_campaign | The campaign that the assessment should start at. | integer | `1` | no |
| groups | Consolidated list of email recipients grouped to receive campaigns, [example](#group-dictionary). | list(dict) | | yes |
| pages | GoPhish landing pages, [example](#page-dictionary). | list(dict) | | yes |
| pages | Gophish landing pages, [example](#page-dictionary). | list(dict) | | yes |
| campaigns | Assessment campaigns, [example](#campaign-dictionary). | list(dict) | | yes |

### Group Dictionary ###
Expand All @@ -130,8 +130,8 @@ with the command `pca-wizard-templates --targets`.
| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-------:|:--------:|
| name | Page name in the format of `{assessment identifier}-{integer}-{descriptor}` (e.g. "RV0000-1-AutoForward"). | string | | yes |
| capture_credentials | Capture all non-password input with GoPhish. Supports forwarding after submit action. | boolean | | yes |
| capture_passwords | Capture password input by the user, but note that captured input is **stored in plain text as of GoPhish version 0.9.0.** | boolean | `False` | no |
| capture_credentials | Capture all non-password input with Gophish. Supports forwarding after submit action. | boolean | | yes |
| capture_passwords | Capture password input by the user, but note that captured input is **stored in plain text as of Gophish version 0.9.0.** | boolean | `False` | no |
| html | Content of the landing page in HTML format. | string | | yes |

### Campaign Dictionary ###
Expand All @@ -145,7 +145,7 @@ with the command `pca-wizard-templates --targets`.
| page_name | Landing page name as defined in the assessment json. | string | | yes |
| group_name | Group name as defined in the assessment json. | string | | yes |
| template | Email template for the campaign, [example](#email-template-dictionary). | dict | | yes |
| smtp | GoPhish sending profile, [example](#smtp-dictionary). | dict | | yes |
| smtp | Gophish sending profile, [example](#smtp-dictionary). | dict | | yes |

### Email Template Dictionary ###

Expand All @@ -165,9 +165,9 @@ with the command `pca-wizard-templates --emails`.
|------|-------------|:----:|:-------:|:--------:|
| name | Sending profile name in the format of `{assessment identifier}-SP-{integer}` (e.g. "RV0000-SP-1"). | string | | yes |
| from_address | From email address with display name, required format: `{display name}<{sending email address}>`. (e.g. "John Doe\<john.doe@domain.tld\>") | string | | yes |
| host | Email server for GoPhish to send email through. | string | "postfix:587" | no |
| interface_type | Type of interface GoPhish will use with mail server. | string | "SMTP" | no |
| ignore_cert | Indicate if GoPhish should ignore certs with mail server. | boolean | `True` | no |
| host | Email server for Gophish to send email through. | string | "postfix:587" | no |
| interface_type | Type of interface Gophish will use with mail server. | string | "SMTP" | no |
| ignore_cert | Indicate if Gophish should ignore certs with mail server. | boolean | `True` | no |

## User Report Field Dictionary ##

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_version(version_file):
name="gophish-tools",
# Versions should comply with PEP440
version=get_version("src/_version.py"),
description="Helpful tools for interacting with GoPhish",
description="Helpful tools for interacting with Gophish",
long_description=readme(),
long_description_content_type="text/markdown",
# Landing page for CISA's cybersecurity mission
Expand Down
31 changes: 19 additions & 12 deletions src/assessment/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@
</html>
"""

CONFIRMATION_PROMPT = "\nDo you need to modify any of the values for this campaign?"


def set_time_zone():
"""Select a timezone from a list of US-based time zones.
:return: Time zone name based on pytz.
Returns: Time zone name based on pytz.
"""
# TODO Allow for a select more option to get access to full list of Time Zones
# See issue: https://github.com/cisagov/gophish-tools/issues/49

# Creates list of US Time Zones
time_zone = list()
Expand Down Expand Up @@ -103,7 +106,7 @@ def display_list_pages(assessment):
def build_assessment(assessment_id):
"""Walk user through building a new assessment document.
:return an assessment object
Returns: an assessment object
"""
logging.info("Building Assessment")
# Initializes assessment object with ID and timezone
Expand Down Expand Up @@ -212,7 +215,7 @@ def review_campaign(campaign):
)
)

if yes_no_prompt("\nChanges Required") == "yes":
if yes_no_prompt(CONFIRMATION_PROMPT) == "yes":
completer = WordCompleter(
campaign_dict.keys().remove("template"), ignore_case=True
)
Expand Down Expand Up @@ -341,7 +344,7 @@ def import_email(assessment, campaign_number, template_smtp):

continue

# Finalize SMTP profile, push to GoPhish for check.
# Finalize SMTP profile, push to Gophish for check.
# TODO Need to valid this formatting.
temp_smtp.from_address = import_temp["from_address"]

Expand Down Expand Up @@ -472,7 +475,10 @@ def build_emails(domains, labels):
targets.append(target)
else:
logging.error("{} Formatting Errors".format(len(format_error)))
if yes_no_prompt("Would you like to correct each here") == "yes":
if (
yes_no_prompt("Would you like to correct each here? (yes/no)")
== "yes"
):
for email in format_error:
email[2] = prompt(
"Correct Email Formatting: ",
Expand Down Expand Up @@ -501,10 +507,11 @@ def build_emails(domains, labels):
validator=EmailValidator(),
)
else:
logging.error(
"{} Domain Miss Match Errors".format(len(format_error))
)
if yes_no_prompt("Would you like to correct each here") == "yes":
logging.error("{} Domain Mismatch Errors".format(len(format_error)))
if (
yes_no_prompt("Would you like to correct each here? (yes/no)")
== "yes"
):
for email in domain_miss_match:
while True:
email[2] = prompt(
Expand Down Expand Up @@ -568,7 +575,7 @@ def build_pages(id_):
for page_num in range(int(num_pages)):
logging.info(f"Building Page {page_num + 1}")
temp_page = Page()
auto_forward = yes_no_prompt(" Will this page auto forward")
auto_forward = yes_no_prompt(" Will this page auto forward?")

if auto_forward == "yes":

Expand All @@ -581,7 +588,7 @@ def build_pages(id_):
else:
temp_page.name = f"{id_}-{page_num+1}-Landing"

forward = yes_no_prompt(" Will this page forward after action")
forward = yes_no_prompt(" Will this page forward after action? (yes/no)")
if forward == "yes":
temp_page.capture_credentials = True
temp_page.redirect_url = get_input(" URL to Redirect to:")
Expand Down Expand Up @@ -629,7 +636,7 @@ def review_page(page):
if key != "html":
print("{}: {}".format(key, value))
page_keys.append(key)
if yes_no_prompt("Changes Required") == "yes":
if yes_no_prompt(CONFIRMATION_PROMPT) == "yes":
completer = WordCompleter(page_keys, ignore_case=True)

# Loops to get valid Field name form user.
Expand Down
8 changes: 4 additions & 4 deletions src/tools/connect.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Module to create a GoPhish API connection."""
"""Module to create a Gophish API connection."""

# Third-Party Libraries
from gophish import Gophish
Expand All @@ -7,7 +7,7 @@


def connect_api(api_key, server):
"""Create a GoPhish API connection."""
"""Create a Gophish API connection."""
api = Gophish(api_key, host=server, verify=False)

# Sets up connection and test that it works.
Expand All @@ -22,7 +22,7 @@ def connect_api(api_key, server):
raise Exception(f"Error Connecting: {message}")

except ConnectionError:
raise Exception("Networking Error, unable to reach GoPhish.")
raise Exception("Networking Error, unable to reach Gophish.")

except Exception:
raise Exception("Cannot connect to GoPhish.")
raise Exception("Cannot connect to Gophish.")
8 changes: 4 additions & 4 deletions src/tools/gophish_cleaner.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""Remove an assessment or elements of an assessment in GoPhish.
"""Remove an assessment or elements of an assessment in Gophish.
Usage:
gophish-cleaner (--assessment | --campaigns | --groups | --pages | --smtp | --templates) [--log-level=LEVEL] ASSESSMENT_ID SERVER API_KEY
gophish-cleaner (-h | --help)
gophish-cleaner --version
Options:
API_KEY GoPhish API key.
API_KEY Gophish API key.
ASSESSMENT_ID ID of the assessment to remove data from.
SERVER Full URL to GoPhish server.
SERVER Full URL to Gophish server.
-a --assessment Remove all data for the specified assessment.
-c --campaigns Remove all campaigns from the specified assessment.
-g --groups Remove all users and groups from the specified assessment.
Expand Down Expand Up @@ -39,7 +39,7 @@

from ._version import __version__

# Disable "Insecure Request" warning: GoPhish uses a self-signed certificate
# Disable "Insecure Request" warning: Gophish uses a self-signed certificate
# as default for https connections, which can not be verified by a third
# party; thus, an SSL insecure request warning is produced.
requests.packages.urllib3.disable_warnings()
Expand Down
24 changes: 12 additions & 12 deletions src/tools/gophish_complete.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Complete a campaign in GoPhish and/or output a GoPhish campaign summary.
"""Complete a campaign in Gophish and/or output a Gophish campaign summary.
Usage:
gophish-complete [--campaign=NAME] [--summary-only] [--log-level=LEVEL] SERVER API_KEY
gophish-complete (-h | --help)
gophish-complete --version
Options:
API_KEY GoPhish API key.
SERVER Full URL to GoPhish server.
-c --campaign=NAME GoPhish campaign name.
-s --summary-only Output a summary of a GoPhish campaign.
API_KEY Gophish API key.
SERVER Full URL to Gophish server.
-c --campaign=NAME Gophish campaign name.
-s --summary-only Output a summary of a Gophish campaign.
-h --help Show this screen.
--version Show version.
-l --log-level=LEVEL If specified, then the log level will be set to
Expand Down Expand Up @@ -38,7 +38,7 @@

from ._version import __version__

# Disable "Insecure Request" warning: GoPhish uses a self-signed certificate
# Disable "Insecure Request" warning: Gophish uses a self-signed certificate
# as default for https connections, which can not be verified by a third
# party; thus, an SSL insecure request warning is produced.
requests.packages.urllib3.disable_warnings()
Expand Down Expand Up @@ -72,7 +72,7 @@ def get_campaigns(api, assessment_id=""):
provided, then only the campaigns for that assessment will be returned.
Args:
api (GoPhish API): Connection to GoPhish server via the API.
api (Gophish API): Connection to Gophish server via the API.
assessment_id (string): Assessment identifier to get campaigns from.
Raises:
Expand Down Expand Up @@ -117,15 +117,15 @@ def select_campaign(campaigns):


def complete_campaign(api_key, server, campaign_id):
"""Complete a campaign in GoPhish.
"""Complete a campaign in Gophish.
Args:
api_key (string): GoPhish API key.
server (string): Full URL to GoPhish server.
campaign_id (int): GoPhish campaign id.
api_key (string): Gophish API key.
server (string): Full URL to Gophish server.
campaign_id (int): Gophish campaign id.
Raises:
UserWarning: GoPhish is unsuccessful in completing the campaign.
UserWarning: Gophish is unsuccessful in completing the campaign.
"""
url = f"{server}/api/campaigns/{campaign_id}/complete?api_key={api_key}"

Expand Down

0 comments on commit 8095e00

Please sign in to comment.