ffuff/pkg/input/command.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

69 lines
1.4 KiB
Go

package input
import (
"bytes"
"os"
"os/exec"
"strconv"
"github.com/ffuf/ffuf/pkg/ffuf"
)
type CommandInput struct {
config *ffuf.Config
count int
keyword string
command string
}
func NewCommandInput(keyword string, value string, conf *ffuf.Config) (*CommandInput, error) {
var cmd CommandInput
cmd.keyword = keyword
cmd.config = conf
cmd.count = -1
cmd.command = value
return &cmd, nil
}
//Keyword returns the keyword assigned to this InternalInputProvider
func (c *CommandInput) Keyword() string {
return c.keyword
}
//Position will return the current position in the input list
func (c *CommandInput) Position() int {
return c.count
}
//ResetPosition will reset the current position of the InternalInputProvider
func (c *CommandInput) ResetPosition() {
c.count = 0
}
//Next will increment the cursor position, and return a boolean telling if there's iterations left
func (c *CommandInput) Next() bool {
c.count++
if c.count >= c.config.InputNum {
return false
}
return true
}
//Value returns the input from command stdoutput
func (c *CommandInput) Value() []byte {
var stdout bytes.Buffer
os.Setenv("FFUF_NUM", strconv.Itoa(c.count))
cmd := exec.Command(SHELL_CMD, SHELL_ARG, c.command)
cmd.Stdout = &stdout
err := cmd.Run()
if err != nil {
return []byte("")
}
return stdout.Bytes()
}
//Total returns the size of wordlist
func (c *CommandInput) Total() int {
return c.config.InputNum
}