diff --git a/modules/base_proxy_script.go b/modules/base_proxy_script.go index 4cee92d8..f31c498a 100644 --- a/modules/base_proxy_script.go +++ b/modules/base_proxy_script.go @@ -3,6 +3,7 @@ package modules import ( "io/ioutil" "sync" + "encoding/base64" "github.com/bettercap/bettercap/log" "github.com/bettercap/bettercap/session" @@ -109,6 +110,69 @@ func (s *ProxyScript) defineBuiltins() error { return otto.Value{} }) + // log debug + s.VM.Set("log_debug", func(call otto.FunctionCall) otto.Value { + for _, v := range call.ArgumentList { + log.Debug("%s", v.String()) + } + return otto.Value{} + }) + + // log info + s.VM.Set("log_info", func(call otto.FunctionCall) otto.Value { + for _, v := range call.ArgumentList { + log.Info("%s", v.String()) + } + return otto.Value{} + }) + + // log warning + s.VM.Set("log_warn", func(call otto.FunctionCall) otto.Value { + for _, v := range call.ArgumentList { + log.Warning("%s", v.String()) + } + return otto.Value{} + }) + + // log error + s.VM.Set("log_error", func(call otto.FunctionCall) otto.Value { + for _, v := range call.ArgumentList { + log.Error("%s", v.String()) + } + return otto.Value{} + }) + + // log fatal + s.VM.Set("log_fatal", func(call otto.FunctionCall) otto.Value { + for _, v := range call.ArgumentList { + log.Fatal("%s", v.String()) + } + return otto.Value{} + }) + + // javascript btoa function + s.VM.Set("btoa", func(call otto.FunctionCall) otto.Value { + varValue := base64.StdEncoding.EncodeToString([]byte(call.Argument(0).String())) + v, err := s.VM.ToValue(varValue) + if err != nil { + return errOtto("Could not convert to string: %s", varValue) + } + return v + }) + + // javascript atob function + s.VM.Set("atob", func(call otto.FunctionCall) otto.Value { + varValue, err := base64.StdEncoding.DecodeString(call.Argument(0).String()) + if err != nil { + return errOtto("Could not decode string: %s", call.Argument(0).String()) + } + v, err := s.VM.ToValue(string(varValue)) + if err != nil { + return errOtto("Could not convert to string: %s", varValue) + } + return v + }) + // read or write environment variable s.VM.Set("env", func(call otto.FunctionCall) otto.Value { argv := call.ArgumentList