mirror of https://github.com/gophish/gophish
Added logic to unescape template variables in Word documents for remote images
parent
51cb65a44e
commit
b9824f6ac3
|
@ -6,7 +6,9 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -95,6 +97,17 @@ func (a *Attachment) ApplyTemplate(ptx PhishingTemplateContext) (io.Reader, erro
|
||||||
subFileExtension := filepath.Ext(zipFile.Name)
|
subFileExtension := filepath.Ext(zipFile.Name)
|
||||||
var tFile string
|
var tFile string
|
||||||
if subFileExtension == ".xml" || subFileExtension == ".rels" { // Ignore other files, e.g binary ones and images
|
if subFileExtension == ".xml" || subFileExtension == ".rels" { // Ignore other files, e.g binary ones and images
|
||||||
|
// First we look for instances where Word has URL escaped our template variables. This seems to happen when inserting a remote image, converting {{.Foo}} to %7b%7b.foo%7d%7d.
|
||||||
|
// See https://stackoverflow.com/questions/68287630/disable-url-encoding-for-includepicture-in-microsoft-word
|
||||||
|
rx, _ := regexp.Compile("%7b%7b.([a-zA-Z]+)%7d%7d")
|
||||||
|
contents := rx.ReplaceAllFunc(contents, func(m []byte) []byte {
|
||||||
|
d, err := url.QueryUnescape(string(m))
|
||||||
|
if err != nil {
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
return []byte(d)
|
||||||
|
})
|
||||||
|
|
||||||
// For each file apply the template.
|
// For each file apply the template.
|
||||||
tFile, err = ExecuteTemplate(string(contents), ptx)
|
tFile, err = ExecuteTemplate(string(contents), ptx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue