Fixed behavior of wordlist:keyword separator in Windows (#240)

This commit is contained in:
Joona Hoikkala 2020-05-16 15:49:57 +03:00 committed by GitHub
parent 08ec6bad2a
commit 0633fb6b0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 1 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
/ffuf
.idea

20
main.go
View file

@ -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",

View file

@ -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()
}