mirror of
https://github.com/bettercap/bettercap
synced 2025-07-06 04:52:10 -07:00
Implement addSessionEvent function in DNS proxy script env
This commit is contained in:
parent
6de6de7418
commit
08e248e38c
1 changed files with 27 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
||||||
package dns_proxy
|
package dns_proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/bettercap/bettercap/v2/log"
|
"github.com/bettercap/bettercap/v2/log"
|
||||||
"github.com/bettercap/bettercap/v2/session"
|
"github.com/bettercap/bettercap/v2/session"
|
||||||
"github.com/evilsocket/islazy/plugin"
|
"github.com/evilsocket/islazy/plugin"
|
||||||
|
@ -32,6 +34,31 @@ func LoadDnsProxyScript(path string, sess *session.Session) (err error, s *DnsPr
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// define addSessionEvent function
|
||||||
|
err = plug.Set("addSessionEvent", func(call otto.FunctionCall) otto.Value {
|
||||||
|
if len(call.ArgumentList) < 2 {
|
||||||
|
log.Error("Failed to execute 'addSessionEvent' in DNS proxy: 2 arguments required, but only %d given.", len(call.ArgumentList))
|
||||||
|
return otto.FalseValue()
|
||||||
|
}
|
||||||
|
ottoTag := call.Argument(0)
|
||||||
|
if !ottoTag.IsString() {
|
||||||
|
log.Error("Failed to execute 'addSessionEvent' in DNS proxy: first argument must be a string.")
|
||||||
|
return otto.FalseValue()
|
||||||
|
}
|
||||||
|
tag := strings.TrimSpace(ottoTag.String())
|
||||||
|
if tag == "" {
|
||||||
|
log.Error("Failed to execute 'addSessionEvent' in DNS proxy: tag cannot be empty.")
|
||||||
|
return otto.FalseValue()
|
||||||
|
}
|
||||||
|
data := call.Argument(1)
|
||||||
|
sess.Events.Add(tag, data)
|
||||||
|
return otto.TrueValue()
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Error while defining addSessionEvent function: %+v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// run onLoad if defined
|
// run onLoad if defined
|
||||||
if plug.HasFunc("onLoad") {
|
if plug.HasFunc("onLoad") {
|
||||||
if _, err = plug.Call("onLoad"); err != nil {
|
if _, err = plug.Call("onLoad"); err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue