mirror of https://github.com/gophish/gophish
added the ability to generate QR code for phishing URL.
parent
d2efb18ef1
commit
43982882e7
1
go.mod
1
go.mod
|
@ -25,6 +25,7 @@ require (
|
|||
github.com/mattn/go-sqlite3 v2.0.3+incompatible
|
||||
github.com/oschwald/maxminddb-golang v1.6.0
|
||||
github.com/sirupsen/logrus v1.4.2
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||
github.com/ziutek/mymysql v1.5.4 // indirect
|
||||
golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -74,6 +74,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
|
|
|
@ -6,6 +6,9 @@ import (
|
|||
"net/url"
|
||||
"path"
|
||||
"text/template"
|
||||
"encoding/base64"
|
||||
log "github.com/gophish/gophish/logger"
|
||||
qrcode "github.com/skip2/go-qrcode" //library for generating qrcode
|
||||
)
|
||||
|
||||
// TemplateContext is an interface that allows both campaigns and email
|
||||
|
@ -24,6 +27,7 @@ type PhishingTemplateContext struct {
|
|||
TrackingURL string
|
||||
RId string
|
||||
BaseURL string
|
||||
QrURL string
|
||||
BaseRecipient
|
||||
}
|
||||
|
||||
|
@ -61,6 +65,8 @@ func NewPhishingTemplateContext(ctx TemplateContext, r BaseRecipient, rid string
|
|||
trackingURL.Path = path.Join(trackingURL.Path, "/track")
|
||||
trackingURL.RawQuery = q.Encode()
|
||||
|
||||
qrDataUrl := generateQRCodeDataUrl(phishURL.String())
|
||||
|
||||
return PhishingTemplateContext{
|
||||
BaseRecipient: r,
|
||||
BaseURL: baseURL.String(),
|
||||
|
@ -69,6 +75,7 @@ func NewPhishingTemplateContext(ctx TemplateContext, r BaseRecipient, rid string
|
|||
Tracker: "<img alt='' style='display: none' src='" + trackingURL.String() + "'/>",
|
||||
From: fn,
|
||||
RId: rid,
|
||||
QrURL: qrDataUrl,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -124,3 +131,22 @@ func ValidateTemplate(text string) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//Generate QR code dataurl
|
||||
func generateQRCodeDataUrl(websiteURL string) string {
|
||||
|
||||
// imageSize = 256 x 256 pixels
|
||||
|
||||
imageSize := 256
|
||||
qrCodeImageData, taskError := qrcode.Encode(websiteURL, qrcode.High, imageSize)
|
||||
|
||||
if taskError != nil {
|
||||
log.Errorf("Error generating QR code. %s",taskError)
|
||||
}
|
||||
|
||||
// Encode raw QR code data to base 64
|
||||
encodedData := base64.StdEncoding.EncodeToString(qrCodeImageData)
|
||||
log.Infof("QR encodedData = %s", encodedData)
|
||||
|
||||
return "data:image/png;base64, "+encodedData
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue