diff --git a/caplets/beef-inject.js b/caplets/beef-inject.js index ef5499ad..58dbd6f3 100644 --- a/caplets/beef-inject.js +++ b/caplets/beef-inject.js @@ -11,7 +11,6 @@ function onResponse(req, res) { '', '' ); - res.Updated(); } } } diff --git a/caplets/fb-phish.js b/caplets/fb-phish.js index be05cb73..1a1734b0 100644 --- a/caplets/fb-phish.js +++ b/caplets/fb-phish.js @@ -19,6 +19,5 @@ function onRequest(req, res) { res.Status = 301; res.Headers = "Location: https://www.facebook.com/\n" + "Connection: close"; - res.Updated() } } diff --git a/caplets/login-man-abuse.js b/caplets/login-man-abuse.js index 9cf09353..0884df0c 100644 --- a/caplets/login-man-abuse.js +++ b/caplets/login-man-abuse.js @@ -26,7 +26,6 @@ function onRequest(req, res) { res.ContentType = "text/html"; res.Headers = "Connection: close"; res.Body = ""; - res.Updated(); } } @@ -42,7 +41,6 @@ function onResponse(req, res) { '' + '' ); - res.Updated(); } } } diff --git a/caplets/proxy-script-test.js b/caplets/proxy-script-test.js index f8173d04..5b02bba9 100644 --- a/caplets/proxy-script-test.js +++ b/caplets/proxy-script-test.js @@ -18,8 +18,6 @@ function onRequest(req, res) { "
Hello world from bettercap-ng!
" + "" + ""; - - res.Updated(); } } @@ -37,6 +35,5 @@ function onResponse(req, res) { "
Custom 404 from bettercap-ng.
" + "" + ""; - res.Updated(); } } diff --git a/caplets/web-override.js b/caplets/web-override.js index 1bc28afd..4d5de11b 100644 --- a/caplets/web-override.js +++ b/caplets/web-override.js @@ -5,6 +5,4 @@ function onRequest(req, res) { res.ContentType = "text/html"; res.Headers = "Connection: close"; res.Body = readFile("caplets/www/index.html"); - - res.Updated(); } diff --git a/modules/http_proxy_js_response.go b/modules/http_proxy_js_response.go index aa45db98..cda4fa02 100644 --- a/modules/http_proxy_js_response.go +++ b/modules/http_proxy_js_response.go @@ -1,6 +1,7 @@ package modules import ( + "fmt" "io/ioutil" "net/http" "strings" @@ -16,8 +17,8 @@ type JSResponse struct { Headers string Body string - wasUpdated bool - resp *http.Response + refHash string + resp *http.Response } func NewJSResponse(res *http.Response) *JSResponse { @@ -33,16 +34,31 @@ func NewJSResponse(res *http.Response) *JSResponse { } } - return &JSResponse{ + resp := &JSResponse{ Status: res.StatusCode, ContentType: cType, Headers: headers, resp: res, } + resp.UpdateHash() + + return resp } -func (j *JSResponse) Updated() { - j.wasUpdated = true +func (j *JSResponse) NewHash() string { + return fmt.Sprintf("%d.%s.%s.%s", j.Status, j.ContentType, j.Headers, j.Body) +} + +func (j *JSResponse) UpdateHash() { + j.refHash = j.NewHash() +} + +func (j *JSResponse) WasModified() bool { + newHash := j.NewHash() + if newHash != j.refHash { + return true + } + return false } func (j *JSResponse) ToResponse(req *http.Request) (resp *http.Response) { @@ -71,6 +87,7 @@ func (j *JSResponse) ReadBody() string { } j.Body = string(raw) + j.UpdateHash() return j.Body } diff --git a/modules/http_proxy_script.go b/modules/http_proxy_script.go index 65067e31..d0778ce2 100644 --- a/modules/http_proxy_script.go +++ b/modules/http_proxy_script.go @@ -168,7 +168,8 @@ func (s *ProxyScript) OnRequest(req *http.Request) *JSResponse { return nil } - if jsres.wasUpdated == true { + if jsres.WasModified() { + jsres.UpdateHash() return jsres } } @@ -193,7 +194,8 @@ func (s *ProxyScript) OnResponse(res *http.Response) *JSResponse { return nil } - if jsres.wasUpdated == true { + if jsres.WasModified() { + jsres.UpdateHash() return jsres } }