Handle relative URLs in redirects properly (#167)
This commit is contained in:
parent
a19741daa6
commit
ff1bc2a3c2
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
- Changed
|
- Changed
|
||||||
- Write POST request data properly to file when ran with `-od`
|
- Write POST request data properly to file when ran with `-od`
|
||||||
|
- Properly handle relative redirect urls with `-recursion`
|
||||||
|
|
||||||
- v1.0.1
|
- v1.0.1
|
||||||
- Changed
|
- Changed
|
||||||
|
|||||||
@ -279,7 +279,7 @@ func (j *Job) runTask(input map[string][]byte, position int, retried bool) {
|
|||||||
j.updateProgress()
|
j.updateProgress()
|
||||||
}
|
}
|
||||||
|
|
||||||
if j.Config.Recursion && len(resp.GetRedirectLocation()) > 0 {
|
if j.Config.Recursion && len(resp.GetRedirectLocation(false)) > 0 {
|
||||||
j.handleRecursionJob(resp)
|
j.handleRecursionJob(resp)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -287,7 +287,7 @@ func (j *Job) runTask(input map[string][]byte, position int, retried bool) {
|
|||||||
|
|
||||||
//handleRecursionJob adds a new recursion job to the job queue if a new directory is found
|
//handleRecursionJob adds a new recursion job to the job queue if a new directory is found
|
||||||
func (j *Job) handleRecursionJob(resp Response) {
|
func (j *Job) handleRecursionJob(resp Response) {
|
||||||
if (resp.Request.Url + "/") != resp.GetRedirectLocation() {
|
if (resp.Request.Url + "/") != resp.GetRedirectLocation(true) {
|
||||||
// Not a directory, return early
|
// Not a directory, return early
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -298,7 +298,7 @@ func (j *Job) handleRecursionJob(resp Response) {
|
|||||||
j.queuejobs = append(j.queuejobs, newJob)
|
j.queuejobs = append(j.queuejobs, newJob)
|
||||||
j.Output.Info(fmt.Sprintf("Adding a new job to the queue: %s", recUrl))
|
j.Output.Info(fmt.Sprintf("Adding a new job to the queue: %s", recUrl))
|
||||||
} else {
|
} else {
|
||||||
j.Output.Warning(fmt.Sprintf("Directory found, but recursion depth exceeded. Ignoring: %s", resp.GetRedirectLocation()))
|
j.Output.Warning(fmt.Sprintf("Directory found, but recursion depth exceeded. Ignoring: %s", resp.GetRedirectLocation(true)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package ffuf
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Response struct holds the meaningful data returned from request and is meant for passing to filters
|
// Response struct holds the meaningful data returned from request and is meant for passing to filters
|
||||||
@ -19,13 +20,25 @@ type Response struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetRedirectLocation returns the redirect location for a 3xx redirect HTTP response
|
// GetRedirectLocation returns the redirect location for a 3xx redirect HTTP response
|
||||||
func (resp *Response) GetRedirectLocation() string {
|
func (resp *Response) GetRedirectLocation(absolute bool) string {
|
||||||
|
|
||||||
redirectLocation := ""
|
redirectLocation := ""
|
||||||
if resp.StatusCode >= 300 && resp.StatusCode <= 399 {
|
if resp.StatusCode >= 300 && resp.StatusCode <= 399 {
|
||||||
redirectLocation = resp.Headers["Location"][0]
|
redirectLocation = resp.Headers["Location"][0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if absolute {
|
||||||
|
redirectUrl, err := url.Parse(redirectLocation)
|
||||||
|
if err != nil {
|
||||||
|
return redirectLocation
|
||||||
|
}
|
||||||
|
baseUrl, err := url.Parse(resp.Request.Url)
|
||||||
|
if err != nil {
|
||||||
|
return redirectLocation
|
||||||
|
}
|
||||||
|
redirectLocation = baseUrl.ResolveReference(redirectUrl).String()
|
||||||
|
}
|
||||||
|
|
||||||
return redirectLocation
|
return redirectLocation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -233,7 +233,7 @@ func (s *Stdoutput) Result(resp ffuf.Response) {
|
|||||||
ContentLength: resp.ContentLength,
|
ContentLength: resp.ContentLength,
|
||||||
ContentWords: resp.ContentWords,
|
ContentWords: resp.ContentWords,
|
||||||
ContentLines: resp.ContentLines,
|
ContentLines: resp.ContentLines,
|
||||||
RedirectLocation: resp.GetRedirectLocation(),
|
RedirectLocation: resp.GetRedirectLocation(false),
|
||||||
Url: resp.Request.Url,
|
Url: resp.Request.Url,
|
||||||
ResultFile: resp.ResultFile,
|
ResultFile: resp.ResultFile,
|
||||||
}
|
}
|
||||||
@ -315,7 +315,7 @@ func (s *Stdoutput) resultMultiline(resp ffuf.Response) {
|
|||||||
reslines := ""
|
reslines := ""
|
||||||
if s.config.Verbose {
|
if s.config.Verbose {
|
||||||
reslines = fmt.Sprintf("%s%s| URL | %s\n", reslines, TERMINAL_CLEAR_LINE, resp.Request.Url)
|
reslines = fmt.Sprintf("%s%s| URL | %s\n", reslines, TERMINAL_CLEAR_LINE, resp.Request.Url)
|
||||||
redirectLocation := resp.GetRedirectLocation()
|
redirectLocation := resp.GetRedirectLocation(false)
|
||||||
if redirectLocation != "" {
|
if redirectLocation != "" {
|
||||||
reslines = fmt.Sprintf("%s%s| --> | %s\n", reslines, TERMINAL_CLEAR_LINE, redirectLocation)
|
reslines = fmt.Sprintf("%s%s| --> | %s\n", reslines, TERMINAL_CLEAR_LINE, redirectLocation)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user