From 2b4b58462c45cd59c1aedcee0a1c23fe6cfa5902 Mon Sep 17 00:00:00 2001 From: yungtravla Date: Wed, 10 Apr 2019 19:54:40 +1000 Subject: [PATCH 1/2] return more endpoint information with req.Client --- modules/http_proxy/http_proxy_js_request.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/http_proxy/http_proxy_js_request.go b/modules/http_proxy/http_proxy_js_request.go index 975c86a9..80f12ac9 100644 --- a/modules/http_proxy/http_proxy_js_request.go +++ b/modules/http_proxy/http_proxy_js_request.go @@ -8,10 +8,12 @@ import ( "net/url" "regexp" "strings" + + "github.com/bettercap/bettercap/session" ) type JSRequest struct { - Client string + Client map[string]string Method string Version string Scheme string @@ -43,8 +45,16 @@ func NewJSRequest(req *http.Request) *JSRequest { } } + client_ip := strings.Split(req.RemoteAddr, ":")[0] + client_mac := "" + client_alias := "" + if endpoint := session.I.Lan.GetByIp(client_ip); endpoint != nil { + client_mac = endpoint.HwAddress + client_alias = endpoint.Alias + } + jreq := &JSRequest{ - Client: strings.Split(req.RemoteAddr, ":")[0], + Client: map[string]string{"IP": client_ip, "MAC": client_mac, "Alias": client_alias}, Method: req.Method, Version: fmt.Sprintf("%d.%d", req.ProtoMajor, req.ProtoMinor), Scheme: req.URL.Scheme, From 62d46f50453268a49f791b72c48a05dc38e56058 Mon Sep 17 00:00:00 2001 From: yungtravla Date: Wed, 10 Apr 2019 20:27:17 +1000 Subject: [PATCH 2/2] fix NewHash function --- modules/http_proxy/http_proxy_js_request.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/http_proxy/http_proxy_js_request.go b/modules/http_proxy/http_proxy_js_request.go index 80f12ac9..ea6454a0 100644 --- a/modules/http_proxy/http_proxy_js_request.go +++ b/modules/http_proxy/http_proxy_js_request.go @@ -73,7 +73,7 @@ func NewJSRequest(req *http.Request) *JSRequest { } func (j *JSRequest) NewHash() string { - hash := fmt.Sprintf("%s.%s.%s.%s.%s.%s.%s.%s.%s", j.Client, j.Method, j.Version, j.Scheme, j.Hostname, j.Path, j.Query, j.ContentType, j.Headers) + hash := fmt.Sprintf("%s.%s.%s.%s.%s.%s.%s.%s.%s", j.Client["IP"], j.Method, j.Version, j.Scheme, j.Hostname, j.Path, j.Query, j.ContentType, j.Headers) hash += "." + j.Body return hash }