Skip to content

Commit b8109c6

Browse files
committed
full display
1 parent 96265e9 commit b8109c6

File tree

6 files changed

+106
-44
lines changed

6 files changed

+106
-44
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Additionaly, it is possible to filter displayed results:
8282
-emin, --stderr-min filter to only display if stderr characters number is lesser than n
8383
-emax, --stderr-max filter to only display if stderr characters number is greater than n
8484
-eeq, --stderr-equal filter to only display if stderr characters number is equal to n
85+
-ew, --stderr-word filter to only display if stderr cointains specific word
8586
```
8687
8788
**execution time filters:**
@@ -122,5 +123,6 @@ It is also possible to choose which result field is displayed in `cfuzz` output
122123
-t, --time display execution time
123124
-c, --code display exit code
124125
-Hb, --no-banner do not display banner
125-
-w, --only-word only display words
126+
-r, --only-word only display words
127+
-f, --full-output display full command execution output (can't be combined with others display mode)
126128
```

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module github.com/ariary/cfuzz
22

33
go 1.17
4+
5+
require github.com/ariary/go-utils v1.0.16

pkg/fuzz/config.go

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Config struct {
2424
Multiple bool
2525
StdinWordlist bool
2626
DisplayModes []DisplayMode
27+
FullDisplay bool
2728
HideBanner bool
2829
Hide bool
2930
Filters []Filter
@@ -43,31 +44,30 @@ CONFIGURATION
4344
-if, --stdin-fuzzing fuzz sdtin instead of command line
4445
-m, --spider fuzz multiple keyword places. You must provide as many wordlists as keywords. Provide them in order you want them to be applied.
4546
-sw, --stdin-wordlist provide wordlist in cfuzz stdin
46-
-T, --threads number of concurrent threads (if no limit is set the execution of the command could be modified)
4747
4848
DISPLAY
4949
-oc, --stdout display stdout number of characters
5050
-ec, --stderr display stderr number of characters
5151
-t, --time display execution time
5252
-c, --code display exit code
5353
-Hb, --no-banner do not display banner
54-
-w, --only-word only display words
55-
54+
-r, --only-word only display words (from wordlist)
55+
-f, --full-output display full command execution output (can't be combined with others display mode)
5656
5757
FILTER
58-
5958
-H, --hide only display results that don't pass the filters
6059
6160
STDOUT:
6261
-omin, --stdout-min filter to only display if stdout characters number is lesser than n
6362
-omax, --stdout-max filter to only display if stdout characters number is greater than n
6463
-oeq, --stdout-equal filter to only display if stdout characters number is equal to n
65-
-r, --stdout-word filter to only display if stdout cointains specific word
64+
-ow, --stdout-word filter to only display if stdout cointains specific word
6665
6766
STDERR:
6867
-emin, --stderr-min filter to only display if stderr characters number is lesser than n
6968
-emax, --stderr-max filter to only display if stderr characters number is greater than n
7069
-eeq, --stderr-equal filter to only display if stderr characters number is equal to n
70+
-ew, --stderr-word filter to only display if stderr cointains specific word
7171
7272
TIME:
7373
-tmin, --time-min filter to only display if exectuion time is shorter than n seconds
@@ -168,6 +168,9 @@ func NewConfig() Config {
168168
flag.BoolVar(&codeDisplay, "c", false, "display command execution exit code.")
169169
flag.BoolVar(&codeDisplay, "code", false, "display command execution exit code.")
170170

171+
flag.BoolVar(&config.FullDisplay, "f", false, "display full command execution output")
172+
flag.BoolVar(&config.FullDisplay, "full-output", false, "display full command execution output")
173+
171174
// FILTERS
172175
var success, failure bool
173176
flag.BoolVar(&success, "success", false, "filter to display only command with exit code 0.")
@@ -190,7 +193,7 @@ func NewConfig() Config {
190193

191194
// parse display mode
192195
if !noDisplay {
193-
config.DisplayModes = parseDisplayMode(stdoutDisplay, stderrDisplay, timeDisplay, codeDisplay)
196+
config.DisplayModes = parseDisplayMode(&config, stdoutDisplay, stderrDisplay, timeDisplay, codeDisplay)
194197
}
195198

196199
return config
@@ -222,6 +225,10 @@ func (c *Config) CheckConfig() error {
222225
} else if !c.Multiple && len(c.Wordlists) > 1 {
223226
return errors.New("Several wordlists have been submitted. Please use -m flag to use more than one wordlist/keyword")
224227
}
228+
229+
if c.FullDisplay && len(c.DisplayModes) > 0 {
230+
return errors.New("-f/full-output can't be used with other display mode:" + c.DisplayModes[0].Name()) //only give the first one for example
231+
}
225232
// check field consistency
226233
err := checkKeywordsPresence(c)
227234

@@ -254,7 +261,7 @@ func checkKeywordsPresence(c *Config) error {
254261
}
255262

256263
//parseDisplayMode: Return array of display mode interface chosen with flags. If none, default is stdout characters display mode
257-
func parseDisplayMode(stdout bool, stderr bool, time bool, code bool) (modes []DisplayMode) {
264+
func parseDisplayMode(c *Config, stdout bool, stderr bool, time bool, code bool) (modes []DisplayMode) {
258265
if stdout {
259266
modes = append(modes, StdoutDisplay{})
260267
}
@@ -268,11 +275,14 @@ func parseDisplayMode(stdout bool, stderr bool, time bool, code bool) (modes []D
268275
modes = append(modes, CodeDisplay{})
269276
}
270277

271-
//default, if none
272-
if len(modes) == 0 {
273-
stdoutDisplay := StdoutDisplay{}
274-
modes = []DisplayMode{stdoutDisplay}
278+
//default, if none && not full display
279+
if !c.FullDisplay {
280+
if len(modes) == 0 {
281+
stdoutDisplay := StdoutDisplay{}
282+
modes = []DisplayMode{stdoutDisplay}
283+
}
275284
}
285+
276286
return modes
277287
}
278288

@@ -367,6 +377,15 @@ func parseFilters(config *Config) {
367377
})
368378
}
369379

380+
ewordS := []string{"ew", "stderr-word"}
381+
for i := 0; i < len(ewordS); i++ {
382+
flag.Func(ewordS[i], "filter to display only results cointaing specific in stderr", func(word string) error {
383+
filter := StderrWordFilter{TargetWord: word}
384+
config.Filters = append(config.Filters, filter)
385+
return nil
386+
})
387+
}
388+
370389
// time filters
371390
tmaxS := []string{"tmax", "time-max"}
372391
for i := 0; i < len(tmaxS); i++ {

pkg/fuzz/filter.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package fuzz
22

3-
import "strings"
3+
import (
4+
"strings"
5+
)
46

57
// Filter: interface used to determine which results will be displayed
68
type Filter interface {
@@ -10,6 +12,8 @@ type Filter interface {
1012
Name() string
1113
}
1214

15+
// STDOUT FILTERS
16+
1317
// StdoutMaxFilter: Filter that accept only result with less characters than a specific number
1418
type StdoutMaxFilter struct {
1519
Max int
@@ -38,7 +42,7 @@ func (filter StdoutMinFilter) IsOk(result ExecResult) bool {
3842
return len(result.Stdout) >= filter.Min
3943
}
4044

41-
//StdoutEqFilter: filter struct that accept only result with exact amoun of characters
45+
//StdoutEqFilter: filter struct that accept only result with exact amount of characters
4246
type StdoutEqFilter struct {
4347
Eq int
4448
}
@@ -68,6 +72,8 @@ func (filter StdoutWordFilter) IsOk(result ExecResult) bool {
6872
return strings.Contains(result.Stdout, filter.TargetWord)
6973
}
7074

75+
// STDERR FILTERS
76+
7177
//StderrMaxFilter: Filter that accept only result with less characters than a specific number
7278
type StderrMaxFilter struct {
7379
Max int
@@ -108,6 +114,24 @@ func (filter StderrEqFilter) IsOk(result ExecResult) bool {
108114
return len(result.Stderr) == filter.Eq
109115
}
110116

117+
//StderrWordFilter: filter struct that accept only result containing specific word for stderr
118+
type StderrWordFilter struct {
119+
TargetWord string
120+
}
121+
122+
//Name: return StdoutWordFilter name
123+
func (filter StderrWordFilter) Name() string {
124+
return "stderr word containing"
125+
}
126+
127+
//IsOK: return true a specific word is found in result stdout. Note that this is equivalent to grep:
128+
//the word could be surrounded by non-space characters
129+
func (filter StderrWordFilter) IsOk(result ExecResult) bool {
130+
return strings.Contains(result.Stderr, filter.TargetWord)
131+
}
132+
133+
// TIME FILTERS
134+
111135
type TimeMaxFilter struct {
112136
Max int
113137
}
@@ -144,6 +168,8 @@ func (filter TimeEqFilter) IsOk(result ExecResult) bool {
144168
return int(result.Time.Seconds()) == filter.Eq
145169
}
146170

171+
// CODE FILTERS
172+
147173
// CodeSuccessFilter: filter wether result regarding the exit code
148174
type CodeSuccessFilter struct {
149175
Zero bool

pkg/fuzz/fuzz.go

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -193,29 +193,22 @@ func Exec(cfg Config, wg *sync.WaitGroup, substitutesStr []string) {
193193

194194
// PrintExec: Print execution result according to configuration and filter
195195
func PrintExec(cfg Config, result ExecResult) {
196-
// filter
197-
// if cfg.Hide { //hide field that pass filter and show others
198-
// for i := 0; i < len(cfg.Filters); i++ {
199-
// if cfg.Filters[i].IsOk(result) {
200-
// return //don't display it
201-
// }
202-
// }
203-
// } else {
204-
// for i := 0; i < len(cfg.Filters); i++ {
205-
// if !cfg.Filters[i].IsOk(result) {
206-
// return //don't display it
207-
// }
208-
// }
209-
// }
210-
for i := 0; i < len(cfg.Filters); i++ {
211-
if cfg.Filters[i].IsOk(result) == cfg.Hide {
212-
return //don't display it
196+
if cfg.FullDisplay {
197+
PrintFullExecOutput(cfg, result)
198+
return
199+
} else {
200+
201+
for i := 0; i < len(cfg.Filters); i++ {
202+
if cfg.Filters[i].IsOk(result) == cfg.Hide {
203+
return //don't display it
204+
}
213205
}
206+
// display
207+
208+
var fields []string
209+
for i := 0; i < len(cfg.DisplayModes); i++ {
210+
fields = append(fields, cfg.DisplayModes[i].DisplayString(result))
211+
}
212+
PrintLine(cfg, result.Substitute, fields...)
214213
}
215-
// display
216-
var fields []string
217-
for i := 0; i < len(cfg.DisplayModes); i++ {
218-
fields = append(fields, cfg.DisplayModes[i].DisplayString(result))
219-
}
220-
PrintLine(cfg, result.Substitute, fields...)
221214
}

pkg/fuzz/output.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@ import (
44
"fmt"
55
"strings"
66
"text/tabwriter"
7+
8+
"github.com/ariary/go-utils/pkg/color"
79
)
810

9-
// Banner: Print the banner as it is trendy for this kind of tool. thanks to: https://patorjk.com/software/taag
10-
func Banner() {
11-
banner := `
11+
var nameDraw = color.Teal(`
1212
_/_/
1313
_/_/_/ _/ _/ _/ _/_/_/_/ _/_/_/_/
1414
_/ _/_/_/_/ _/ _/ _/ _/
1515
_/ _/ _/ _/ _/ _/
1616
_/_/_/ _/ _/_/_/ _/_/_/_/ _/_/_/_/
1717
18-
By @ariary (https://github.com/ariary)
19-
`
18+
`)
19+
var author = color.Yellow("By @ariary (" + color.Underlined("https://github.com/ariary") + ")")
2020

21+
// Banner: Print the banner as it is trendy for this kind of tool. thanks to: https://patorjk.com/software/taag
22+
func Banner() {
23+
banner := nameDraw + author
2124
fmt.Println(banner)
2225
fmt.Println()
2326
}
@@ -54,14 +57,14 @@ func PrintConfig(cfg Config) {
5457
PrintLine(cfg, "filters:", allFilters)
5558
}
5659
if cfg.Hide {
57-
fmt.Println("Only displays filter that do not pass the filter")
60+
fmt.Println("Only displays words that do not pass the filter")
5861
}
5962
fmt.Println()
6063
fmt.Println(line)
6164
fmt.Println()
6265
}
6366

64-
// Nice printing of a line containing 2 or more elements
67+
//PrintLine: Nice printing of a line containing 2 or more elements
6568
func PrintLine(cfg Config, value string, element ...string) {
6669
// string builder and tabwriter
6770
var strBuilder strings.Builder
@@ -79,3 +82,20 @@ func PrintLine(cfg Config, value string, element ...string) {
7982
cfg.ResultLogger.Println(strBuilder.String())
8083

8184
}
85+
86+
//PrintFullExecOutput Nice printing of command execution
87+
func PrintFullExecOutput(cfg Config, result ExecResult) {
88+
//TODO
89+
cfg.ResultLogger.Println()
90+
cfg.ResultLogger.Println(color.Bold(color.Cyan(result.Substitute)))
91+
if result.Stdout != "" {
92+
cfg.ResultLogger.Println(color.GreenForeground("STDOUT:"))
93+
cfg.ResultLogger.Println(result.Stdout)
94+
}
95+
if result.Stderr != "" {
96+
cfg.ResultLogger.Println(color.RedForeground("STDERR:"))
97+
cfg.ResultLogger.Println(result.Stderr)
98+
}
99+
100+
cfg.ResultLogger.Println()
101+
}

0 commit comments

Comments
 (0)