diff --git a/main.go b/main.go index 015b519e..fa050e19 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,7 @@ func main() { sess.Register(modules.NewTcpProxy(sess)) sess.Register(modules.NewHttpProxy(sess)) sess.Register(modules.NewHttpsProxy(sess)) + sess.Register(modules.NewCustomHttpProxy(sess)) sess.Register(modules.NewHttpServer(sess)) sess.Register(modules.NewRestAPI(sess)) sess.Register(modules.NewWOL(sess)) diff --git a/modules/custom_http_proxy.go b/modules/custom_http_proxy.go index f850f1e2..11fcf785 100644 --- a/modules/custom_http_proxy.go +++ b/modules/custom_http_proxy.go @@ -15,8 +15,8 @@ func NewCustomHttpProxy(s *session.Session) *CustomHttpProxy { proxy: NewCustomProxy(s), } - p.AddParam(session.NewIntParameter("custom.http.port", - "80", + p.AddParam(session.NewStringParameter("custom.http.port", + "80", session.PortListValidator, "HTTP port to redirect when the proxy is activated.")) p.AddParam(session.NewStringParameter("custom.http.proxy.address", @@ -63,7 +63,7 @@ func (p *CustomHttpProxy) Configure() error { var err error var address string var proxyPort int - var httpPort int + var httpPort []string var stripSSL bool if p.Running() { @@ -72,7 +72,7 @@ func (p *CustomHttpProxy) Configure() error { return err } else if err, proxyPort = p.IntParam("custom.http.proxy.port"); err != nil { return err - } else if err, httpPort = p.IntParam("custom.http.port"); err != nil { + } else if err, httpPort = p.ListParam("custom.http.port"); err != nil { return err } else if err, stripSSL = p.BoolParam("custom.http.proxy.sslstrip"); err != nil { return err diff --git a/modules/custom_proxy_base.go b/modules/custom_proxy_base.go index 96460b65..bb6a7789 100644 --- a/modules/custom_proxy_base.go +++ b/modules/custom_proxy_base.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/bettercap/bettercap/log" "github.com/bettercap/bettercap/core" + "strconv" ) type CustomProxy struct { @@ -60,7 +61,7 @@ func (p *CustomProxy) stripPort(s string) string { return s[:ix] } -func (p *CustomProxy) Configure(proxyAddress string, proxyPort int, srcPort int, stripSSL bool) error { +func (p *CustomProxy) Configure(proxyAddress string, proxyPort int, srcPort []string, stripSSL bool) error { p.stripper.Enable(stripSSL) p.Address = proxyAddress @@ -70,17 +71,21 @@ func (p *CustomProxy) Configure(proxyAddress string, proxyPort int, srcPort int, p.sess.Firewall.EnableForwarding(true) } - p.Redirection = firewall.NewRedirection(p.sess.Interface.Name(), - "TCP", - srcPort, - p.Address, - proxyPort) + for _,v := range srcPort { - if err := p.sess.Firewall.EnableRedirection(p.Redirection, true); err != nil { - return err + 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()) return nil } diff --git a/session/module_handler.go b/session/module_handler.go index 35b18027..6d936d3b 100644 --- a/session/module_handler.go +++ b/session/module_handler.go @@ -9,6 +9,7 @@ import ( ) const IPv4Validator = `^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$` +const PortListValidator = `^(([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])+[,]+)*(([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])+)$` type ModuleHandler struct { Name string