Debian Codegraph @

pkg/input/command.go

raw symbols SCIP
1 package input
2
3 import (
4 "bytes"
5 "os"
6 "os/exec"
7 "strconv"
8
9 "github.com/ffuf/ffuf/v2/pkg/ffuf"
10 )
11
12 type CommandInput struct {
13 config *ffuf.Config
14 count int
15 active bool
16 keyword string
17 command string
18 shell string
19 }
20
21 func NewCommandInput(keyword string, value string, conf *ffuf.Config) (*CommandInput, error) {
22 var cmd CommandInput
23 cmd.active = true
24 cmd.keyword = keyword
25 cmd.config = conf
26 cmd.count = 0
27 cmd.command = value
28 cmd.shell = SHELL_CMD
29
30 if cmd.config.InputShell != "" {
31 cmd.shell = cmd.config.InputShell
32 }
33
34 return &cmd, nil
35 }
36
37 // Keyword returns the keyword assigned to this InternalInputProvider
38 func (c *CommandInput) Keyword() string {
39 return c.keyword
40 }
41
42 // Position will return the current position in the input list
43 func (c *CommandInput) Position() int {
44 return c.count
45 }
46
47 // SetPosition will set the current position of the inputprovider
48 func (c *CommandInput) SetPosition(pos int) {
49 c.count = pos
50 }
51
52 // ResetPosition will reset the current position of the InternalInputProvider
53 func (c *CommandInput) ResetPosition() {
54 c.count = 0
55 }
56
57 // IncrementPosition increments the current position in the inputprovider
58 func (c *CommandInput) IncrementPosition() {
59 c.count += 1
60 }
61
62 // Next will increment the cursor position, and return a boolean telling if there's iterations left
63 func (c *CommandInput) Next() bool {
64 return c.count < c.config.InputNum
65 }
66
67 // Value returns the input from command stdoutput
68 func (c *CommandInput) Value() []byte {
69 var stdout bytes.Buffer
70 os.Setenv("FFUF_NUM", strconv.Itoa(c.count))
71 cmd := exec.Command(c.shell, SHELL_ARG, c.command)
72 cmd.Stdout = &stdout
73 err := cmd.Run()
74 if err != nil {
75 return []byte("")
76 }
77 return stdout.Bytes()
78 }
79
80 // Total returns the size of wordlist
81 func (c *CommandInput) Total() int {
82 return c.config.InputNum
83 }
84
85 func (c *CommandInput) Active() bool {
86 return c.active
87 }
88
89 func (c *CommandInput) Enable() {
90 c.active = true
91 }
92
93 func (c *CommandInput) Disable() {
94 c.active = false
95 }