mirror of
https://github.com/bettercap/bettercap
synced 2025-07-10 23:33:28 -07:00
fix: do not override req.Hostname in http proxy module script (fixes #678)
This commit is contained in:
parent
2b4188bb52
commit
1d306e6cd2
1 changed files with 21 additions and 4 deletions
|
@ -20,6 +20,7 @@ type JSRequest struct {
|
||||||
Path string
|
Path string
|
||||||
Query string
|
Query string
|
||||||
Hostname string
|
Hostname string
|
||||||
|
Port string
|
||||||
ContentType string
|
ContentType string
|
||||||
Headers string
|
Headers string
|
||||||
Body string
|
Body string
|
||||||
|
@ -58,7 +59,8 @@ func NewJSRequest(req *http.Request) *JSRequest {
|
||||||
Method: req.Method,
|
Method: req.Method,
|
||||||
Version: fmt.Sprintf("%d.%d", req.ProtoMajor, req.ProtoMinor),
|
Version: fmt.Sprintf("%d.%d", req.ProtoMajor, req.ProtoMinor),
|
||||||
Scheme: req.URL.Scheme,
|
Scheme: req.URL.Scheme,
|
||||||
Hostname: req.Host,
|
Hostname: req.URL.Hostname(),
|
||||||
|
Port: req.URL.Port(),
|
||||||
Path: req.URL.Path,
|
Path: req.URL.Path,
|
||||||
Query: req.URL.RawQuery,
|
Query: req.URL.RawQuery,
|
||||||
ContentType: cType,
|
ContentType: cType,
|
||||||
|
@ -73,7 +75,17 @@ func NewJSRequest(req *http.Request) *JSRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *JSRequest) NewHash() string {
|
func (j *JSRequest) NewHash() string {
|
||||||
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 := fmt.Sprintf("%s.%s.%s.%s.%s.%s.%s.%s.%s.%s",
|
||||||
|
j.Client["IP"],
|
||||||
|
j.Method,
|
||||||
|
j.Version,
|
||||||
|
j.Scheme,
|
||||||
|
j.Hostname,
|
||||||
|
j.Port,
|
||||||
|
j.Path,
|
||||||
|
j.Query,
|
||||||
|
j.ContentType,
|
||||||
|
j.Headers)
|
||||||
hash += "." + j.Body
|
hash += "." + j.Body
|
||||||
return hash
|
return hash
|
||||||
}
|
}
|
||||||
|
@ -114,7 +126,7 @@ func (j *JSRequest) SetHeader(name, value string) {
|
||||||
value = strings.TrimSpace(value)
|
value = strings.TrimSpace(value)
|
||||||
|
|
||||||
if strings.ToLower(name) == "content-type" {
|
if strings.ToLower(name) == "content-type" {
|
||||||
j.ContentType = value;
|
j.ContentType = value
|
||||||
}
|
}
|
||||||
|
|
||||||
headers := strings.Split(j.Headers, "\r\n")
|
headers := strings.Split(j.Headers, "\r\n")
|
||||||
|
@ -194,7 +206,12 @@ func (j *JSRequest) ParseForm() map[string]string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *JSRequest) ToRequest() (req *http.Request) {
|
func (j *JSRequest) ToRequest() (req *http.Request) {
|
||||||
url := fmt.Sprintf("%s://%s:%s%s?%s", j.Scheme, j.req.URL.Hostname(), j.req.URL.Port(), j.Path, j.Query)
|
portPart := ""
|
||||||
|
if j.Port != "" {
|
||||||
|
portPart = fmt.Sprintf(":%s", j.Port)
|
||||||
|
}
|
||||||
|
|
||||||
|
url := fmt.Sprintf("%s://%s%s%s?%s", j.Scheme, j.Hostname, portPart, j.Path, j.Query)
|
||||||
if j.Body == "" {
|
if j.Body == "" {
|
||||||
req, _ = http.NewRequest(j.Method, url, j.req.Body)
|
req, _ = http.NewRequest(j.Method, url, j.req.Body)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue