Projects STRLCPY gophish Commits 15e57b6c
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■
    models/template_context.go
    skipped 22 lines
    23 23   Tracker string
    24 24   TrackingURL string
    25 25   RId string
     26 + BaseURL string
    26 27   BaseRecipient
    27 28  }
    28 29   
    skipped 8 lines
    37 38   if fn == "" {
    38 39   fn = f.Address
    39 40   }
    40  - baseURL, err := ExecuteTemplate(ctx.getBaseURL(), r)
     41 + templateURL, err := ExecuteTemplate(ctx.getBaseURL(), r)
    41 42   if err != nil {
    42 43   return PhishingTemplateContext{}, err
    43 44   }
    44 45   
    45  - phishURL, _ := url.Parse(baseURL)
     46 + // For the base URL, we'll reset the the path and the query
     47 + // This will create a URL in the form of http://example.com
     48 + baseURL, _ := url.Parse(templateURL)
     49 + baseURL.Path = ""
     50 + baseURL.RawQuery = ""
     51 + 
     52 + phishURL, _ := url.Parse(templateURL)
    46 53   q := phishURL.Query()
    47 54   q.Set(RecipientParameter, rid)
    48 55   phishURL.RawQuery = q.Encode()
    49 56   
    50  - trackingURL, _ := url.Parse(baseURL)
     57 + trackingURL, _ := url.Parse(templateURL)
    51 58   trackingURL.Path = path.Join(trackingURL.Path, "/track")
    52 59   trackingURL.RawQuery = q.Encode()
    53 60   
    54 61   return PhishingTemplateContext{
    55 62   BaseRecipient: r,
     63 + BaseURL: baseURL.String(),
    56 64   URL: phishURL.String(),
    57 65   TrackingURL: trackingURL.String(),
    58 66   Tracker: "<img alt='' style='display: none' src='" + trackingURL.String() + "'/>",
    skipped 17 lines
  • ■ ■ ■ ■ ■ ■
    models/template_context_test.go
     1 +package models
     2 + 
     3 +import (
     4 + "fmt"
     5 + 
     6 + check "gopkg.in/check.v1"
     7 +)
     8 + 
     9 +type mockTemplateContext struct {
     10 + URL string
     11 + FromAddress string
     12 +}
     13 + 
     14 +func (m mockTemplateContext) getFromAddress() string {
     15 + return m.FromAddress
     16 +}
     17 + 
     18 +func (m mockTemplateContext) getBaseURL() string {
     19 + return m.URL
     20 +}
     21 + 
     22 +func (s *ModelsSuite) TestNewTemplateContext(c *check.C) {
     23 + r := Result{
     24 + BaseRecipient: BaseRecipient{
     25 + FirstName: "Foo",
     26 + LastName: "Bar",
     27 + Email: "[email protected]",
     28 + },
     29 + RId: "1234567",
     30 + }
     31 + ctx := mockTemplateContext{
     32 + URL: "http://example.com",
     33 + FromAddress: "From Address <[email protected]>",
     34 + }
     35 + expected := PhishingTemplateContext{
     36 + URL: fmt.Sprintf("%s?rid=%s", ctx.URL, r.RId),
     37 + BaseURL: ctx.URL,
     38 + BaseRecipient: r.BaseRecipient,
     39 + TrackingURL: fmt.Sprintf("%s/track?rid=%s", ctx.URL, r.RId),
     40 + From: "From Address",
     41 + RId: r.RId,
     42 + }
     43 + expected.Tracker = "<img alt='' style='display: none' src='" + expected.TrackingURL + "'/>"
     44 + got, err := NewPhishingTemplateContext(ctx, r.BaseRecipient, r.RId)
     45 + c.Assert(err, check.Equals, nil)
     46 + c.Assert(got, check.DeepEquals, expected)
     47 +}
     48 + 
Please wait...
Page is in error, reload to recover