| 1 | package tcp_proxyscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/tcp_proxy`/ |
| 2 | |
| 3 | import ( |
| 4 | "netscip-go gomod github.com/golang/go/src go1.16 net/" |
| 5 | "stringsscip-go gomod github.com/golang/go/src go1.16 strings/" |
| 6 | |
| 7 | "github.com/bettercap/bettercap/logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/" |
| 8 | "github.com/bettercap/bettercap/sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/" |
| 9 | |
| 10 | "github.com/evilsocket/islazy/pluginscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/" |
| 11 | |
| 12 | "github.com/robertkrimen/ottoscip-go gomod github.com/robertkrimen/otto v0.4.0 `github.com/robertkrimen/otto`/" |
| 13 | ) |
| 14 | |
| 15 | type TcpProxyScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/tcp_proxy`/TcpProxyScript# struct { |
| 16 | *pluginscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/.Pluginscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/tcp_proxy`/TcpProxyScript#Plugin. |
| 17 | doOnDatascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/tcp_proxy`/TcpProxyScript#doOnData. bool |
| 18 | } |
| 19 | |
| 20 | func LoadTcpProxyScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/tcp_proxy`/LoadTcpProxyScript().(path string, sess *sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#) (err error, s *TcpProxyScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/tcp_proxy`/TcpProxyScript#) { |
| 21 | logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/Info().("loading tcp proxy script %s ...", path) |
| 22 | |
| 23 | plug, err := pluginscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/.Loadscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/Load().(path) |
| 24 | if err != nil { |
| 25 | return |
| 26 | } |
| 27 | |
| 28 | // define session pointer |
| 29 | if err = plug.Setscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/Plugin#Set().("env", sess.Envscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Env..Datascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Environment#Data.); err != nil { |
| 30 | logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/Error().("error while defining environment: %+v", err) |
| 31 | return |
| 32 | } |
| 33 | |
| 34 | // run onLoad if defined |
| 35 | if plug.HasFuncscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/Plugin#HasFunc().("onLoad") { |
| 36 | if _, err = plug.Callscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/Plugin#Call().("onLoad"); err != nil { |
| 37 | logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/Error().("error while executing onLoad callback: %s", "\ntraceback:\n "+err.(*ottoscip-go gomod github.com/robertkrimen/otto v0.4.0 `github.com/robertkrimen/otto`/.Errorscip-go gomod github.com/robertkrimen/otto v0.4.0 `github.com/robertkrimen/otto`/Error#).Stringscip-go gomod github.com/robertkrimen/otto v0.4.0 `github.com/robertkrimen/otto`/Error#String().()) |
| 38 | return |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | s = &TcpProxyScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/tcp_proxy`/TcpProxyScript#{ |
| 43 | Pluginscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/tcp_proxy`/TcpProxyScript#Plugin.: plug, |
| 44 | doOnDatascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/tcp_proxy`/TcpProxyScript#doOnData.: plug.HasFuncscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/Plugin#HasFunc().("onData"), |
| 45 | } |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | func (s *TcpProxyScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/tcp_proxy`/TcpProxyScript#) OnDatascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/tcp_proxy`/TcpProxyScript#OnData().(from, to netscip-go gomod github.com/golang/go/src go1.16 net/.Addrscip-go gomod github.com/golang/go/src go1.16 net/Addr#, data []byte, callback func(call ottoscip-go gomod github.com/robertkrimen/otto v0.4.0 `github.com/robertkrimen/otto`/.FunctionCallscip-go gomod github.com/robertkrimen/otto v0.4.0 `github.com/robertkrimen/otto`/FunctionCall#) ottoscip-go gomod github.com/robertkrimen/otto v0.4.0 `github.com/robertkrimen/otto`/.Valuescip-go gomod github.com/robertkrimen/otto v0.4.0 `github.com/robertkrimen/otto`/Value#) []byte { |
| 50 | if s.doOnDatascip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/tcp_proxy`/TcpProxyScript#doOnData. { |
| 51 | addrFrom := stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Splitscip-go gomod github.com/golang/go/src go1.16 strings/Split().(from.Stringscip-go gomod github.com/golang/go/src go1.16 net/Addr#String().(), ":")[0] |
| 52 | addrTo := stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Splitscip-go gomod github.com/golang/go/src go1.16 strings/Split().(to.Stringscip-go gomod github.com/golang/go/src go1.16 net/Addr#String().(), ":")[0] |
| 53 | |
| 54 | if ret, err := s.Callscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/Plugin#Call().("onData", addrFrom, addrTo, data, callback); err != nil { |
| 55 | logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/Error().("error while executing onData callback: %s", err) |
| 56 | return nil |
| 57 | } else if ret != nil { |
| 58 | array, ok := ret.([]byte) |
| 59 | if !ok { |
| 60 | logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/Error().("error while casting exported value to array of byte: value = %+v", ret) |
| 61 | } |
| 62 | return array |
| 63 | } |
| 64 | } |
| 65 | return nil |
| 66 | } |