mirror of
https://github.com/bettercap/bettercap
synced 2025-07-07 05:22:04 -07:00
Added dropCallback to drop packets instead of just changing it
This commit is contained in:
parent
709232dba2
commit
11d2756283
3 changed files with 12 additions and 7 deletions
|
@ -8,6 +8,8 @@ import (
|
||||||
|
|
||||||
"github.com/bettercap/bettercap/firewall"
|
"github.com/bettercap/bettercap/firewall"
|
||||||
"github.com/bettercap/bettercap/session"
|
"github.com/bettercap/bettercap/session"
|
||||||
|
|
||||||
|
"github.com/robertkrimen/otto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TcpProxy struct {
|
type TcpProxy struct {
|
||||||
|
@ -150,7 +152,7 @@ func (mod *TcpProxy) Configure() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mod *TcpProxy) doPipe(from, to net.Addr, src, dst io.ReadWriter, wg *sync.WaitGroup) {
|
func (mod *TcpProxy) doPipe(from, to net.Addr, src *net.TCPConn, dst io.ReadWriter, wg *sync.WaitGroup) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
buff := make([]byte, 0xffff)
|
buff := make([]byte, 0xffff)
|
||||||
|
@ -165,7 +167,11 @@ func (mod *TcpProxy) doPipe(from, to net.Addr, src, dst io.ReadWriter, wg *sync.
|
||||||
b := buff[:n]
|
b := buff[:n]
|
||||||
|
|
||||||
if mod.script != nil {
|
if mod.script != nil {
|
||||||
ret := mod.script.OnData(from, to, b)
|
ret := mod.script.OnData(from, to, b, func(call otto.FunctionCall) otto.Value {
|
||||||
|
mod.Debug("onData dropCallback called")
|
||||||
|
src.Close()
|
||||||
|
return otto.Value{}
|
||||||
|
})
|
||||||
|
|
||||||
if ret != nil {
|
if ret != nil {
|
||||||
nret := len(ret)
|
nret := len(ret)
|
||||||
|
|
|
@ -7,9 +7,9 @@ import (
|
||||||
"github.com/bettercap/bettercap/log"
|
"github.com/bettercap/bettercap/log"
|
||||||
"github.com/bettercap/bettercap/session"
|
"github.com/bettercap/bettercap/session"
|
||||||
|
|
||||||
"github.com/robertkrimen/otto"
|
|
||||||
|
|
||||||
"github.com/evilsocket/islazy/plugin"
|
"github.com/evilsocket/islazy/plugin"
|
||||||
|
|
||||||
|
"github.com/robertkrimen/otto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TcpProxyScript struct {
|
type TcpProxyScript struct {
|
||||||
|
@ -46,12 +46,12 @@ func LoadTcpProxyScript(path string, sess *session.Session) (err error, s *TcpPr
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *TcpProxyScript) OnData(from, to net.Addr, data []byte) []byte {
|
func (s *TcpProxyScript) OnData(from, to net.Addr, data []byte, callback func(call otto.FunctionCall) otto.Value) []byte {
|
||||||
if s.doOnData {
|
if s.doOnData {
|
||||||
addrFrom := strings.Split(from.String(), ":")[0]
|
addrFrom := strings.Split(from.String(), ":")[0]
|
||||||
addrTo := strings.Split(to.String(), ":")[0]
|
addrTo := strings.Split(to.String(), ":")[0]
|
||||||
|
|
||||||
if ret, err := s.Call("onData", addrFrom, addrTo, data); err != nil {
|
if ret, err := s.Call("onData", addrFrom, addrTo, data, callback); err != nil {
|
||||||
log.Error("error while executing onData callback: %s", err)
|
log.Error("error while executing onData callback: %s", err)
|
||||||
return nil
|
return nil
|
||||||
} else if ret != nil {
|
} else if ret != nil {
|
||||||
|
|
|
@ -276,7 +276,6 @@ func init() {
|
||||||
}
|
}
|
||||||
req.Header.Add(key, v.String())
|
req.Header.Add(key, v.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return errOtto("Could create request to url %s: %s", url, err)
|
return errOtto("Could create request to url %s: %s", url, err)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue