mirror of
https://github.com/bettercap/bettercap
synced 2025-08-22 22:34:22 -07:00
the builtin proxy can forward multiple source ports
This commit is contained in:
parent
8682512a7e
commit
82186e2b47
3 changed files with 24 additions and 20 deletions
|
@ -15,8 +15,8 @@ func NewHttpProxy(s *session.Session) *HttpProxy {
|
|||
proxy: NewHTTPProxy(s),
|
||||
}
|
||||
|
||||
p.AddParam(session.NewIntParameter("http.port",
|
||||
"80",
|
||||
p.AddParam(session.NewStringParameter("http.port",
|
||||
"80", session.PortListValidator,
|
||||
"HTTP port to redirect when the proxy is activated."))
|
||||
|
||||
p.AddParam(session.NewStringParameter("http.proxy.address",
|
||||
|
@ -68,7 +68,7 @@ func (p *HttpProxy) Configure() error {
|
|||
var err error
|
||||
var address string
|
||||
var proxyPort int
|
||||
var httpPort int
|
||||
var httpPort []string
|
||||
var scriptPath string
|
||||
var stripSSL bool
|
||||
|
||||
|
@ -78,7 +78,7 @@ func (p *HttpProxy) Configure() error {
|
|||
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 {
|
||||
} else if err, httpPort = p.ListParam("http.port"); err != nil {
|
||||
return err
|
||||
} else if err, scriptPath = p.StringParam("http.proxy.script"); err != nil {
|
||||
return err
|
||||
|
|
|
@ -106,7 +106,7 @@ func (p *HTTPProxy) doProxy(req *http.Request) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func (p *HTTPProxy) Configure(address string, proxyPort int, httpPort int, scriptPath string, stripSSL bool) error {
|
||||
func (p *HTTPProxy) Configure(address string, proxyPort int, httpPort []string, scriptPath string, stripSSL bool) error {
|
||||
var err error
|
||||
|
||||
p.stripper.Enable(stripSSL)
|
||||
|
@ -132,18 +132,22 @@ func (p *HTTPProxy) Configure(address string, proxyPort int, httpPort int, scrip
|
|||
p.sess.Firewall.EnableForwarding(true)
|
||||
}
|
||||
|
||||
p.Redirection = firewall.NewRedirection(p.sess.Interface.Name(),
|
||||
"TCP",
|
||||
httpPort,
|
||||
p.Address,
|
||||
proxyPort)
|
||||
|
||||
if err := p.sess.Firewall.EnableRedirection(p.Redirection, true); err != nil {
|
||||
return err
|
||||
for _,v := range httpPort {
|
||||
|
||||
port, _ := strconv.Atoi(v)
|
||||
p.Redirection = firewall.NewRedirection(p.sess.Interface.Name(),
|
||||
"TCP",
|
||||
port,
|
||||
p.Address,
|
||||
proxyPort)
|
||||
|
||||
if err := p.sess.Firewall.EnableRedirection(p.Redirection, true); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Debug("Applied redirection %s", p.Redirection.String())
|
||||
}
|
||||
|
||||
log.Debug("Applied redirection %s", p.Redirection.String())
|
||||
|
||||
p.sess.UnkCmdCallback = func(cmd string) bool {
|
||||
if p.Script != nil {
|
||||
return p.Script.OnCommand(cmd)
|
||||
|
@ -187,7 +191,7 @@ func TLSConfigFromCA(ca *tls.Certificate) func(host string, ctx *goproxy.ProxyCt
|
|||
}
|
||||
}
|
||||
|
||||
func (p *HTTPProxy) ConfigureTLS(address string, proxyPort int, httpPort int, scriptPath string, certFile string, keyFile string, stripSSL bool) (err error) {
|
||||
func (p *HTTPProxy) ConfigureTLS(address string, proxyPort int, httpPort []string, scriptPath string, certFile string, keyFile string, stripSSL bool) (err error) {
|
||||
if p.Configure(address, proxyPort, httpPort, scriptPath, stripSSL); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ func NewHttpsProxy(s *session.Session) *HttpsProxy {
|
|||
proxy: NewHTTPProxy(s),
|
||||
}
|
||||
|
||||
p.AddParam(session.NewIntParameter("https.port",
|
||||
"443",
|
||||
p.AddParam(session.NewStringParameter("https.port",
|
||||
"443", session.PortListValidator,
|
||||
"HTTPS port to redirect when the proxy is activated."))
|
||||
|
||||
p.AddParam(session.NewStringParameter("https.proxy.address",
|
||||
|
@ -81,7 +81,7 @@ func (p *HttpsProxy) Configure() error {
|
|||
var err error
|
||||
var address string
|
||||
var proxyPort int
|
||||
var httpPort int
|
||||
var httpsPort []string
|
||||
var scriptPath string
|
||||
var certFile string
|
||||
var keyFile string
|
||||
|
@ -93,7 +93,7 @@ func (p *HttpsProxy) Configure() error {
|
|||
return err
|
||||
} else if err, proxyPort = p.IntParam("https.proxy.port"); err != nil {
|
||||
return err
|
||||
} else if err, httpPort = p.IntParam("https.port"); err != nil {
|
||||
} else if err, httpsPort = p.ListParam("https.port"); err != nil {
|
||||
return err
|
||||
} else if err, stripSSL = p.BoolParam("https.proxy.sslstrip"); err != nil {
|
||||
return err
|
||||
|
@ -120,7 +120,7 @@ func (p *HttpsProxy) Configure() error {
|
|||
log.Info("Loading proxy certification authority TLS certificate from %s", certFile)
|
||||
}
|
||||
|
||||
return p.proxy.ConfigureTLS(address, proxyPort, httpPort, scriptPath, certFile, keyFile, stripSSL)
|
||||
return p.proxy.ConfigureTLS(address, proxyPort, httpsPort, scriptPath, certFile, keyFile, stripSSL)
|
||||
}
|
||||
|
||||
func (p *HttpsProxy) Start() error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue