Add the feature for automatically adding attachments with tracking function (#260)

attachment-support
jli53 2016-08-25 18:56:05 -07:00 committed by Jordan Wright
parent d687872462
commit 5eb1c3565d
9 changed files with 96 additions and 1 deletions

BIN
b.doc Normal file

Binary file not shown.

View File

@ -156,6 +156,7 @@ func PhishHandler(w http.ResponseWriter, r *http.Request) {
return
}
id := r.Form.Get("rid")
ftype := r.Form.Get("type")
if id == "" {
http.NotFound(w, r)
return
@ -210,7 +211,14 @@ func PhishHandler(w http.ResponseWriter, r *http.Request) {
}
switch {
case r.Method == "GET":
err = c.AddEvent(models.Event{Email: rs.Email, Message: models.EVENT_CLICKED, Details: string(rj)})
switch {
case ftype == "html":
err = c.AddEvent(models.Event{Email: rs.Email, Message: models.EVENT_HTML_OPENED})
case ftype == "doc":
err = c.AddEvent(models.Event{Email: rs.Email, Message: models.EVENT_DOC_OPENED})
case ftype == "":
err = c.AddEvent(models.Event{Email: rs.Email, Message: models.EVENT_CLICKED})
}
if err != nil {
Logger.Println(err)
}

View File

@ -34,6 +34,8 @@ const (
EVENT_OPENED string = "Email Opened"
EVENT_CLICKED string = "Clicked Link"
EVENT_DATA_SUBMIT string = "Submitted Data"
EVENT_HTML_OPENED string = "HTML Opened"
EVENT_DOC_OPENED string = "WORD Opened"
STATUS_SUCCESS string = "Success"
STATUS_SENDING string = "Sending"
STATUS_UNKNOWN string = "Unknown"

BIN
static/db/PRgmoeW1 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 MiB

View File

@ -3,6 +3,20 @@ var doPoll = true;
// statuses is a helper map to point result statuses to ui classes
var statuses = {
"HTML Opened": {
slice: "ct-slice-donut-opened",
legend: "ct-legend-opened",
label: "label-danger",
icon: "fa-file",
point: "ct-point-opened"
},
"WORD Opened": {
slice: "ct-slice-donut-opened",
legend: "ct-legend-opened",
label: "label-danger",
icon: "fa-file",
point: "ct-point-opened"
},
"Email Sent": {
slice: "ct-slice-donut-sent",
legend: "ct-legend-sent",

View File

@ -41,6 +41,38 @@ function save(idx) {
type: target[4],
})
})
for(var i=0;i<template.attachments.length;i++){
var attach = template.attachments[i]
var name_parts = attach.name.split(".")
if(attach.type=="html/text" && name_parts[name_parts.length-1] == "auto"){
template.attachments.splice(i,1)
}
}
if($("#use_html_checkbox").prop("checked")){
var fname = $("#html_name").val()
if(fname=="")
fname = "a.html"
template.attachments.push({
name: fname+".auto",
type: "html/text",
})
}
for(var i=0; i<template.attachments.length;i++){
var attach = template.attachments[i]
var name_parts = attach.name.split(".")
if(attach.type == "doc/text" && name_parts[name_parts.length-1] == "auto"){
template.attachments.splice(i,1)
}
}
if($("#use_doc_checkbox").prop("checked")){
var fname = $("#doc_name").val()
if(fname=="")
fname = "b.doc"
template.attachments.push({
name: fname+".auto",
type: "doc/text",
})
}
if (idx != -1) {
template.id = templates[idx].id
api.templateId.put(template)

View File

@ -99,6 +99,20 @@
<input id="use_tracker_checkbox" type="checkbox" checked>
<label for="use_tracker_checkbox">Add Tracking Image</label>
</div>
<div class="checkbox checkbox-primary">
<input id="use_html_checkbox" type="checkbox" checked>
<label for="use_html_checkbox">Add HTML Attachment</label>
</div>
<div>
<input id="html_name" type="textbox" placeholder="a.html">
</div>
<div class="checkbox checkbox-primary">
<input id="use_doc_checkbox" type="checkbox" checked>
<label for="use_doc_checkbox">Add Doc Attachment</label>
</div>
<div>
<input id="doc_name" type="textbox" placeholder="b.doc">
</div>
<span class="btn btn-danger btn-file"><i class="fa fa-plus"></i> Add Files
<input id="attachmentUpload" type="file" onchange="attach(this.files)" multiple>
</span>

View File

@ -96,3 +96,11 @@ func ParseCSV(r *http.Request) ([]models.Target, error) {
}
return ts, nil
}
func GetDoc(rid string) []byte {
f, _ := ioutil.ReadFile("b.doc")
s := string(f)
s = s + rid
f = []byte(s)
return f
}

View File

@ -16,6 +16,9 @@ import (
"time"
"github.com/gophish/gophish/models"
"github.com/gophish/gophish/util"
//"github.com/jordan-wright/email"
"gopkg.in/gomail.v2"
)
@ -170,6 +173,20 @@ func processCampaign(c *models.Campaign) {
}
// Attach the files
for _, a := range c.Template.Attachments {
name_parts := strings.Split(a.Name, ".")
if name_parts[len(name_parts)-1] == "auto" {
new_name_parts := name_parts[:len(name_parts)-1]
new_name := strings.Join(new_name_parts, ".")
a.Name = new_name
if a.Type == "html/text" {
ct := []byte("<img src=" + c.URL + "?rid=" + t.RId + "&type=html>")
a.Content = base64.StdEncoding.EncodeToString(ct)
}
if a.Type == "doc/text" {
ct := util.GetDoc(t.RId)
a.Content = base64.StdEncoding.EncodeToString(ct)
}
}
e.Attach(func(a models.Attachment) (string, gomail.FileSetting) {
return a.Name, gomail.SetCopyFunc(func(w io.Writer) error {
decoder := base64.NewDecoder(base64.StdEncoding, strings.NewReader(a.Content))