mirror of
https://github.com/bettercap/bettercap
synced 2025-07-06 04:52:10 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
bf3671465b
commit
4eead7eafa
58 changed files with 2052 additions and 2052 deletions
|
@ -14,78 +14,78 @@ type HttpsProxy struct {
|
|||
}
|
||||
|
||||
func NewHttpsProxy(s *session.Session) *HttpsProxy {
|
||||
p := &HttpsProxy{
|
||||
mod := &HttpsProxy{
|
||||
SessionModule: session.NewSessionModule("https.proxy", s),
|
||||
proxy: http_proxy.NewHTTPProxy(s),
|
||||
}
|
||||
|
||||
p.AddParam(session.NewIntParameter("https.port",
|
||||
mod.AddParam(session.NewIntParameter("https.port",
|
||||
"443",
|
||||
"HTTPS port to redirect when the proxy is activated."))
|
||||
|
||||
p.AddParam(session.NewStringParameter("https.proxy.address",
|
||||
mod.AddParam(session.NewStringParameter("https.proxy.address",
|
||||
session.ParamIfaceAddress,
|
||||
session.IPv4Validator,
|
||||
"Address to bind the HTTPS proxy to."))
|
||||
|
||||
p.AddParam(session.NewIntParameter("https.proxy.port",
|
||||
mod.AddParam(session.NewIntParameter("https.proxy.port",
|
||||
"8083",
|
||||
"Port to bind the HTTPS proxy to."))
|
||||
|
||||
p.AddParam(session.NewBoolParameter("https.proxy.sslstrip",
|
||||
mod.AddParam(session.NewBoolParameter("https.proxy.sslstrip",
|
||||
"false",
|
||||
"Enable or disable SSL stripping."))
|
||||
|
||||
p.AddParam(session.NewStringParameter("https.proxy.injectjs",
|
||||
mod.AddParam(session.NewStringParameter("https.proxy.injectjs",
|
||||
"",
|
||||
"",
|
||||
"URL, path or javascript code to inject into every HTML page."))
|
||||
|
||||
p.AddParam(session.NewStringParameter("https.proxy.certificate",
|
||||
mod.AddParam(session.NewStringParameter("https.proxy.certificate",
|
||||
"~/.bettercap-ca.cert.pem",
|
||||
"",
|
||||
"HTTPS proxy certification authority TLS certificate file."))
|
||||
|
||||
p.AddParam(session.NewStringParameter("https.proxy.key",
|
||||
mod.AddParam(session.NewStringParameter("https.proxy.key",
|
||||
"~/.bettercap-ca.key.pem",
|
||||
"",
|
||||
"HTTPS proxy certification authority TLS key file."))
|
||||
|
||||
tls.CertConfigToModule("https.proxy", &p.SessionModule, tls.DefaultSpoofConfig)
|
||||
tls.CertConfigToModule("https.proxy", &mod.SessionModule, tls.DefaultSpoofConfig)
|
||||
|
||||
p.AddParam(session.NewStringParameter("https.proxy.script",
|
||||
mod.AddParam(session.NewStringParameter("https.proxy.script",
|
||||
"",
|
||||
"",
|
||||
"Path of a proxy JS script."))
|
||||
|
||||
p.AddHandler(session.NewModuleHandler("https.proxy on", "",
|
||||
mod.AddHandler(session.NewModuleHandler("https.proxy on", "",
|
||||
"Start HTTPS proxy.",
|
||||
func(args []string) error {
|
||||
return p.Start()
|
||||
return mod.Start()
|
||||
}))
|
||||
|
||||
p.AddHandler(session.NewModuleHandler("https.proxy off", "",
|
||||
mod.AddHandler(session.NewModuleHandler("https.proxy off", "",
|
||||
"Stop HTTPS proxy.",
|
||||
func(args []string) error {
|
||||
return p.Stop()
|
||||
return mod.Stop()
|
||||
}))
|
||||
|
||||
return p
|
||||
return mod
|
||||
}
|
||||
|
||||
func (p *HttpsProxy) Name() string {
|
||||
func (mod *HttpsProxy) Name() string {
|
||||
return "https.proxy"
|
||||
}
|
||||
|
||||
func (p *HttpsProxy) Description() string {
|
||||
func (mod *HttpsProxy) Description() string {
|
||||
return "A full featured HTTPS proxy that can be used to inject malicious contents into webpages, all HTTPS traffic will be redirected to it."
|
||||
}
|
||||
|
||||
func (p *HttpsProxy) Author() string {
|
||||
func (mod *HttpsProxy) Author() string {
|
||||
return "Simone Margaritelli <evilsocket@gmail.com>"
|
||||
}
|
||||
|
||||
func (p *HttpsProxy) Configure() error {
|
||||
func (mod *HttpsProxy) Configure() error {
|
||||
var err error
|
||||
var address string
|
||||
var proxyPort int
|
||||
|
@ -96,62 +96,62 @@ func (p *HttpsProxy) Configure() error {
|
|||
var stripSSL bool
|
||||
var jsToInject string
|
||||
|
||||
if p.Running() {
|
||||
if mod.Running() {
|
||||
return session.ErrAlreadyStarted
|
||||
} else if err, address = p.StringParam("https.proxy.address"); err != nil {
|
||||
} else if err, address = mod.StringParam("https.proxy.address"); err != nil {
|
||||
return err
|
||||
} else if err, proxyPort = p.IntParam("https.proxy.port"); err != nil {
|
||||
} else if err, proxyPort = mod.IntParam("https.proxy.port"); err != nil {
|
||||
return err
|
||||
} else if err, httpPort = p.IntParam("https.port"); err != nil {
|
||||
} else if err, httpPort = mod.IntParam("https.port"); err != nil {
|
||||
return err
|
||||
} else if err, stripSSL = p.BoolParam("https.proxy.sslstrip"); err != nil {
|
||||
} else if err, stripSSL = mod.BoolParam("https.proxy.sslstrip"); err != nil {
|
||||
return err
|
||||
} else if err, certFile = p.StringParam("https.proxy.certificate"); err != nil {
|
||||
} else if err, certFile = mod.StringParam("https.proxy.certificate"); err != nil {
|
||||
return err
|
||||
} else if certFile, err = fs.Expand(certFile); err != nil {
|
||||
return err
|
||||
} else if err, keyFile = p.StringParam("https.proxy.key"); err != nil {
|
||||
} else if err, keyFile = mod.StringParam("https.proxy.key"); err != nil {
|
||||
return err
|
||||
} else if keyFile, err = fs.Expand(keyFile); err != nil {
|
||||
return err
|
||||
} else if err, scriptPath = p.StringParam("https.proxy.script"); err != nil {
|
||||
} else if err, scriptPath = mod.StringParam("https.proxy.script"); err != nil {
|
||||
return err
|
||||
} else if err, jsToInject = p.StringParam("https.proxy.injectjs"); err != nil {
|
||||
} else if err, jsToInject = mod.StringParam("https.proxy.injectjs"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !fs.Exists(certFile) || !fs.Exists(keyFile) {
|
||||
err, cfg := tls.CertConfigFromModule("https.proxy", p.SessionModule)
|
||||
err, cfg := tls.CertConfigFromModule("https.proxy", mod.SessionModule)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.Debug("%+v", cfg)
|
||||
p.Info("generating proxy certification authority TLS key to %s", keyFile)
|
||||
p.Info("generating proxy certification authority TLS certificate to %s", certFile)
|
||||
mod.Debug("%+v", cfg)
|
||||
mod.Info("generating proxy certification authority TLS key to %s", keyFile)
|
||||
mod.Info("generating proxy certification authority TLS certificate to %s", certFile)
|
||||
if err := tls.Generate(cfg, certFile, keyFile); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
p.Info("loading proxy certification authority TLS key from %s", keyFile)
|
||||
p.Info("loading proxy certification authority TLS certificate from %s", certFile)
|
||||
mod.Info("loading proxy certification authority TLS key from %s", keyFile)
|
||||
mod.Info("loading proxy certification authority TLS certificate from %s", certFile)
|
||||
}
|
||||
|
||||
return p.proxy.ConfigureTLS(address, proxyPort, httpPort, scriptPath, certFile, keyFile, jsToInject, stripSSL)
|
||||
return mod.proxy.ConfigureTLS(address, proxyPort, httpPort, scriptPath, certFile, keyFile, jsToInject, stripSSL)
|
||||
}
|
||||
|
||||
func (p *HttpsProxy) Start() error {
|
||||
if err := p.Configure(); err != nil {
|
||||
func (mod *HttpsProxy) Start() error {
|
||||
if err := mod.Configure(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return p.SetRunning(true, func() {
|
||||
p.proxy.Start()
|
||||
return mod.SetRunning(true, func() {
|
||||
mod.proxy.Start()
|
||||
})
|
||||
}
|
||||
|
||||
func (p *HttpsProxy) Stop() error {
|
||||
return p.SetRunning(false, func() {
|
||||
p.proxy.Stop()
|
||||
func (mod *HttpsProxy) Stop() error {
|
||||
return mod.SetRunning(false, func() {
|
||||
mod.proxy.Stop()
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue