From 25a831293356a073636fa26c2721e865f9fc6dd6 Mon Sep 17 00:00:00 2001 From: domwhewell-sage <122788350+domwhewell-sage@users.noreply.github.com> Date: Fri, 7 Jun 2024 14:53:12 +0100 Subject: [PATCH 1/5] Initial commit of new event types --- README.md | 8 ++ config.go | 1 + messages.go | 270 ++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 239 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 42709e6..f9d58cb 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,14 @@ base_url: https://10.0.0.15:3333 profiles: - slack - email +# Enables notifications for each of the webhook events https://docs.getgophish.com/user-guide/documentation/webhooks. Options are `email_error`, `email_sent`, `email_opened`, `clicked_link`, `submitted_data` and `email_reported`. +events: + - email_error + - email_sent + - email_opened + - clicked_link + - submitted_data + - email_reported # Slack Profile slack: diff --git a/config.go b/config.go index ea7eb9c..376c34f 100644 --- a/config.go +++ b/config.go @@ -58,6 +58,7 @@ func setDefaults() { viper.SetDefault("email_default_email_open_template", defaultEmailOpenedTemplate) viper.SetDefault("graphql_default_query", defaultgraphqlTemplate) viper.SetDefault("profiles", []string{"slack"}) + viper.SetDefault("events", []string{"email_opened", "clicked_link", "submitted_data"}) } func setLogLevel() { diff --git a/messages.go b/messages.go index 66518cd..cd1f141 100644 --- a/messages.go +++ b/messages.go @@ -14,9 +14,12 @@ import ( // Can't be const because need reference to variable for Slack webhook title var ( + EmailError string = "Error Sending Email" + EmailSent string = "Email Sent" + EmailOpened string = "Email Opened" ClickedLink string = "Clicked Link" SubmittedData string = "Submitted Data" - EmailOpened string = "Email Opened" + EmailReported string = "Email Reported" ) type Sender interface { @@ -25,16 +28,35 @@ type Sender interface { SendGraphql() error } +func contains(slice []string, str string) bool { + for _, a := range slice { + if a == str { + return true + } + } + return false +} + func senderDispatch(status string, webhookResponse WebhookResponse, response []byte) (Sender, error) { - if status == ClickedLink { - return NewClickDetails(webhookResponse, response) + enabled_events := viper.GetStringSlice("events") + if status == EmailError && contains(enabled_events, "email_error") { + return NewErrorDetails(webhookResponse, response) + } + if status == EmailSent && contains(enabled_events, "email_sent") { + return NewSentDetails(webhookResponse, response) } - if status == EmailOpened { + if status == EmailOpened && contains(enabled_events, "email_opened") { return NewOpenedDetails(webhookResponse, response) } - if status == SubmittedData { + if status == ClickedLink && contains(enabled_events, "clicked_link") { + return NewClickDetails(webhookResponse, response) + } + if status == SubmittedData && contains(enabled_events, "submitted_data") { return NewSubmittedDetails(webhookResponse, response) } + if status == EmailReported && contains(enabled_events, "email_reported") { + return NewReportedDetails(webhookResponse, response) + } log.Warn("unknown status:", status) return nil, nil } @@ -81,68 +103,170 @@ func (e EventDetails) Address() string { return e.Browser["address"] } -type SubmittedDetails struct { +type ErrorDetails struct { CampaignID uint ID string Email string Address string UserAgent string - Username string - Password string } -func NewSubmittedDetails(response WebhookResponse, detailsRaw []byte) (SubmittedDetails, error) { +func NewErrorDetails(response WebhookResponse, detailsRaw []byte) (ErrorDetails, error) { details, err := NewEventDetails(detailsRaw) if err != nil { - return SubmittedDetails{}, err + return ErrorDetails{}, err } - submittedDetails := SubmittedDetails{ + errorDetails := ErrorDetails{ CampaignID: response.CampaignID, ID: details.ID(), Address: details.Address(), + Email: response.Email, UserAgent: details.UserAgent(), + } + return errorDetails, nil +} + +func (w ErrorDetails) SendSlack() error { + orange := "#ffa500" + attachment := slack.Attachment{Title: &EmailError, Color: &orange} + attachment.AddField(slack.Field{Title: "ID", Value: w.ID}) + attachment.AddField(slack.Field{Title: "Address", Value: slackFormatIP(w.Address)}) + attachment.AddField(slack.Field{Title: "User Agent", Value: w.UserAgent}) + if !viper.GetBool("slack.disable_credentials") { + attachment.AddField(slack.Field{Title: "Email", Value: w.Email}) + } + attachment = addCampaignButton(attachment, w.CampaignID) + return sendSlackAttachment(attachment) +} + +func (w ErrorDetails) SendEmail() error { + templateString := viper.GetString("email_send_click_template") + body, err := getEmailBody(templateString, w) + if err != nil { + return err + } + return sendEmail("PhishBot - Error Sending Email", body) +} + +func (w ErrorDetails) SendGraphql() error { + oplog_entry := ghostwriterOplogEntry{ + SourceIp: w.Address, + UserContext: w.Email, + Description: "User ID: " + w.ID + "\nCampaign ID: " + strconv.FormatUint(uint64(w.CampaignID), 10), + Output: "UserAgent: " + w.UserAgent, + Comments: EmailError, + } + return sendGraphql(oplog_entry) +} + +type SentDetails struct { + CampaignID uint + ID string + Email string + Address string + UserAgent string +} + +func NewSentDetails(response WebhookResponse, detailsRaw []byte) (SentDetails, error) { + details, err := NewEventDetails(detailsRaw) + if err != nil { + return SentDetails{}, err + } + sentDetails := SentDetails{ + CampaignID: response.CampaignID, + ID: details.ID(), + Address: details.Address(), Email: response.Email, - Username: details.Payload.Get("username"), - Password: details.Payload.Get("password"), + UserAgent: details.UserAgent(), } - return submittedDetails, nil + return sentDetails, nil } -func (w SubmittedDetails) SendSlack() error { - red := "#f05b4f" - attachment := slack.Attachment{Title: &SubmittedData, Color: &red} +func (w SentDetails) SendSlack() error { + orange := "#ffa500" + attachment := slack.Attachment{Title: &EmailSent, Color: &orange} attachment.AddField(slack.Field{Title: "ID", Value: w.ID}) attachment.AddField(slack.Field{Title: "Address", Value: slackFormatIP(w.Address)}) attachment.AddField(slack.Field{Title: "User Agent", Value: w.UserAgent}) if !viper.GetBool("slack.disable_credentials") { attachment.AddField(slack.Field{Title: "Email", Value: w.Email}) - attachment.AddField(slack.Field{Title: "Username", Value: w.Username}) - attachment.AddField(slack.Field{Title: "Password", Value: w.Password}) } attachment = addCampaignButton(attachment, w.CampaignID) return sendSlackAttachment(attachment) } -func (w SubmittedDetails) SendEmail() error { - templateString := viper.GetString("email_submitted_credentials_template") +func (w SentDetails) SendEmail() error { + templateString := viper.GetString("email_send_click_template") body, err := getEmailBody(templateString, w) if err != nil { return err } - return sendEmail("PhishBot - Credentials Submitted", body) + return sendEmail("PhishBot - Email Sent", body) } -func (w SubmittedDetails) SendGraphql() error { - var output string - if !viper.GetBool("ghostwriter.disable_credentials") { - output = "\nUsername: " + w.Username + "\nPassword: " + w.Password +func (w SentDetails) SendGraphql() error { + oplog_entry := ghostwriterOplogEntry{ + SourceIp: w.Address, + UserContext: w.Email, + Description: "User ID: " + w.ID + "\nCampaign ID: " + strconv.FormatUint(uint64(w.CampaignID), 10), + Output: "UserAgent: " + w.UserAgent, + Comments: EmailSent, } + return sendGraphql(oplog_entry) +} + +type OpenedDetails struct { + CampaignID uint + ID string + Email string + Address string + UserAgent string +} + +func NewOpenedDetails(response WebhookResponse, detailsRaw []byte) (OpenedDetails, error) { + details, err := NewEventDetails(detailsRaw) + if err != nil { + return OpenedDetails{}, err + } + clickDetails := OpenedDetails{ + CampaignID: response.CampaignID, + ID: details.ID(), + Email: response.Email, + Address: details.Address(), + UserAgent: details.UserAgent(), + } + return clickDetails, nil +} + +func (w OpenedDetails) SendSlack() error { + yellow := "#ffff00" + attachment := slack.Attachment{Title: &EmailOpened, Color: &yellow} + attachment.AddField(slack.Field{Title: "ID", Value: w.ID}) + attachment.AddField(slack.Field{Title: "Address", Value: slackFormatIP(w.Address)}) + attachment.AddField(slack.Field{Title: "User Agent", Value: w.UserAgent}) + if !viper.GetBool("slack.disable_credentials") { + attachment.AddField(slack.Field{Title: "Email", Value: w.Email}) + } + attachment = addCampaignButton(attachment, w.CampaignID) + return sendSlackAttachment(attachment) +} + +func (w OpenedDetails) SendEmail() error { + templateString := viper.GetString("email_send_click_template") + body, err := getEmailBody(templateString, w) + if err != nil { + return err + } + return sendEmail("PhishBot - Email Opened", body) +} + +func (w OpenedDetails) SendGraphql() error { oplog_entry := ghostwriterOplogEntry{ SourceIp: w.Address, UserContext: w.Email, Description: "User ID: " + w.ID + "\nCampaign ID: " + strconv.FormatUint(uint64(w.CampaignID), 10), - Output: output, - Comments: SubmittedData, + Output: "UserAgent: " + w.UserAgent, + Comments: EmailOpened, } return sendGraphql(oplog_entry) } @@ -215,32 +339,98 @@ func getEmailBody(templateValue string, obj interface{}) (string, error) { return out.String(), nil } -type OpenedDetails struct { +type SubmittedDetails struct { CampaignID uint ID string Email string Address string UserAgent string + Username string + Password string } -func NewOpenedDetails(response WebhookResponse, detailsRaw []byte) (OpenedDetails, error) { +func NewSubmittedDetails(response WebhookResponse, detailsRaw []byte) (SubmittedDetails, error) { details, err := NewEventDetails(detailsRaw) if err != nil { - return OpenedDetails{}, err + return SubmittedDetails{}, err } - clickDetails := OpenedDetails{ + submittedDetails := SubmittedDetails{ CampaignID: response.CampaignID, ID: details.ID(), + Address: details.Address(), + UserAgent: details.UserAgent(), Email: response.Email, + Username: details.Payload.Get("username"), + Password: details.Payload.Get("password"), + } + return submittedDetails, nil +} + +func (w SubmittedDetails) SendSlack() error { + red := "#f05b4f" + attachment := slack.Attachment{Title: &SubmittedData, Color: &red} + attachment.AddField(slack.Field{Title: "ID", Value: w.ID}) + attachment.AddField(slack.Field{Title: "Address", Value: slackFormatIP(w.Address)}) + attachment.AddField(slack.Field{Title: "User Agent", Value: w.UserAgent}) + if !viper.GetBool("slack.disable_credentials") { + attachment.AddField(slack.Field{Title: "Email", Value: w.Email}) + attachment.AddField(slack.Field{Title: "Username", Value: w.Username}) + attachment.AddField(slack.Field{Title: "Password", Value: w.Password}) + } + attachment = addCampaignButton(attachment, w.CampaignID) + return sendSlackAttachment(attachment) +} + +func (w SubmittedDetails) SendEmail() error { + templateString := viper.GetString("email_submitted_credentials_template") + body, err := getEmailBody(templateString, w) + if err != nil { + return err + } + return sendEmail("PhishBot - Credentials Submitted", body) +} + +func (w SubmittedDetails) SendGraphql() error { + var output string + if !viper.GetBool("ghostwriter.disable_credentials") { + output = "\nUsername: " + w.Username + "\nPassword: " + w.Password + } + oplog_entry := ghostwriterOplogEntry{ + SourceIp: w.Address, + UserContext: w.Email, + Description: "User ID: " + w.ID + "\nCampaign ID: " + strconv.FormatUint(uint64(w.CampaignID), 10), + Output: output, + Comments: SubmittedData, + } + return sendGraphql(oplog_entry) +} + +type ReportedDetails struct { + CampaignID uint + ID string + Email string + Address string + UserAgent string +} + +func NewReportedDetails(response WebhookResponse, detailsRaw []byte) (ReportedDetails, error) { + details, err := NewEventDetails(detailsRaw) + if err != nil { + return ReportedDetails{}, err + } + reportedDetails := ReportedDetails{ + CampaignID: response.CampaignID, + ID: details.ID(), Address: details.Address(), + Email: response.Email, UserAgent: details.UserAgent(), } - return clickDetails, nil + return reportedDetails, nil } -func (w OpenedDetails) SendSlack() error { - yellow := "#ffff00" - attachment := slack.Attachment{Title: &EmailOpened, Color: &yellow} +func (w ReportedDetails) SendSlack() error { + orange := "#ffa500" + attachment := slack.Attachment{Title: &EmailReported, Color: &orange} attachment.AddField(slack.Field{Title: "ID", Value: w.ID}) attachment.AddField(slack.Field{Title: "Address", Value: slackFormatIP(w.Address)}) attachment.AddField(slack.Field{Title: "User Agent", Value: w.UserAgent}) @@ -251,22 +441,22 @@ func (w OpenedDetails) SendSlack() error { return sendSlackAttachment(attachment) } -func (w OpenedDetails) SendEmail() error { +func (w ReportedDetails) SendEmail() error { templateString := viper.GetString("email_send_click_template") body, err := getEmailBody(templateString, w) if err != nil { return err } - return sendEmail("PhishBot - Email Opened", body) + return sendEmail("PhishBot - Email Reported", body) } -func (w OpenedDetails) SendGraphql() error { +func (w ReportedDetails) SendGraphql() error { oplog_entry := ghostwriterOplogEntry{ SourceIp: w.Address, UserContext: w.Email, Description: "User ID: " + w.ID + "\nCampaign ID: " + strconv.FormatUint(uint64(w.CampaignID), 10), Output: "UserAgent: " + w.UserAgent, - Comments: EmailOpened, + Comments: EmailReported, } return sendGraphql(oplog_entry) } From a7ccbbb7ebe6afdbacf2849d3e9831692ee3dd74 Mon Sep 17 00:00:00 2001 From: Dom Whewell Date: Sun, 9 Jun 2024 18:39:49 +0100 Subject: [PATCH 2/5] Only the "Email Opened", "Clicked Link", and "Submitted Data" events include the details json --- main.go | 7 ++++- messages.go | 73 ++++++++++------------------------------------------- 2 files changed, 20 insertions(+), 60 deletions(-) diff --git a/main.go b/main.go index 3cd49a6..6cd7c6d 100644 --- a/main.go +++ b/main.go @@ -62,7 +62,12 @@ func handler(w http.ResponseWriter, r *http.Request) { return } - sender, err := senderDispatch(response.Message, response, []byte(response.Details)) + var details []byte + if response.Details != nil { + details = []byte(*response.Details) + } + + sender, err := senderDispatch(response.Message, response, details) if err != nil { log.Error(err) http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/messages.go b/messages.go index cd1f141..108c4bc 100644 --- a/messages.go +++ b/messages.go @@ -40,10 +40,10 @@ func contains(slice []string, str string) bool { func senderDispatch(status string, webhookResponse WebhookResponse, response []byte) (Sender, error) { enabled_events := viper.GetStringSlice("events") if status == EmailError && contains(enabled_events, "email_error") { - return NewErrorDetails(webhookResponse, response) + return NewErrorDetails(webhookResponse) } if status == EmailSent && contains(enabled_events, "email_sent") { - return NewSentDetails(webhookResponse, response) + return NewSentDetails(webhookResponse) } if status == EmailOpened && contains(enabled_events, "email_opened") { return NewOpenedDetails(webhookResponse, response) @@ -55,7 +55,7 @@ func senderDispatch(status string, webhookResponse WebhookResponse, response []b return NewSubmittedDetails(webhookResponse, response) } if status == EmailReported && contains(enabled_events, "email_reported") { - return NewReportedDetails(webhookResponse, response) + return NewReportedDetails(webhookResponse) } log.Warn("unknown status:", status) return nil, nil @@ -64,11 +64,11 @@ func senderDispatch(status string, webhookResponse WebhookResponse, response []b // More information about events can be found here: // https://github.com/gophish/gophish/blob/db63ee978dcd678caee0db71e5e1b91f9f293880/models/result.go#L50 type WebhookResponse struct { - Success bool `json:"success"` - CampaignID uint `json:"campaign_id"` - Message string `json:"message"` - Details string `json:"details"` - Email string `json:"email"` + Success bool `json:"success"` + CampaignID uint `json:"campaign_id"` + Message string `json:"message"` + Details *string `json:"details"` + Email string `json:"email"` } func NewWebhookResponse(body []byte) (WebhookResponse, error) { @@ -105,23 +105,13 @@ func (e EventDetails) Address() string { type ErrorDetails struct { CampaignID uint - ID string Email string - Address string - UserAgent string } -func NewErrorDetails(response WebhookResponse, detailsRaw []byte) (ErrorDetails, error) { - details, err := NewEventDetails(detailsRaw) - if err != nil { - return ErrorDetails{}, err - } +func NewErrorDetails(response WebhookResponse) (ErrorDetails, error) { errorDetails := ErrorDetails{ CampaignID: response.CampaignID, - ID: details.ID(), - Address: details.Address(), Email: response.Email, - UserAgent: details.UserAgent(), } return errorDetails, nil } @@ -129,9 +119,6 @@ func NewErrorDetails(response WebhookResponse, detailsRaw []byte) (ErrorDetails, func (w ErrorDetails) SendSlack() error { orange := "#ffa500" attachment := slack.Attachment{Title: &EmailError, Color: &orange} - attachment.AddField(slack.Field{Title: "ID", Value: w.ID}) - attachment.AddField(slack.Field{Title: "Address", Value: slackFormatIP(w.Address)}) - attachment.AddField(slack.Field{Title: "User Agent", Value: w.UserAgent}) if !viper.GetBool("slack.disable_credentials") { attachment.AddField(slack.Field{Title: "Email", Value: w.Email}) } @@ -150,10 +137,8 @@ func (w ErrorDetails) SendEmail() error { func (w ErrorDetails) SendGraphql() error { oplog_entry := ghostwriterOplogEntry{ - SourceIp: w.Address, UserContext: w.Email, - Description: "User ID: " + w.ID + "\nCampaign ID: " + strconv.FormatUint(uint64(w.CampaignID), 10), - Output: "UserAgent: " + w.UserAgent, + Description: "Campaign ID: " + strconv.FormatUint(uint64(w.CampaignID), 10), Comments: EmailError, } return sendGraphql(oplog_entry) @@ -161,23 +146,13 @@ func (w ErrorDetails) SendGraphql() error { type SentDetails struct { CampaignID uint - ID string Email string - Address string - UserAgent string } -func NewSentDetails(response WebhookResponse, detailsRaw []byte) (SentDetails, error) { - details, err := NewEventDetails(detailsRaw) - if err != nil { - return SentDetails{}, err - } +func NewSentDetails(response WebhookResponse) (SentDetails, error) { sentDetails := SentDetails{ CampaignID: response.CampaignID, - ID: details.ID(), - Address: details.Address(), Email: response.Email, - UserAgent: details.UserAgent(), } return sentDetails, nil } @@ -185,9 +160,6 @@ func NewSentDetails(response WebhookResponse, detailsRaw []byte) (SentDetails, e func (w SentDetails) SendSlack() error { orange := "#ffa500" attachment := slack.Attachment{Title: &EmailSent, Color: &orange} - attachment.AddField(slack.Field{Title: "ID", Value: w.ID}) - attachment.AddField(slack.Field{Title: "Address", Value: slackFormatIP(w.Address)}) - attachment.AddField(slack.Field{Title: "User Agent", Value: w.UserAgent}) if !viper.GetBool("slack.disable_credentials") { attachment.AddField(slack.Field{Title: "Email", Value: w.Email}) } @@ -206,10 +178,8 @@ func (w SentDetails) SendEmail() error { func (w SentDetails) SendGraphql() error { oplog_entry := ghostwriterOplogEntry{ - SourceIp: w.Address, UserContext: w.Email, - Description: "User ID: " + w.ID + "\nCampaign ID: " + strconv.FormatUint(uint64(w.CampaignID), 10), - Output: "UserAgent: " + w.UserAgent, + Description: "Campaign ID: " + strconv.FormatUint(uint64(w.CampaignID), 10), Comments: EmailSent, } return sendGraphql(oplog_entry) @@ -407,23 +377,13 @@ func (w SubmittedDetails) SendGraphql() error { type ReportedDetails struct { CampaignID uint - ID string Email string - Address string - UserAgent string } -func NewReportedDetails(response WebhookResponse, detailsRaw []byte) (ReportedDetails, error) { - details, err := NewEventDetails(detailsRaw) - if err != nil { - return ReportedDetails{}, err - } +func NewReportedDetails(response WebhookResponse) (ReportedDetails, error) { reportedDetails := ReportedDetails{ CampaignID: response.CampaignID, - ID: details.ID(), - Address: details.Address(), Email: response.Email, - UserAgent: details.UserAgent(), } return reportedDetails, nil } @@ -431,9 +391,6 @@ func NewReportedDetails(response WebhookResponse, detailsRaw []byte) (ReportedDe func (w ReportedDetails) SendSlack() error { orange := "#ffa500" attachment := slack.Attachment{Title: &EmailReported, Color: &orange} - attachment.AddField(slack.Field{Title: "ID", Value: w.ID}) - attachment.AddField(slack.Field{Title: "Address", Value: slackFormatIP(w.Address)}) - attachment.AddField(slack.Field{Title: "User Agent", Value: w.UserAgent}) if !viper.GetBool("slack.disable_credentials") { attachment.AddField(slack.Field{Title: "Email", Value: w.Email}) } @@ -452,10 +409,8 @@ func (w ReportedDetails) SendEmail() error { func (w ReportedDetails) SendGraphql() error { oplog_entry := ghostwriterOplogEntry{ - SourceIp: w.Address, UserContext: w.Email, - Description: "User ID: " + w.ID + "\nCampaign ID: " + strconv.FormatUint(uint64(w.CampaignID), 10), - Output: "UserAgent: " + w.UserAgent, + Description: "Campaign ID: " + strconv.FormatUint(uint64(w.CampaignID), 10), Comments: EmailReported, } return sendGraphql(oplog_entry) From 5f8874679f549532c5cbdcaffeb4a5a90856d493 Mon Sep 17 00:00:00 2001 From: Dom Whewell Date: Sun, 9 Jun 2024 18:50:33 +0100 Subject: [PATCH 3/5] Modify `sendGraphql` for optional strings --- sending_helpers.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/sending_helpers.go b/sending_helpers.go index b7a93bd..e698ca8 100644 --- a/sending_helpers.go +++ b/sending_helpers.go @@ -79,12 +79,22 @@ func sendGraphql(data ghostwriterOplogEntry) error { req := graphql.NewRequest(query) req.Header.Set("Authorization", "Bearer "+apiKey) req.Var("oplog", oplogId) - req.Var("sourceIp", data.SourceIp) + if data.SourceIp != "" { + req.Var("sourceIp", data.SourceIp) + } req.Var("tool", "gophish") - req.Var("userContext", data.UserContext) - req.Var("description", data.Description) - req.Var("output", data.Output) - req.Var("comments", data.Comments) + if data.UserContext != "" { + req.Var("userContext", data.UserContext) + } + if data.Description != "" { + req.Var("description", data.Description) + } + if data.Output != "" { + req.Var("output", data.Output) + } + if data.Comments != "" { + req.Var("comments", data.Comments) + } req.Var("extraFields", "") ctx := context.Background() From 34897e0631d94f7b6e0af375781e6ec9cfc403b7 Mon Sep 17 00:00:00 2001 From: Dom Whewell Date: Sun, 9 Jun 2024 19:04:33 +0100 Subject: [PATCH 4/5] Check `events` in config --- config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.go b/config.go index 376c34f..9bd48a7 100644 --- a/config.go +++ b/config.go @@ -78,7 +78,7 @@ func validateConfig() { } } - globalConfigs := []string{"secret", "profiles"} + globalConfigs := []string{"secret", "profiles", "events"} checkKeysExist(globalConfigs...) profiles := viper.GetStringSlice("profiles") From ce5eab2e6d0cec7bf07faa5a8b514ca89f1815a0 Mon Sep 17 00:00:00 2001 From: Dom Whewell Date: Sun, 9 Jun 2024 19:13:28 +0100 Subject: [PATCH 5/5] Set default email templates --- config.go | 9 +++++++++ messages.go | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index 9bd48a7..bfbd596 100644 --- a/config.go +++ b/config.go @@ -5,6 +5,10 @@ import ( "github.com/spf13/viper" ) +var defaultErrorTemplate = `Email ID - {{ .ID }}` + +var defaultSentTemplate = `Email ID - {{ .ID }}` + var defaultClickedTemplate = `Email ID - {{ .ID }} Email Address - {{ .Email }} IP Address - {{ .Address }} @@ -22,6 +26,8 @@ Email Address - {{ .Email }} IP Address - {{ .Address }} User Agent - {{ .UserAgent }}` +var defaultReportedTemplate = `Email ID - {{ .ID }}` + var defaultgraphqlTemplate = `mutation InsertGophishLog ($oplog: bigint!, $sourceIp: String, $tool: String, $userContext: String, $description: String, $output: String, $comments: String, $extraFields: jsonb!) { insert_oplogEntry(objects: {oplog: $oplog, sourceIp: $sourceIp, tool: $tool, userContext: $userContext, description: $description, comments: $comments, output: $output, extraFields: $extraFields}) { returning { @@ -53,9 +59,12 @@ func setDefaults() { viper.SetDefault("ip_query_base", "https://whatismyipaddress.com/ip/") viper.SetDefault("listen_port", "9999") viper.SetDefault("webhook_path", "/webhook") + viper.SetDefault("email_error_sending_template", defaultErrorTemplate) + viper.SetDefault("email_sent_template", defaultSentTemplate) viper.SetDefault("email_send_click_template", defaultClickedTemplate) viper.SetDefault("email_submitted_credentials_template", defaultSubmittedCredentailsTemplate) viper.SetDefault("email_default_email_open_template", defaultEmailOpenedTemplate) + viper.SetDefault("email_reported_template", defaultReportedTemplate) viper.SetDefault("graphql_default_query", defaultgraphqlTemplate) viper.SetDefault("profiles", []string{"slack"}) viper.SetDefault("events", []string{"email_opened", "clicked_link", "submitted_data"}) diff --git a/messages.go b/messages.go index 108c4bc..5e747bc 100644 --- a/messages.go +++ b/messages.go @@ -127,7 +127,7 @@ func (w ErrorDetails) SendSlack() error { } func (w ErrorDetails) SendEmail() error { - templateString := viper.GetString("email_send_click_template") + templateString := viper.GetString("email_error_sending_template") body, err := getEmailBody(templateString, w) if err != nil { return err @@ -168,7 +168,7 @@ func (w SentDetails) SendSlack() error { } func (w SentDetails) SendEmail() error { - templateString := viper.GetString("email_send_click_template") + templateString := viper.GetString("email_sent_template") body, err := getEmailBody(templateString, w) if err != nil { return err @@ -399,7 +399,7 @@ func (w ReportedDetails) SendSlack() error { } func (w ReportedDetails) SendEmail() error { - templateString := viper.GetString("email_send_click_template") + templateString := viper.GetString("email_reported_template") body, err := getEmailBody(templateString, w) if err != nil { return err