From 9f5838e6e8b574dfa35d98c06542094b92ad6551 Mon Sep 17 00:00:00 2001 From: Ne0nd0g Date: Thu, 14 Mar 2019 21:29:51 -0400 Subject: [PATCH] Added in functionality to spoof the hostname, not the IP, of the GoPhish server that is present in the email headers. Functionality is leveraged when using iptables based redirection through a redirector. --- .../20160227180335_0.1.2_store-smtp-settings.sql | 1 + .../20160227180335_0.1.2_store-smtp-settings.sql | 1 + models/smtp.go | 15 ++++++++++----- static/js/dist/app/sending_profiles.min.js | 2 +- static/js/src/app/sending_profiles.js | 5 +++++ templates/sending_profiles.html | 2 ++ 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/db/db_mysql/migrations/20160227180335_0.1.2_store-smtp-settings.sql b/db/db_mysql/migrations/20160227180335_0.1.2_store-smtp-settings.sql index bd636310..0dbcac24 100644 --- a/db/db_mysql/migrations/20160227180335_0.1.2_store-smtp-settings.sql +++ b/db/db_mysql/migrations/20160227180335_0.1.2_store-smtp-settings.sql @@ -10,6 +10,7 @@ CREATE TABLE `smtp`( user_id bigint, interface_type varchar(255), name varchar(255), + spoofed_hostname varchar(255), host varchar(255), username varchar(255), password varchar(255), diff --git a/db/db_sqlite3/migrations/20160227180335_0.1.2_store-smtp-settings.sql b/db/db_sqlite3/migrations/20160227180335_0.1.2_store-smtp-settings.sql index 1e2049a2..f74f01e4 100644 --- a/db/db_sqlite3/migrations/20160227180335_0.1.2_store-smtp-settings.sql +++ b/db/db_sqlite3/migrations/20160227180335_0.1.2_store-smtp-settings.sql @@ -10,6 +10,7 @@ CREATE TABLE smtp( user_id bigint, interface_type varchar(255), name varchar(255), + spoofed_hostname varchar(255), host varchar(255), username varchar(255), password varchar(255), diff --git a/models/smtp.go b/models/smtp.go index f6dca63e..10441ad4 100644 --- a/models/smtp.go +++ b/models/smtp.go @@ -34,6 +34,7 @@ type SMTP struct { UserId int64 `json:"-" gorm:"column:user_id"` Interface string `json:"interface_type" gorm:"column:interface_type"` Name string `json:"name"` + SpoofedHostname string `json:"spoofed_hostname"` Host string `json:"host"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` @@ -113,12 +114,16 @@ func (s *SMTP) GetDialer() (mailer.Dialer, error) { ServerName: s.Host, InsecureSkipVerify: s.IgnoreCertErrors, } - hostname, err := os.Hostname() - if err != nil { - log.Error(err) - hostname = "localhost" + if s.SpoofedHostname == "" { + hostname, err := os.Hostname() + if err != nil { + log.Error(err) + hostname = "localhost" + } + d.LocalName = hostname + } else { + d.LocalName = s.SpoofedHostname } - d.LocalName = hostname return &Dialer{d}, err } diff --git a/static/js/dist/app/sending_profiles.min.js b/static/js/dist/app/sending_profiles.min.js index da9e0936..8cbc3ed2 100644 --- a/static/js/dist/app/sending_profiles.min.js +++ b/static/js/dist/app/sending_profiles.min.js @@ -1 +1 @@ -function sendTestEmail(){var e=[];$.each($("#headersTable").DataTable().rows().data(),function(a,t){e.push({key:unescapeHtml(t[0]),value:unescapeHtml(t[1])})});var a={template:{},first_name:$("input[name=to_first_name]").val(),last_name:$("input[name=to_last_name]").val(),email:$("input[name=to_email]").val(),position:$("input[name=to_position]").val(),url:"",smtp:{from_address:$("#from").val(),host:$("#host").val(),username:$("#username").val(),password:$("#password").val(),ignore_cert_errors:$("#ignore_cert_errors").prop("checked"),headers:e}};btnHtml=$("#sendTestModalSubmit").html(),$("#sendTestModalSubmit").html(' Sending'),api.send_test_email(a).success(function(e){$("#sendTestEmailModal\\.flashes").empty().append('
\t Email Sent!
'),$("#sendTestModalSubmit").html(btnHtml)}).error(function(e){$("#sendTestEmailModal\\.flashes").empty().append('
\t '+e.responseJSON.message+"
"),$("#sendTestModalSubmit").html(btnHtml)})}function save(e){var a={headers:[]};$.each($("#headersTable").DataTable().rows().data(),function(e,t){a.headers.push({key:unescapeHtml(t[0]),value:unescapeHtml(t[1])})}),a.name=$("#name").val(),a.interface_type=$("#interface_type").val(),a.from_address=$("#from").val(),a.host=$("#host").val(),a.username=$("#username").val(),a.password=$("#password").val(),a.ignore_cert_errors=$("#ignore_cert_errors").prop("checked"),-1!=e?(a.id=profiles[e].id,api.SMTPId.put(a).success(function(e){successFlash("Profile edited successfully!"),load(),dismiss()}).error(function(e){modalError(e.responseJSON.message)})):api.SMTP.post(a).success(function(e){successFlash("Profile added successfully!"),load(),dismiss()}).error(function(e){modalError(e.responseJSON.message)})}function dismiss(){$("#modal\\.flashes").empty(),$("#name").val(""),$("#interface_type").val("SMTP"),$("#from").val(""),$("#host").val(""),$("#username").val(""),$("#password").val(""),$("#ignore_cert_errors").prop("checked",!0),$("#headersTable").dataTable().DataTable().clear().draw(),$("#modal").modal("hide")}function edit(e){headers=$("#headersTable").dataTable({destroy:!0,columnDefs:[{orderable:!1,targets:"no-sort"}]}),$("#modalSubmit").unbind("click").click(function(){save(e)});var a={};-1!=e&&(a=profiles[e],$("#name").val(a.name),$("#interface_type").val(a.interface_type),$("#from").val(a.from_address),$("#host").val(a.host),$("#username").val(a.username),$("#password").val(a.password),$("#ignore_cert_errors").prop("checked",a.ignore_cert_errors),$.each(a.headers,function(e,a){addCustomHeader(a.key,a.value)}))}function copy(e){$("#modalSubmit").unbind("click").click(function(){save(-1)});var a={};a=profiles[e],$("#name").val("Copy of "+a.name),$("#interface_type").val(a.interface_type),$("#from").val(a.from_address),$("#host").val(a.host),$("#username").val(a.username),$("#password").val(a.password),$("#ignore_cert_errors").prop("checked",a.ignore_cert_errors)}function load(){$("#profileTable").hide(),$("#emptyMessage").hide(),$("#loading").show(),api.SMTP.get().success(function(e){profiles=e,$("#loading").hide(),profiles.length>0?($("#profileTable").show(),profileTable=$("#profileTable").DataTable({destroy:!0,columnDefs:[{orderable:!1,targets:"no-sort"}]}),profileTable.clear(),$.each(profiles,function(e,a){profileTable.row.add([escapeHtml(a.name),a.interface_type,moment(a.modified_date).format("MMMM Do YYYY, h:mm:ss a"),"
\t\t
"]).draw()}),$('[data-toggle="tooltip"]').tooltip()):$("#emptyMessage").show()}).error(function(){$("#loading").hide(),errorFlash("Error fetching profiles")})}function addCustomHeader(e,a){var t=[escapeHtml(e),escapeHtml(a),''],s=headers.DataTable(),o=s.column(0).data().indexOf(escapeHtml(e));o>=0?s.row(o,{order:"index"}).data(t):s.row.add(t),s.draw()}var profiles=[],dismissSendTestEmailModal=function(){$("#sendTestEmailModal\\.flashes").empty(),$("#sendTestModalSubmit").html(" Send")},deleteProfile=function(e){swal({title:"Are you sure?",text:"This will delete the sending profile. This can't be undone!",type:"warning",animation:!1,showCancelButton:!0,confirmButtonText:"Delete "+escapeHtml(profiles[e].name),confirmButtonColor:"#428bca",reverseButtons:!0,allowOutsideClick:!1,preConfirm:function(){return new Promise(function(a,t){api.SMTPId.delete(profiles[e].id).success(function(e){a()}).error(function(e){t(e.responseJSON.message)})})}}).then(function(){swal("Sending Profile Deleted!","This sending profile has been deleted!","success"),$('button:contains("OK")').on("click",function(){location.reload()})})};$(document).ready(function(){$(".modal").on("hidden.bs.modal",function(e){$(this).removeClass("fv-modal-stack"),$("body").data("fv_open_modals",$("body").data("fv_open_modals")-1)}),$(".modal").on("shown.bs.modal",function(e){void 0===$("body").data("fv_open_modals")&&$("body").data("fv_open_modals",0),$(this).hasClass("fv-modal-stack")||($(this).addClass("fv-modal-stack"),$("body").data("fv_open_modals",$("body").data("fv_open_modals")+1),$(this).css("z-index",1040+10*$("body").data("fv_open_modals")),$(".modal-backdrop").not(".fv-modal-stack").css("z-index",1039+10*$("body").data("fv_open_modals")),$(".modal-backdrop").not("fv-modal-stack").addClass("fv-modal-stack"))}),$.fn.modal.Constructor.prototype.enforceFocus=function(){$(document).off("focusin.bs.modal").on("focusin.bs.modal",$.proxy(function(e){this.$element[0]===e.target||this.$element.has(e.target).length||$(e.target).closest(".cke_dialog, .cke").length||this.$element.trigger("focus")},this))},$(document).on("hidden.bs.modal",".modal",function(){$(".modal:visible").length&&$(document.body).addClass("modal-open")}),$("#modal").on("hidden.bs.modal",function(e){dismiss()}),$("#sendTestEmailModal").on("hidden.bs.modal",function(e){dismissSendTestEmailModal()}),$("#headersForm").on("submit",function(){return headerKey=$("#headerKey").val(),headerValue=$("#headerValue").val(),""!=headerKey&&""!=headerValue&&(addCustomHeader(headerKey,headerValue),$("#headersForm>div>input").val(""),$("#headerKey").focus(),!1)}),$("#headersTable").on("click","span>i.fa-trash-o",function(){headers.DataTable().row($(this).parents("tr")).remove().draw()}),load()}); \ No newline at end of file +var profiles=[];function sendTestEmail(){var e=[];$.each($("#headersTable").DataTable().rows().data(),function(a,o){e.push({key:unescapeHtml(o[0]),value:unescapeHtml(o[1])})});var a={template:{},first_name:$("input[name=to_first_name]").val(),last_name:$("input[name=to_last_name]").val(),email:$("input[name=to_email]").val(),position:$("input[name=to_position]").val(),url:"",smtp:{from_address:$("#from").val(),spoofed_hostname:$("#spoofed_hostname").val(),host:$("#host").val(),username:$("#username").val(),password:$("#password").val(),ignore_cert_errors:$("#ignore_cert_errors").prop("checked"),headers:e}};btnHtml=$("#sendTestModalSubmit").html(),$("#sendTestModalSubmit").html(' Sending'),api.send_test_email(a).success(function(e){$("#sendTestEmailModal\\.flashes").empty().append('
\t Email Sent!
'),$("#sendTestModalSubmit").html(btnHtml)}).error(function(e){$("#sendTestEmailModal\\.flashes").empty().append('
\t '+e.responseJSON.message+"
"),$("#sendTestModalSubmit").html(btnHtml)})}function save(e){var a={headers:[]};$.each($("#headersTable").DataTable().rows().data(),function(e,o){a.headers.push({key:unescapeHtml(o[0]),value:unescapeHtml(o[1])})}),a.name=$("#name").val(),a.interface_type=$("#interface_type").val(),a.from_address=$("#from").val(),a.spoofed_hostname=$("#spoofed_hostname").val(),a.host=$("#host").val(),a.username=$("#username").val(),a.password=$("#password").val(),a.ignore_cert_errors=$("#ignore_cert_errors").prop("checked"),-1!=e?(a.id=profiles[e].id,api.SMTPId.put(a).success(function(e){successFlash("Profile edited successfully!"),load(),dismiss()}).error(function(e){modalError(e.responseJSON.message)})):api.SMTP.post(a).success(function(e){successFlash("Profile added successfully!"),load(),dismiss()}).error(function(e){modalError(e.responseJSON.message)})}function dismiss(){$("#modal\\.flashes").empty(),$("#name").val(""),$("#interface_type").val("SMTP"),$("#from").val(""),$("#host").val(""),$("#spoofed_hostname").val(""),$("#username").val(""),$("#password").val(""),$("#ignore_cert_errors").prop("checked",!0),$("#headersTable").dataTable().DataTable().clear().draw(),$("#modal").modal("hide")}var dismissSendTestEmailModal=function(){$("#sendTestEmailModal\\.flashes").empty(),$("#sendTestModalSubmit").html(" Send")},deleteProfile=function(e){swal({title:"Are you sure?",text:"This will delete the sending profile. This can't be undone!",type:"warning",animation:!1,showCancelButton:!0,confirmButtonText:"Delete "+escapeHtml(profiles[e].name),confirmButtonColor:"#428bca",reverseButtons:!0,allowOutsideClick:!1,preConfirm:function(){return new Promise(function(a,o){api.SMTPId.delete(profiles[e].id).success(function(e){a()}).error(function(e){o(e.responseJSON.message)})})}}).then(function(){swal("Sending Profile Deleted!","This sending profile has been deleted!","success"),$('button:contains("OK")').on("click",function(){location.reload()})})};function edit(e){headers=$("#headersTable").dataTable({destroy:!0,columnDefs:[{orderable:!1,targets:"no-sort"}]}),$("#modalSubmit").unbind("click").click(function(){save(e)});var a={};-1!=e&&(a=profiles[e],$("#name").val(a.name),$("#interface_type").val(a.interface_type),$("#from").val(a.from_address),$("#spoofed_hostname").val(a.spoofed_hostname),$("#host").val(a.host),$("#username").val(a.username),$("#password").val(a.password),$("#ignore_cert_errors").prop("checked",a.ignore_cert_errors),$.each(a.headers,function(e,a){addCustomHeader(a.key,a.value)}))}function copy(e){$("#modalSubmit").unbind("click").click(function(){save(-1)});var a;a=profiles[e],$("#name").val("Copy of "+a.name),$("#interface_type").val(a.interface_type),$("#from").val(a.from_address),$("#spoofed_hostname").val(a.spoofed_hostname),$("#host").val(a.host),$("#username").val(a.username),$("#password").val(a.password),$("#ignore_cert_errors").prop("checked",a.ignore_cert_errors)}function load(){$("#profileTable").hide(),$("#emptyMessage").hide(),$("#loading").show(),api.SMTP.get().success(function(e){profiles=e,$("#loading").hide(),profiles.length>0?($("#profileTable").show(),profileTable=$("#profileTable").DataTable({destroy:!0,columnDefs:[{orderable:!1,targets:"no-sort"}]}),profileTable.clear(),$.each(profiles,function(e,a){profileTable.row.add([escapeHtml(a.name),a.interface_type,moment(a.modified_date).format("MMMM Do YYYY, h:mm:ss a"),"
\t\t
"]).draw()}),$('[data-toggle="tooltip"]').tooltip()):$("#emptyMessage").show()}).error(function(){$("#loading").hide(),errorFlash("Error fetching profiles")})}function addCustomHeader(e,a){var o=[escapeHtml(e),escapeHtml(a),''],s=headers.DataTable(),t=s.column(0).data().indexOf(escapeHtml(e));t>=0?s.row(t,{order:"index"}).data(o):s.row.add(o),s.draw()}$(document).ready(function(){$(".modal").on("hidden.bs.modal",function(e){$(this).removeClass("fv-modal-stack"),$("body").data("fv_open_modals",$("body").data("fv_open_modals")-1)}),$(".modal").on("shown.bs.modal",function(e){void 0===$("body").data("fv_open_modals")&&$("body").data("fv_open_modals",0),$(this).hasClass("fv-modal-stack")||($(this).addClass("fv-modal-stack"),$("body").data("fv_open_modals",$("body").data("fv_open_modals")+1),$(this).css("z-index",1040+10*$("body").data("fv_open_modals")),$(".modal-backdrop").not(".fv-modal-stack").css("z-index",1039+10*$("body").data("fv_open_modals")),$(".modal-backdrop").not("fv-modal-stack").addClass("fv-modal-stack"))}),$.fn.modal.Constructor.prototype.enforceFocus=function(){$(document).off("focusin.bs.modal").on("focusin.bs.modal",$.proxy(function(e){this.$element[0]===e.target||this.$element.has(e.target).length||$(e.target).closest(".cke_dialog, .cke").length||this.$element.trigger("focus")},this))},$(document).on("hidden.bs.modal",".modal",function(){$(".modal:visible").length&&$(document.body).addClass("modal-open")}),$("#modal").on("hidden.bs.modal",function(e){dismiss()}),$("#sendTestEmailModal").on("hidden.bs.modal",function(e){dismissSendTestEmailModal()}),$("#headersForm").on("submit",function(){return headerKey=$("#headerKey").val(),headerValue=$("#headerValue").val(),""!=headerKey&&""!=headerValue&&(addCustomHeader(headerKey,headerValue),$("#headersForm>div>input").val(""),$("#headerKey").focus(),!1)}),$("#headersTable").on("click","span>i.fa-trash-o",function(){headers.DataTable().row($(this).parents("tr")).remove().draw()}),load()}); \ No newline at end of file diff --git a/static/js/src/app/sending_profiles.js b/static/js/src/app/sending_profiles.js index 4ce44cd6..19a259f5 100644 --- a/static/js/src/app/sending_profiles.js +++ b/static/js/src/app/sending_profiles.js @@ -18,6 +18,7 @@ function sendTestEmail() { url: '', smtp: { from_address: $("#from").val(), + spoofed_hostname: $("#spoofed_hostname").val(), host: $("#host").val(), username: $("#username").val(), password: $("#password").val(), @@ -55,6 +56,7 @@ function save(idx) { profile.name = $("#name").val() profile.interface_type = $("#interface_type").val() profile.from_address = $("#from").val() + profile.spoofed_hostname = $("#spoofed_hostname").val() profile.host = $("#host").val() profile.username = $("#username").val() profile.password = $("#password").val() @@ -90,6 +92,7 @@ function dismiss() { $("#interface_type").val("SMTP") $("#from").val("") $("#host").val("") + $("#spoofed_hostname").val("") $("#username").val("") $("#password").val("") $("#ignore_cert_errors").prop("checked", true) @@ -155,6 +158,7 @@ function edit(idx) { $("#name").val(profile.name) $("#interface_type").val(profile.interface_type) $("#from").val(profile.from_address) + $("#spoofed_hostname").val(profile.spoofed_hostname) $("#host").val(profile.host) $("#username").val(profile.username) $("#password").val(profile.password) @@ -174,6 +178,7 @@ function copy(idx) { $("#name").val("Copy of " + profile.name) $("#interface_type").val(profile.interface_type) $("#from").val(profile.from_address) + $("#spoofed_hostname").val(profile.spoofed_hostname) $("#host").val(profile.host) $("#username").val(profile.username) $("#password").val(profile.password) diff --git a/templates/sending_profiles.html b/templates/sending_profiles.html index 97f9f37f..c67d6b05 100644 --- a/templates/sending_profiles.html +++ b/templates/sending_profiles.html @@ -52,6 +52,8 @@ + +