mirror of
https://github.com/bettercap/bettercap
synced 2025-08-22 22:34:22 -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.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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue