Added dropCallback to drop packets instead of just changing it

This commit is contained in:
realgam3 2019-09-06 02:31:48 +03:00
parent 709232dba2
commit 11d2756283
3 changed files with 12 additions and 7 deletions

View file

@ -8,6 +8,8 @@ import (
"github.com/bettercap/bettercap/firewall"
"github.com/bettercap/bettercap/session"
"github.com/robertkrimen/otto"
)
type TcpProxy struct {
@ -150,7 +152,7 @@ func (mod *TcpProxy) Configure() error {
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()
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]
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 {
nret := len(ret)

View file

@ -7,9 +7,9 @@ import (
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/session"
"github.com/robertkrimen/otto"
"github.com/evilsocket/islazy/plugin"
"github.com/robertkrimen/otto"
)
type TcpProxyScript struct {
@ -46,12 +46,12 @@ func LoadTcpProxyScript(path string, sess *session.Session) (err error, s *TcpPr
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 {
addrFrom := strings.Split(from.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)
return nil
} else if ret != nil {

View file

@ -276,7 +276,6 @@ func init() {
}
req.Header.Add(key, v.String())
}
}
} else if err != nil {
return errOtto("Could create request to url %s: %s", url, err)