Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions core/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -289,14 +290,14 @@ func (httpResponse *HTTPResponse) PatchHeaders(p *ReverseProxy) {
newLocation = strings.Replace(newLocation, "https://", "http://", -1)
}

if len(runtime.ReplaceStrings) > 0 {
// if len(runtime.ReplaceStrings) > 0 {

log.Debugf("Patching Location header for static redirect")
for k, v := range runtime.ReplaceStrings {
newLocation = strings.ReplaceAll(newLocation, k, v)
}
// log.Debugf("Patching Location header for static redirect")
// for k, v := range runtime.ReplaceStrings {
// newLocation = strings.ReplaceAll(newLocation, k, v)
// }

}
// }

// Handle static location values
// This flag will determine if real FQDNs in the location header should
Expand Down Expand Up @@ -492,9 +493,22 @@ func (p *ReverseProxy) PatchURL(buffer []byte) []byte {
// Translate URLs
buffer = []byte(runtime.RegexpUrl.ReplaceAllStringFunc(string(buffer), runtime.RealURLtoPhish))

// TargetRules `json:"rules"`
// if len(runtime.ReplaceStrings) > 0 {
// for key, value := range runtime.ReplaceStrings {
// buffer = bytes.Replace(buffer, []byte(key), []byte(value), -1)
// }
// }
if len(runtime.ReplaceStrings) > 0 {
for key, value := range runtime.ReplaceStrings {
buffer = bytes.Replace(buffer, []byte(key), []byte(value), -1)
for pattern, replacement := range runtime.ReplaceStrings {
re, err := regexp.Compile(pattern)
if err != nil {
log.Warningf("Bad regular expression rule for replacement:\n%v\n", err)
continue
}
buffer = re.ReplaceAllFunc(buffer, func(match []byte) []byte {
return []byte(replacement)
})
}
}

Expand Down
Loading