| 1 | package inputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/ |
| 2 | |
| 3 | import ( |
| 4 | "bufioscip-go gomod github.com/golang/go/src go1.18 bufio/" |
| 5 | "osscip-go gomod github.com/golang/go/src go1.18 os/" |
| 6 | "regexpscip-go gomod github.com/golang/go/src go1.18 regexp/" |
| 7 | "stringsscip-go gomod github.com/golang/go/src go1.18 strings/" |
| 8 | |
| 9 | "github.com/ffuf/ffuf/v2/pkg/ffufscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/" |
| 10 | ) |
| 11 | |
| 12 | type WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput# struct { |
| 13 | activescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#active. bool |
| 14 | configscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#config. *ffufscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/.Configscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Config# |
| 15 | datascip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#data. [][]byte |
| 16 | positionscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#position. int |
| 17 | keywordscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#keyword. string |
| 18 | } |
| 19 | |
| 20 | func NewWordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/NewWordlistInput().(keyword string, value string, conf *ffufscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/.Configscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Config#) (*WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#, error) { |
| 21 | var wl WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput# |
| 22 | wl.activescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#active. = true |
| 23 | wl.keywordscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#keyword. = keyword |
| 24 | wl.configscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#config. = conf |
| 25 | wl.positionscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#position. = 0 |
| 26 | var valid bool |
| 27 | var err error |
| 28 | // stdin? |
| 29 | if value == "-" { |
| 30 | // yes |
| 31 | valid = true |
| 32 | } else { |
| 33 | // no |
| 34 | valid, err = wl.validFilescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#validFile().(value) |
| 35 | } |
| 36 | if err != nil { |
| 37 | return &wl, err |
| 38 | } |
| 39 | if valid { |
| 40 | err = wl.readFilescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#readFile().(value) |
| 41 | } |
| 42 | return &wl, err |
| 43 | } |
| 44 | |
| 45 | // Position will return the current position in the input list |
| 46 | func (w *WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#) Positionscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#Position().() int { |
| 47 | return w.positionscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#position. |
| 48 | } |
| 49 | |
| 50 | // SetPosition sets the current position of the inputprovider |
| 51 | func (w *WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#) SetPositionscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#SetPosition().(pos int) { |
| 52 | w.positionscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#position. = pos |
| 53 | } |
| 54 | |
| 55 | // ResetPosition resets the position back to beginning of the wordlist. |
| 56 | func (w *WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#) ResetPositionscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#ResetPosition().() { |
| 57 | w.positionscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#position. = 0 |
| 58 | } |
| 59 | |
| 60 | // Keyword returns the keyword assigned to this InternalInputProvider |
| 61 | func (w *WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#) Keywordscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#Keyword().() string { |
| 62 | return w.keywordscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#keyword. |
| 63 | } |
| 64 | |
| 65 | // Next will return a boolean telling if there's words left in the list |
| 66 | func (w *WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#) Nextscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#Next().() bool { |
| 67 | return w.positionscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#position. < len(w.datascip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#data.) |
| 68 | } |
| 69 | |
| 70 | // IncrementPosition will increment the current position in the inputprovider data slice |
| 71 | func (w *WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#) IncrementPositionscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#IncrementPosition().() { |
| 72 | w.positionscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#position. += 1 |
| 73 | } |
| 74 | |
| 75 | // Value returns the value from wordlist at current cursor position |
| 76 | func (w *WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#) Valuescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#Value().() []byte { |
| 77 | return w.datascip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#data.[w.positionscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#position.] |
| 78 | } |
| 79 | |
| 80 | // Total returns the size of wordlist |
| 81 | func (w *WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#) Totalscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#Total().() int { |
| 82 | return len(w.datascip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#data.) |
| 83 | } |
| 84 | |
| 85 | // Active returns boolean if the inputprovider is active |
| 86 | func (w *WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#) Activescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#Active().() bool { |
| 87 | return w.activescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#active. |
| 88 | } |
| 89 | |
| 90 | // Enable sets the inputprovider as active |
| 91 | func (w *WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#) Enablescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#Enable().() { |
| 92 | w.activescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#active. = true |
| 93 | } |
| 94 | |
| 95 | // Disable disables the inputprovider |
| 96 | func (w *WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#) Disablescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#Disable().() { |
| 97 | w.activescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#active. = false |
| 98 | } |
| 99 | |
| 100 | // validFile checks that the wordlist file exists and can be read |
| 101 | func (w *WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#) validFilescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#validFile().(path string) (bool, error) { |
| 102 | _, err := osscip-go gomod github.com/golang/go/src go1.18 os/.Statscip-go gomod github.com/golang/go/src go1.18 os/Stat().(path) |
| 103 | if err != nil { |
| 104 | return false, err |
| 105 | } |
| 106 | f, err := osscip-go gomod github.com/golang/go/src go1.18 os/.Openscip-go gomod github.com/golang/go/src go1.18 os/Open().(path) |
| 107 | if err != nil { |
| 108 | return false, err |
| 109 | } |
| 110 | f.Closescip-go gomod github.com/golang/go/src go1.18 os/File#Close().() |
| 111 | return true, nil |
| 112 | } |
| 113 | |
| 114 | // readFile reads the file line by line to a byte slice |
| 115 | func (w *WordlistInputscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#) readFilescip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#readFile().(path string) error { |
| 116 | var file *osscip-go gomod github.com/golang/go/src go1.18 os/.Filescip-go gomod github.com/golang/go/src go1.18 os/File# |
| 117 | var err error |
| 118 | if path == "-" { |
| 119 | file = osscip-go gomod github.com/golang/go/src go1.18 os/.Stdinscip-go gomod github.com/golang/go/src go1.18 os/Stdin. |
| 120 | } else { |
| 121 | file, err = osscip-go gomod github.com/golang/go/src go1.18 os/.Openscip-go gomod github.com/golang/go/src go1.18 os/Open().(path) |
| 122 | if err != nil { |
| 123 | return err |
| 124 | } |
| 125 | } |
| 126 | defer file.Closescip-go gomod github.com/golang/go/src go1.18 os/File#Close().() |
| 127 | |
| 128 | var data [][]byte |
| 129 | var ok bool |
| 130 | reader := bufioscip-go gomod github.com/golang/go/src go1.18 bufio/.NewScannerscip-go gomod github.com/golang/go/src go1.18 bufio/NewScanner().(file) |
| 131 | re := regexpscip-go gomod github.com/golang/go/src go1.18 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.18 regexp/MustCompile().(`(?i)%ext%`) |
| 132 | for reader.Scanscip-go gomod github.com/golang/go/src go1.18 bufio/Scanner#Scan().() { |
| 133 | if w.configscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#config..DirSearchCompatscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Config#DirSearchCompat. && len(w.configscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#config..Extensionsscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Config#Extensions.) > 0 { |
| 134 | text := []byte(reader.Textscip-go gomod github.com/golang/go/src go1.18 bufio/Scanner#Text().()) |
| 135 | if re.Matchscip-go gomod github.com/golang/go/src go1.18 regexp/Regexp#Match().(text) { |
| 136 | for _, ext := range w.configscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#config..Extensionsscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Config#Extensions. { |
| 137 | contnt := re.ReplaceAllscip-go gomod github.com/golang/go/src go1.18 regexp/Regexp#ReplaceAll().(text, []byte(ext)) |
| 138 | data = append(data, []byte(contnt)) |
| 139 | } |
| 140 | } else { |
| 141 | text := reader.Textscip-go gomod github.com/golang/go/src go1.18 bufio/Scanner#Text().() |
| 142 | |
| 143 | if w.configscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#config..IgnoreWordlistCommentsscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Config#IgnoreWordlistComments. { |
| 144 | text, ok = stripCommentsscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/stripComments().(text) |
| 145 | if !ok { |
| 146 | continue |
| 147 | } |
| 148 | } |
| 149 | data = append(data, []byte(text)) |
| 150 | } |
| 151 | } else { |
| 152 | text := reader.Textscip-go gomod github.com/golang/go/src go1.18 bufio/Scanner#Text().() |
| 153 | |
| 154 | if w.configscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#config..IgnoreWordlistCommentsscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Config#IgnoreWordlistComments. { |
| 155 | text, ok = stripCommentsscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/stripComments().(text) |
| 156 | if !ok { |
| 157 | continue |
| 158 | } |
| 159 | } |
| 160 | data = append(data, []byte(text)) |
| 161 | if w.keywordscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#keyword. == "FUZZ" && len(w.configscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#config..Extensionsscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Config#Extensions.) > 0 { |
| 162 | for _, ext := range w.configscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#config..Extensionsscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/ffuf`/Config#Extensions. { |
| 163 | data = append(data, []byte(text+ext)) |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | w.datascip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/WordlistInput#data. = data |
| 169 | return reader.Errscip-go gomod github.com/golang/go/src go1.18 bufio/Scanner#Err().() |
| 170 | } |
| 171 | |
| 172 | // stripComments removes all kind of comments from the word |
| 173 | func stripCommentsscip-go gomod github.com/ffuf/ffuf/v2 . `github.com/ffuf/ffuf/v2/pkg/input`/stripComments().(text string) (string, bool) { |
| 174 | // If the line starts with a # ignoring any space on the left, |
| 175 | // return blank. |
| 176 | if stringsscip-go gomod github.com/golang/go/src go1.18 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.18 strings/HasPrefix().(stringsscip-go gomod github.com/golang/go/src go1.18 strings/.TrimLeftscip-go gomod github.com/golang/go/src go1.18 strings/TrimLeft().(text, " "), "#") { |
| 177 | return "", false |
| 178 | } |
| 179 | |
| 180 | // If the line has # later after a space, that's a comment. |
| 181 | // Only send the word upto space to the routine. |
| 182 | index := stringsscip-go gomod github.com/golang/go/src go1.18 strings/.Indexscip-go gomod github.com/golang/go/src go1.18 strings/Index().(text, " #") |
| 183 | if index == -1 { |
| 184 | return text, true |
| 185 | } |
| 186 | return text[:index], true |
| 187 | } |