| 1 | package http_proxyscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/ |
| 2 | |
| 3 | import ( |
| 4 | "net/httpscip-go gomod github.com/golang/go/src go1.16 `net/http`/" |
| 5 | |
| 6 | "github.com/bettercap/bettercap/logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/" |
| 7 | "github.com/bettercap/bettercap/sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/" |
| 8 | |
| 9 | "github.com/robertkrimen/ottoscip-go gomod github.com/robertkrimen/otto v0.4.0 `github.com/robertkrimen/otto`/" |
| 10 | |
| 11 | "github.com/evilsocket/islazy/pluginscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/" |
| 12 | ) |
| 13 | |
| 14 | type HttpProxyScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript# struct { |
| 15 | *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/http_proxy`/HttpProxyScript#Plugin. |
| 16 | |
| 17 | doOnRequestscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#doOnRequest. bool |
| 18 | doOnResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#doOnResponse. bool |
| 19 | doOnCommandscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#doOnCommand. bool |
| 20 | } |
| 21 | |
| 22 | func LoadHttpProxyScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/LoadHttpProxyScript().(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 *HttpProxyScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#) { |
| 23 | logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/Debug().("loading proxy script %s ...", path) |
| 24 | |
| 25 | 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) |
| 26 | if err != nil { |
| 27 | return |
| 28 | } |
| 29 | |
| 30 | // define session pointer |
| 31 | 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 { |
| 32 | 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) |
| 33 | return |
| 34 | } |
| 35 | |
| 36 | // run onLoad if defined |
| 37 | if plug.HasFuncscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/Plugin#HasFunc().("onLoad") { |
| 38 | if _, err = plug.Callscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/Plugin#Call().("onLoad"); err != nil { |
| 39 | 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().()) |
| 40 | return |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | s = &HttpProxyScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#{ |
| 45 | Pluginscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#Plugin.: plug, |
| 46 | doOnRequestscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#doOnRequest.: plug.HasFuncscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/Plugin#HasFunc().("onRequest"), |
| 47 | doOnResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#doOnResponse.: plug.HasFuncscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/Plugin#HasFunc().("onResponse"), |
| 48 | doOnCommandscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#doOnCommand.: plug.HasFuncscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/Plugin#HasFunc().("onCommand"), |
| 49 | } |
| 50 | return |
| 51 | } |
| 52 | |
| 53 | func (s *HttpProxyScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#) OnRequestscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#OnRequest().(original *httpscip-go gomod github.com/golang/go/src go1.16 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.16 `net/http`/Request#) (jsreq *JSRequestscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSRequest#, jsres *JSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#) { |
| 54 | if s.doOnRequestscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#doOnRequest. { |
| 55 | jsreq := NewJSRequestscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/NewJSRequest().(original) |
| 56 | jsres := NewJSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/NewJSResponse().(nil) |
| 57 | |
| 58 | if _, err := s.Callscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/Plugin#Call().("onRequest", jsreq, jsres); err != nil { |
| 59 | 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().("%s", err) |
| 60 | return nil, nil |
| 61 | } else if jsreq.WasModifiedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSRequest#WasModified().() { |
| 62 | jsreq.UpdateHashscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSRequest#UpdateHash().() |
| 63 | return jsreq, nil |
| 64 | } else if jsres.WasModifiedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#WasModified().() { |
| 65 | jsres.UpdateHashscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#UpdateHash().() |
| 66 | return nil, jsres |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return nil, nil |
| 71 | } |
| 72 | |
| 73 | func (s *HttpProxyScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#) OnResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#OnResponse().(res *httpscip-go gomod github.com/golang/go/src go1.16 `net/http`/.Responsescip-go gomod github.com/golang/go/src go1.16 `net/http`/Response#) (jsreq *JSRequestscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSRequest#, jsres *JSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#) { |
| 74 | if s.doOnResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#doOnResponse. { |
| 75 | jsreq := NewJSRequestscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/NewJSRequest().(res.Requestscip-go gomod github.com/golang/go/src go1.16 `net/http`/Response#Request.) |
| 76 | jsres := NewJSResponsescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/NewJSResponse().(res) |
| 77 | |
| 78 | if _, err := s.Callscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/Plugin#Call().("onResponse", jsreq, jsres); err != nil { |
| 79 | 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().("%s", err) |
| 80 | return nil, nil |
| 81 | } else if jsres.WasModifiedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#WasModified().() { |
| 82 | jsres.UpdateHashscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/JSResponse#UpdateHash().() |
| 83 | return nil, jsres |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return nil, nil |
| 88 | } |
| 89 | |
| 90 | func (s *HttpProxyScriptscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#) OnCommandscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#OnCommand().(cmd string) bool { |
| 91 | if s.doOnCommandscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/http_proxy`/HttpProxyScript#doOnCommand. { |
| 92 | if ret, err := s.Callscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/plugin`/Plugin#Call().("onCommand", cmd); err != nil { |
| 93 | 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 onCommand callback: %+v", err) |
| 94 | return false |
| 95 | } else if v, ok := ret.(bool); ok { |
| 96 | return v |
| 97 | } |
| 98 | } |
| 99 | return false |
| 100 | } |