the custom proxy can forward multiple source ports now

This commit is contained in:
gorgiaxx 2018-07-11 17:54:52 +08:00
commit 8682512a7e
4 changed files with 20 additions and 13 deletions

View file

@ -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))

View file

@ -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

View file

@ -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)
}
for _,v := range srcPort {
port, _ := strconv.Atoi(v)
p.Redirection = firewall.NewRedirection(p.sess.Interface.Name(),
"TCP",
srcPort,
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())
}
return nil
}

View file

@ -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