Skip to content

Commit dc8ad17

Browse files
committed
introduce dynamic filtering
1 parent 809b888 commit dc8ad17

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

runner/options.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
fileutil "github.com/projectdiscovery/utils/file"
3232
sliceutil "github.com/projectdiscovery/utils/slice"
3333
stringsutil "github.com/projectdiscovery/utils/strings"
34+
"github.com/projectdiscovery/utils/structs"
3435
updateutils "github.com/projectdiscovery/utils/update"
3536
wappalyzer "github.com/projectdiscovery/wappalyzergo"
3637
)
@@ -310,6 +311,8 @@ type Options struct {
310311
OutputFilterCondition string
311312
OutputMatchCondition string
312313
StripFilter string
314+
ListOutputFields bool
315+
ExcludeОutputFields goflags.StringSlice
313316
//The OnResult callback function is invoked for each result. It is important to check for errors in the result before using Result.Err.
314317
OnResult OnResultCallback
315318
DisableUpdateCheck bool
@@ -432,6 +435,8 @@ func ParseOptions() *Options {
432435
flagSet.StringVarP(&options.OutputFilterResponseTime, "filter-response-time", "frt", "", "filter response with specified response time in seconds (-frt '> 1')"),
433436
flagSet.StringVarP(&options.OutputFilterCondition, "filter-condition", "fdc", "", "filter response with dsl expression condition"),
434437
flagSet.DynamicVar(&options.StripFilter, "strip", "html", "strips all tags in response. supported formats: html,xml"),
438+
flagSet.BoolVarP(&options.ListOutputFields, "list-output-fields", "lof", false, "list of fields to output (comma separated)"),
439+
flagSet.StringSliceVarP(&options.ExcludeОutputFields, "exclude-output-fields", "eof", nil, "exclude output fields output based on a condition", goflags.NormalizedOriginalStringSliceOptions),
435440
)
436441

437442
flagSet.CreateGroup("rate-limit", "Rate-Limit",
@@ -544,6 +549,17 @@ func ParseOptions() *Options {
544549

545550
_ = flagSet.Parse()
546551

552+
if options.ListOutputFields {
553+
fields, err := structs.GetStructFields(Result{})
554+
if err != nil {
555+
gologger.Fatal().Msgf("Could not get struct fields: %s\n", err)
556+
}
557+
for _, field := range fields {
558+
fmt.Println(field)
559+
}
560+
os.Exit(0)
561+
}
562+
547563
if options.OutputAll && options.Output == "" {
548564
gologger.Fatal().Msg("Please specify an output file using -o/-output when using -oa/-output-all")
549565
}

runner/runner.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
"github.com/projectdiscovery/networkpolicy"
4242
errorutil "github.com/projectdiscovery/utils/errors"
4343
osutil "github.com/projectdiscovery/utils/os"
44+
"github.com/projectdiscovery/utils/structs"
4445

4546
"github.com/Mzack9999/gcache"
4647
"github.com/logrusorgru/aurora"
@@ -1153,6 +1154,12 @@ func (r *Runner) RunEnumeration() {
11531154
plainFile.WriteString(resp.str + "\n")
11541155
}
11551156

1157+
if len(r.options.ExcludeОutputFields) > 0 {
1158+
if filteredData, err := structs.FilterStruct(resp, nil, r.options.ExcludeОutputFields); err == nil {
1159+
resp = filteredData
1160+
}
1161+
}
1162+
11561163
// call the callback function if any
11571164
// be careful and check for result.Err
11581165
if r.options.OnResult != nil {

0 commit comments

Comments
 (0)