From 0633fb6b0aaa0332726e9b9d62c209846d1af78f Mon Sep 17 00:00:00 2001 From: Joona Hoikkala Date: Sat, 16 May 2020 15:49:57 +0300 Subject: [PATCH] Fixed behavior of wordlist:keyword separator in Windows (#240) --- .gitignore | 1 + main.go | 20 +++++++++++++++++++- pkg/ffuf/util.go | 10 ++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bc37ca7..2bbc392 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /ffuf +.idea diff --git a/main.go b/main.go index ab01a92..43ee02d 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "net/textproto" "net/url" "os" + "runtime" "strconv" "strings" @@ -303,7 +304,24 @@ func prepareConfig(parseOpts *cliOptions, conf *ffuf.Config) error { //Prepare inputproviders for _, v := range parseOpts.wordlists { - wl := strings.SplitN(v, ":", 2) + var wl []string + if runtime.GOOS == "windows" { + // Try to ensure that Windows file paths like C:\path\to\wordlist.txt:KEYWORD are treated properly + if ffuf.FileExists(v) { + // The wordlist was supplied without a keyword parameter + wl = []string{v} + } else { + filepart := v[:strings.LastIndex(v, ":")] + if ffuf.FileExists(filepart) { + wl = []string{filepart, v[strings.LastIndex(v, ":")+1:]} + } else { + // The file was not found. Use full wordlist parameter value for more concise error message down the line + wl = []string{v} + } + } + } else { + wl = strings.SplitN(v, ":", 2) + } if len(wl) == 2 { conf.InputProviders = append(conf.InputProviders, ffuf.InputProviderConfig{ Name: "wordlist", diff --git a/pkg/ffuf/util.go b/pkg/ffuf/util.go index ef12ffc..b078bec 100644 --- a/pkg/ffuf/util.go +++ b/pkg/ffuf/util.go @@ -2,6 +2,7 @@ package ffuf import ( "math/rand" + "os" ) //used for random string generation in calibration function @@ -29,3 +30,12 @@ func UniqStringSlice(inslice []string) []string { } return ret } + +//FileExists checks if the filepath exists and is not a directory +func FileExists(path string) bool { + md, err := os.Stat(path) + if os.IsNotExist(err) { + return false + } + return !md.IsDir() +}