forked from bettercap/bettercap
/
http_proxy.go
114 lines (93 loc) · 2.71 KB
/
http_proxy.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
package modules
import (
"github.com/bettercap/bettercap/session"
)
type HttpProxy struct {
session.SessionModule
proxy *HTTPProxy
}
func NewHttpProxy(s *session.Session) *HttpProxy {
p := &HttpProxy{
SessionModule: session.NewSessionModule("http.proxy", s),
proxy: NewHTTPProxy(s),
}
p.AddParam(session.NewIntParameter("http.port",
"80",
"HTTP port to redirect when the proxy is activated."))
p.AddParam(session.NewStringParameter("http.proxy.address",
session.ParamIfaceAddress,
session.IPv4Validator,
"Address to bind the HTTP proxy to."))
p.AddParam(session.NewIntParameter("http.proxy.port",
"8080",
"Port to bind the HTTP proxy to."))
p.AddParam(session.NewStringParameter("http.proxy.script",
"",
"",
"Path of a proxy JS script."))
p.AddParam(session.NewStringParameter("http.proxy.injectjs",
"",
"",
"URL, path or javascript code to inject into every HTML page."))
p.AddParam(session.NewBoolParameter("http.proxy.sslstrip",
"false",
"Enable or disable SSL stripping."))
p.AddHandler(session.NewModuleHandler("http.proxy on", "",
"Start HTTP proxy.",
func(args []string) error {
return p.Start()
}))
p.AddHandler(session.NewModuleHandler("http.proxy off", "",
"Stop HTTP proxy.",
func(args []string) error {
return p.Stop()
}))
return p
}
func (p *HttpProxy) Name() string {
return "http.proxy"
}
func (p *HttpProxy) Description() string {
return "A full featured HTTP proxy that can be used to inject malicious contents into webpages, all HTTP traffic will be redirected to it."
}
func (p *HttpProxy) Author() string {
return "Simone Margaritelli <evilsocket@protonmail.com>"
}
func (p *HttpProxy) Configure() error {
var err error
var address string
var proxyPort int
var httpPort int
var scriptPath string
var stripSSL bool
var jsToInject string
if p.Running() {
return session.ErrAlreadyStarted
} else if err, address = p.StringParam("http.proxy.address"); err != nil {
return err
} else if err, proxyPort = p.IntParam("http.proxy.port"); err != nil {
return err
} else if err, httpPort = p.IntParam("http.port"); err != nil {
return err
} else if err, scriptPath = p.StringParam("http.proxy.script"); err != nil {
return err
} else if err, stripSSL = p.BoolParam("http.proxy.sslstrip"); err != nil {
return err
} else if err, jsToInject = p.StringParam("http.proxy.injectjs"); err != nil {
return err
}
return p.proxy.Configure(address, proxyPort, httpPort, scriptPath, jsToInject, stripSSL)
}
func (p *HttpProxy) Start() error {
if err := p.Configure(); err != nil {
return err
}
return p.SetRunning(true, func() {
p.proxy.Start()
})
}
func (p *HttpProxy) Stop() error {
return p.SetRunning(false, func() {
p.proxy.Stop()
})
}