From 8fa9b5fdabd2e84244f8d9746cabffd6bc849349 Mon Sep 17 00:00:00 2001 From: h1x Date: Sat, 19 Feb 2022 15:16:55 +0100 Subject: [PATCH] Fix a recursion bug when redirected to the same domain and a port was specified (#377) This fixes the situation where the URL port is specified from the command line and the "Location" redirection header contains an absolute URL path. --- CHANGELOG.md | 1 + CONTRIBUTORS.md | 1 + pkg/ffuf/response.go | 30 +++++++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9b3d736..2815b3f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Fixed an issue where output (often a lot of it) would be printed after entering interactive mode - Fixed an issue when reading wordlist files from ffufrc - Fixed an issue where `-of all` option only creates one output file (instead of all formats) + - Fixed an issue where redirection to the same domain in recursive mode dropped port info from URL - Added HTTP2 support - v1.3.1 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 16249785..19409af8 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -20,6 +20,7 @@ * [fang0654](https://github.com/fang0654) * [Hazegard](https://github.com/Hazegard) * [helpermika](https://github.com/helpermika) +* [h1x](https://github.com/h1x-lnx) * [Ice3man543](https://github.com/Ice3man543) * [JamTookTheBait](https://github.com/JamTookTheBait) * [jimen0](https://github.com/jimen0) diff --git a/pkg/ffuf/response.go b/pkg/ffuf/response.go index fb188388..58f9f8da 100644 --- a/pkg/ffuf/response.go +++ b/pkg/ffuf/response.go @@ -43,12 +43,40 @@ func (resp *Response) GetRedirectLocation(absolute bool) string { if err != nil { return redirectLocation } - redirectLocation = baseUrl.ResolveReference(redirectUrl).String() + if redirectUrl.IsAbs() && UrlEqual(redirectUrl, baseUrl) { + redirectLocation = redirectUrl.Scheme + "://" + + baseUrl.Host + redirectUrl.Path + } else { + redirectLocation = baseUrl.ResolveReference(redirectUrl).String() + } } return redirectLocation } +func UrlEqual(url1, url2 *url.URL) bool { + if url1.Hostname() != url2.Hostname() { + return false + } + if url1.Scheme != url2.Scheme { + return false + } + p1, p2 := getUrlPort(url1), getUrlPort(url2) + return p1 == p2 +} + +func getUrlPort(url *url.URL) string { + var portMap = map[string]string{ + "http": "80", + "https": "443", + } + p := url.Port() + if p == "" { + p = portMap[url.Scheme] + } + return p +} + func NewResponse(httpresp *http.Response, req *Request) Response { var resp Response resp.Request = req