ffuff/pkg/ffuf/util.go
M. Ángel Jimeno c6a6293499
pkg/ffuf: fix panic in Windows when parsing wordlist flag (#335)
This change addresses two panics that happened while parsing the provided
wordlist flag in Windows systems.

- pkg/ffuf/util.go:40: panic happened when the provided path was
invalid. Example: ".\wordlist.txt:" as the os.Stat call returned an
error different than os.ErrNotExist.

- pkg/ffuf/optionsparser.go:179: panic happened when the provided value
did not existed and did not contain a colon character. Example:
".\asdf.txt" when the local file ".\asdf.txt" did not exist. This panic
happened due to strings.LastIndex returning -1 when the provided
substring does not appear. Therefore, v[:-1] panicking.

Fixes #333

Signed-off-by: Miguel Ángel Jimeno <miguelangel4b@gmail.com>
2020-10-26 23:43:09 +02:00

44 lines
944 B
Go

package ffuf
import (
"math/rand"
"os"
)
//used for random string generation in calibration function
var chars = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
//RandomString returns a random string of length of parameter n
func RandomString(n int) string {
s := make([]rune, n)
for i := range s {
s[i] = chars[rand.Intn(len(chars))]
}
return string(s)
}
//UniqStringSlice returns an unordered slice of unique strings. The duplicates are dropped
func UniqStringSlice(inslice []string) []string {
found := map[string]bool{}
for _, v := range inslice {
found[v] = true
}
ret := []string{}
for k := range found {
ret = append(ret, k)
}
return ret
}
//FileExists checks if the filepath exists and is not a directory.
//Returns false in case it's not possible to describe the named file.
func FileExists(path string) bool {
md, err := os.Stat(path)
if err != nil {
return false
}
return !md.IsDir()
}