mirror of https://github.com/gophish/gophish
Working on tracking and email handling - want to make it as smooth as possible
Removed flash that shouldn't have been on the campaigns page Added small time delay to prevent connection overload - might remove it later, but it'll be trickypull/24/head
parent
03b25f5fee
commit
7af35237a7
|
@ -67,10 +67,32 @@ func CreateAdminRouter() http.Handler {
|
||||||
func CreatePhishingRouter() http.Handler {
|
func CreatePhishingRouter() http.Handler {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
router.PathPrefix("/static").Handler(http.FileServer(http.Dir("./static/endpoint/")))
|
router.PathPrefix("/static").Handler(http.FileServer(http.Dir("./static/endpoint/")))
|
||||||
|
router.HandleFunc("/track", PhishTracker)
|
||||||
router.HandleFunc("/{path:.*}", PhishHandler)
|
router.HandleFunc("/{path:.*}", PhishHandler)
|
||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PhishTracker tracks emails as they are opened, updating the status for the given Result
|
||||||
|
func PhishTracker(w http.ResponseWriter, r *http.Request) {
|
||||||
|
r.ParseForm()
|
||||||
|
id := r.Form.Get("rid")
|
||||||
|
if id == "" {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rs, err := models.GetResult(id)
|
||||||
|
if err != nil {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c, err := models.GetCampaign(rs.CampaignId, rs.UserId)
|
||||||
|
if err != nil {
|
||||||
|
Logger.Println(err)
|
||||||
|
}
|
||||||
|
c.AddEvent(models.Event{Email: rs.Email, Message: models.EVENT_OPENED})
|
||||||
|
w.Write([]byte("It Works!"))
|
||||||
|
}
|
||||||
|
|
||||||
// PhishHandler handles incoming client connections and registers the associated actions performed
|
// PhishHandler handles incoming client connections and registers the associated actions performed
|
||||||
// (such as clicked link, etc.)
|
// (such as clicked link, etc.)
|
||||||
func PhishHandler(w http.ResponseWriter, r *http.Request) {
|
func PhishHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -22,11 +22,6 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" ng-controller="CampaignResultsCtrl">
|
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" ng-controller="CampaignResultsCtrl">
|
||||||
<div ng-show="campaign">
|
<div ng-show="campaign">
|
||||||
<div class="row">
|
|
||||||
<div class="alert alert-info">
|
|
||||||
No groups created yet. Let's create one!
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<h1 class="page-header">Results for {{campaign.name}}</h1>
|
<h1 class="page-header">Results for {{campaign.name}}</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,15 +3,18 @@ package worker
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jordan-wright/email"
|
"github.com/jordan-wright/email"
|
||||||
"github.com/jordan-wright/gophish/models"
|
"github.com/jordan-wright/gophish/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Logger is the logger for the worker
|
||||||
var Logger = log.New(os.Stdout, " ", log.Ldate|log.Ltime|log.Lshortfile)
|
var Logger = log.New(os.Stdout, " ", log.Ldate|log.Ltime|log.Lshortfile)
|
||||||
|
|
||||||
// Worker is the background worker that handles watching for new campaigns and sending emails appropriately.
|
// Worker is the background worker that handles watching for new campaigns and sending emails appropriately.
|
||||||
|
@ -19,6 +22,7 @@ type Worker struct {
|
||||||
Queue chan *models.Campaign
|
Queue chan *models.Campaign
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New creates a new worker object to handle the creation of campaigns
|
||||||
func New() *Worker {
|
func New() *Worker {
|
||||||
return &Worker{
|
return &Worker{
|
||||||
Queue: make(chan *models.Campaign),
|
Queue: make(chan *models.Campaign),
|
||||||
|
@ -48,40 +52,57 @@ func processCampaign(c *models.Campaign) {
|
||||||
if c.SMTP.Username != "" && c.SMTP.Password != "" {
|
if c.SMTP.Username != "" && c.SMTP.Password != "" {
|
||||||
auth = smtp.PlainAuth("", c.SMTP.Username, c.SMTP.Password, strings.Split(c.SMTP.Host, ":")[0])
|
auth = smtp.PlainAuth("", c.SMTP.Username, c.SMTP.Password, strings.Split(c.SMTP.Host, ":")[0])
|
||||||
}
|
}
|
||||||
|
ips, err := net.InterfaceAddrs()
|
||||||
|
if err != nil {
|
||||||
|
Logger.Println(err)
|
||||||
|
}
|
||||||
|
for _, i := range ips {
|
||||||
|
Logger.Println(i.String())
|
||||||
|
}
|
||||||
for _, t := range c.Results {
|
for _, t := range c.Results {
|
||||||
|
td := struct {
|
||||||
|
models.Result
|
||||||
|
URL string
|
||||||
|
Tracker string
|
||||||
|
}{
|
||||||
|
t,
|
||||||
|
"http://" + ips[0].String() + "?rid=" + t.RId,
|
||||||
|
"http://" + ips[0].String() + "/track?rid=" + t.RId,
|
||||||
|
}
|
||||||
// Parse the templates
|
// Parse the templates
|
||||||
var subj_buff bytes.Buffer
|
var subjBuff bytes.Buffer
|
||||||
var html_buff bytes.Buffer
|
var htmlBuff bytes.Buffer
|
||||||
var text_buff bytes.Buffer
|
var textBuff bytes.Buffer
|
||||||
tmpl, err := template.New("html_template").Parse(c.Template.HTML)
|
tmpl, err := template.New("html_template").Parse(c.Template.HTML)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Println(err)
|
Logger.Println(err)
|
||||||
}
|
}
|
||||||
err = tmpl.Execute(&html_buff, t)
|
err = tmpl.Execute(&htmlBuff, td)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Println(err)
|
Logger.Println(err)
|
||||||
}
|
}
|
||||||
e.HTML = html_buff.Bytes()
|
e.HTML = htmlBuff.Bytes()
|
||||||
tmpl, err = template.New("text_template").Parse(c.Template.Text)
|
tmpl, err = template.New("text_template").Parse(c.Template.Text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Println(err)
|
Logger.Println(err)
|
||||||
}
|
}
|
||||||
err = tmpl.Execute(&text_buff, t)
|
err = tmpl.Execute(&textBuff, td)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Println(err)
|
Logger.Println(err)
|
||||||
}
|
}
|
||||||
e.Text = text_buff.Bytes()
|
e.Text = textBuff.Bytes()
|
||||||
tmpl, err = template.New("text_template").Parse(c.Template.Subject)
|
tmpl, err = template.New("text_template").Parse(c.Template.Subject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Println(err)
|
Logger.Println(err)
|
||||||
}
|
}
|
||||||
err = tmpl.Execute(&subj_buff, t)
|
err = tmpl.Execute(&subjBuff, td)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Println(err)
|
Logger.Println(err)
|
||||||
}
|
}
|
||||||
e.Subject = string(subj_buff.Bytes())
|
e.Subject = string(subjBuff.Bytes())
|
||||||
Logger.Println("Creating email using template")
|
Logger.Println("Creating email using template")
|
||||||
e.To = []string{t.Email}
|
e.To = []string{t.Email}
|
||||||
|
Logger.Printf("Sending Email to %s\n", t.Email)
|
||||||
err = e.Send(c.SMTP.Host, auth)
|
err = e.Send(c.SMTP.Host, auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Println(err)
|
Logger.Println(err)
|
||||||
|
@ -95,6 +116,6 @@ func processCampaign(c *models.Campaign) {
|
||||||
Logger.Println(err)
|
Logger.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Logger.Printf("Sending Email to %s\n", t.Email)
|
time.Sleep(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue