ffuf/pkg/input/input.go
Joona Hoikkala 5456a37f72
Multiple wordlist support (#79)
* Multiple wordlist support

* Display error correctly if wordlist file could not be opened

* Add back the redirect location

* Support multiple keywords in HTML output and fix wordlist positioning

* Support multiple wordlists for md output

* Support multiple keywords in CSV output

* Improve output for multi keyword runs

* Add changelog entry

* Switch the wordlist filename <-> keyword around to allow tab completion

* Fix the usage example in README
2019-11-10 23:30:54 +02:00

66 lines
1.6 KiB
Go

package input
import (
"github.com/ffuf/ffuf/pkg/ffuf"
)
type MainInputProvider struct {
Providers []ffuf.InternalInputProvider
Config *ffuf.Config
position int
}
func NewInputProvider(conf *ffuf.Config) ffuf.InputProvider {
return &MainInputProvider{Config: conf}
}
func (i *MainInputProvider) AddProvider(provider ffuf.InputProviderConfig) error {
if provider.Name == "command" {
newcomm, _ := NewCommandInput(provider.Keyword, provider.Value, i.Config)
i.Providers = append(i.Providers, newcomm)
} else {
// Default to wordlist
newwl, err := NewWordlistInput(provider.Keyword, provider.Value, i.Config)
if err != nil {
return err
}
i.Providers = append(i.Providers, newwl)
}
return nil
}
//Position will return the current position of progress
func (i *MainInputProvider) Position() int {
return i.position
}
//Next will increment the cursor position, and return a boolean telling if there's inputs left
func (i *MainInputProvider) Next() bool {
if i.position >= i.Total() {
return false
}
i.position++
return true
}
//Value returns a map of keyword:value pairs including all inputs
func (i *MainInputProvider) Value() map[string][]byte {
values := make(map[string][]byte)
for _, p := range i.Providers {
if !p.Next() {
// Loop to beginning if the inputprovider has been exhausted
p.ResetPosition()
}
values[p.Keyword()] = p.Value()
}
return values
}
//Total returns the amount of input combinations available
func (i *MainInputProvider) Total() int {
count := 1
for _, p := range i.Providers {
count = count * p.Total()
}
return count
}