mirror of
https://github.com/bettercap/bettercap
synced 2025-08-23 06:36:15 -07:00
the custom proxy can forward multiple source ports now
This commit is contained in:
parent
eedf0b66af
commit
8682512a7e
4 changed files with 20 additions and 13 deletions
1
main.go
1
main.go
|
@ -45,6 +45,7 @@ func main() {
|
||||||
sess.Register(modules.NewTcpProxy(sess))
|
sess.Register(modules.NewTcpProxy(sess))
|
||||||
sess.Register(modules.NewHttpProxy(sess))
|
sess.Register(modules.NewHttpProxy(sess))
|
||||||
sess.Register(modules.NewHttpsProxy(sess))
|
sess.Register(modules.NewHttpsProxy(sess))
|
||||||
|
sess.Register(modules.NewCustomHttpProxy(sess))
|
||||||
sess.Register(modules.NewHttpServer(sess))
|
sess.Register(modules.NewHttpServer(sess))
|
||||||
sess.Register(modules.NewRestAPI(sess))
|
sess.Register(modules.NewRestAPI(sess))
|
||||||
sess.Register(modules.NewWOL(sess))
|
sess.Register(modules.NewWOL(sess))
|
||||||
|
|
|
@ -15,8 +15,8 @@ func NewCustomHttpProxy(s *session.Session) *CustomHttpProxy {
|
||||||
proxy: NewCustomProxy(s),
|
proxy: NewCustomProxy(s),
|
||||||
}
|
}
|
||||||
|
|
||||||
p.AddParam(session.NewIntParameter("custom.http.port",
|
p.AddParam(session.NewStringParameter("custom.http.port",
|
||||||
"80",
|
"80", session.PortListValidator,
|
||||||
"HTTP port to redirect when the proxy is activated."))
|
"HTTP port to redirect when the proxy is activated."))
|
||||||
|
|
||||||
p.AddParam(session.NewStringParameter("custom.http.proxy.address",
|
p.AddParam(session.NewStringParameter("custom.http.proxy.address",
|
||||||
|
@ -63,7 +63,7 @@ func (p *CustomHttpProxy) Configure() error {
|
||||||
var err error
|
var err error
|
||||||
var address string
|
var address string
|
||||||
var proxyPort int
|
var proxyPort int
|
||||||
var httpPort int
|
var httpPort []string
|
||||||
var stripSSL bool
|
var stripSSL bool
|
||||||
|
|
||||||
if p.Running() {
|
if p.Running() {
|
||||||
|
@ -72,7 +72,7 @@ func (p *CustomHttpProxy) Configure() error {
|
||||||
return err
|
return err
|
||||||
} else if err, proxyPort = p.IntParam("custom.http.proxy.port"); err != nil {
|
} else if err, proxyPort = p.IntParam("custom.http.proxy.port"); err != nil {
|
||||||
return err
|
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
|
return err
|
||||||
} else if err, stripSSL = p.BoolParam("custom.http.proxy.sslstrip"); err != nil {
|
} else if err, stripSSL = p.BoolParam("custom.http.proxy.sslstrip"); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"github.com/bettercap/bettercap/log"
|
"github.com/bettercap/bettercap/log"
|
||||||
"github.com/bettercap/bettercap/core"
|
"github.com/bettercap/bettercap/core"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CustomProxy struct {
|
type CustomProxy struct {
|
||||||
|
@ -60,7 +61,7 @@ func (p *CustomProxy) stripPort(s string) string {
|
||||||
return s[:ix]
|
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.stripper.Enable(stripSSL)
|
||||||
p.Address = proxyAddress
|
p.Address = proxyAddress
|
||||||
|
@ -70,17 +71,21 @@ func (p *CustomProxy) Configure(proxyAddress string, proxyPort int, srcPort int,
|
||||||
p.sess.Firewall.EnableForwarding(true)
|
p.sess.Firewall.EnableForwarding(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _,v := range srcPort {
|
||||||
|
|
||||||
|
port, _ := strconv.Atoi(v)
|
||||||
p.Redirection = firewall.NewRedirection(p.sess.Interface.Name(),
|
p.Redirection = firewall.NewRedirection(p.sess.Interface.Name(),
|
||||||
"TCP",
|
"TCP",
|
||||||
srcPort,
|
port,
|
||||||
p.Address,
|
p.Address,
|
||||||
proxyPort)
|
proxyPort)
|
||||||
|
|
||||||
if err := p.sess.Firewall.EnableRedirection(p.Redirection, true); err != nil {
|
if err := p.sess.Firewall.EnableRedirection(p.Redirection, true); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("Applied redirection %s", p.Redirection.String())
|
log.Debug("Applied redirection %s", p.Redirection.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const IPv4Validator = `^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$`
|
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 {
|
type ModuleHandler struct {
|
||||||
Name string
|
Name string
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue