mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
new: exposing session environment to proxy scripts
This commit is contained in:
parent
1b3cc9fbca
commit
5b969ffa9e
4 changed files with 20 additions and 5 deletions
|
@ -5,6 +5,8 @@ import (
|
|||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/evilsocket/bettercap-ng/session"
|
||||
|
||||
"github.com/robertkrimen/otto"
|
||||
)
|
||||
|
||||
|
@ -20,7 +22,7 @@ type ProxyScript struct {
|
|||
cbCache map[string]bool
|
||||
}
|
||||
|
||||
func LoadProxyScript(path string) (err error, s *ProxyScript) {
|
||||
func LoadProxyScript(path string, sess *session.Session) (err error, s *ProxyScript) {
|
||||
log.Infof("Loading proxy script %s ...", path)
|
||||
|
||||
raw, err := ioutil.ReadFile(path)
|
||||
|
@ -29,9 +31,10 @@ func LoadProxyScript(path string) (err error, s *ProxyScript) {
|
|||
}
|
||||
|
||||
s = &ProxyScript{
|
||||
Path: path,
|
||||
Source: string(raw),
|
||||
VM: otto.New(),
|
||||
Path: path,
|
||||
Source: string(raw),
|
||||
VM: otto.New(),
|
||||
|
||||
gil: &sync.Mutex{},
|
||||
onRequestScript: nil,
|
||||
onResponseScript: nil,
|
||||
|
@ -45,6 +48,13 @@ func LoadProxyScript(path string) (err error, s *ProxyScript) {
|
|||
return
|
||||
}
|
||||
|
||||
// define session pointer
|
||||
err = s.VM.Set("env", *sess.Env.Storage())
|
||||
if err != nil {
|
||||
log.Errorf("Error while defining environment: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
// run onLoad if defined
|
||||
if s.hasCallback("onLoad") {
|
||||
_, err = s.VM.Run("onLoad()")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue