Skip to content

Commit

Permalink
Revert "enable asnmap unit tests (#3880)"
Browse files Browse the repository at this point in the history
This reverts commit 878580d.
  • Loading branch information
tarunKoyalwar committed Jun 27, 2023
1 parent 878580d commit b5983ca
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 181 deletions.
40 changes: 0 additions & 40 deletions integration_tests/http/matcher-status-per-request.yaml

This file was deleted.

40 changes: 0 additions & 40 deletions integration_tests/http/matcher-status.yaml

This file was deleted.

38 changes: 0 additions & 38 deletions v2/cmd/integration-test/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ var httpTestcases = map[string]testutils.TestCase{
"http/cl-body-with-header.yaml": &httpCLBodyWithHeader{},
"http/save-extractor-values-to-file.yaml": &httpSaveExtractorValuesToFile{},
"http/cli-with-constants.yaml": &ConstantWithCliVar{},
"http/matcher-status.yaml": &matcherStatusTest{},
"http/matcher-status-per-request.yaml": &matcherStatusPerRequestTest{},
"http/disable-path-automerge.yaml": &httpDisablePathAutomerge{},
}

Expand Down Expand Up @@ -1427,42 +1425,6 @@ func (h *ConstantWithCliVar) Execute(filePath string) error {
return expectResultsCount(got, 1)
}

type matcherStatusTest struct{}

// Execute executes a test case and returns an error if occurred
func (h *matcherStatusTest) Execute(filePath string) error {
router := httprouter.New()
router.GET("/200", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
w.WriteHeader(http.StatusOK)
})
ts := httptest.NewServer(router)
defer ts.Close()

results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug, "-ms")
if err != nil {
return err
}
return expectResultsCount(results, 1)
}

type matcherStatusPerRequestTest struct{}

// Execute executes a test case and returns an error if occurred
func (h *matcherStatusPerRequestTest) Execute(filePath string) error {
router := httprouter.New()
router.GET("/200", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
w.WriteHeader(http.StatusOK)
})
ts := httptest.NewServer(router)
defer ts.Close()

results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug, "-msr")
if err != nil {
return err
}
return expectResultsCount(results, 5)
}

// disable path automerge in raw request
type httpDisablePathAutomerge struct{}

Expand Down
1 change: 0 additions & 1 deletion v2/cmd/nuclei/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ on extensive configurability, massive extensibility and ease of use.`)
flagSet.BoolVarP(&options.Timestamp, "timestamp", "ts", false, "enables printing timestamp in cli output"),
flagSet.StringVarP(&options.ReportingDB, "report-db", "rdb", "", "nuclei reporting database (always use this to persist report data)"),
flagSet.BoolVarP(&options.MatcherStatus, "matcher-status", "ms", false, "display match failure status"),
flagSet.BoolVarP(&options.MatchStatusPerRequest, "matcher-status-request", "msr", false, "display match failure status per request"),
flagSet.StringVarP(&options.MarkdownExportDirectory, "markdown-export", "me", "", "directory to export results in markdown format"),
flagSet.StringVarP(&options.SarifExport, "sarif-export", "se", "", "file to export results in SARIF format"),
flagSet.StringVarP(&options.JSONExport, "json-export", "je", "", "file to export results in JSON format"),
Expand Down
17 changes: 9 additions & 8 deletions v2/pkg/core/inputs/hybrid/hmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,15 @@ func Test_expandASNInputValue(t *testing.T) {
asn string
expectedOutputFile string
}{
{
asn: "AS14421",
expectedOutputFile: "tests/AS14421.txt",
},
{
asn: "AS134029",
expectedOutputFile: "tests/AS134029.txt",
},
// {
// asn: "AS14421",
// expectedOutputFile: "tests/AS14421.txt",
// },
// skipping since there is a issue with ASN lookup for AS134029
// {
// asn: "AS134029",
// expectedOutputFile: "tests/AS134029.txt",
// },
}
for _, tt := range tests {
hm, err := hybrid.New(hybrid.DefaultDiskOptions)
Expand Down
53 changes: 26 additions & 27 deletions v2/pkg/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ type Writer interface {

// StandardWriter is a writer writing output to file and screen for results.
type StandardWriter struct {
json bool
jsonReqResp bool
timestamp bool
noMetadata bool
matcherStatus bool
mutex *sync.Mutex
aurora aurora.Aurora
outputFile io.WriteCloser
traceFile io.WriteCloser
errorFile io.WriteCloser
severityColors func(severity.Severity) string
storeResponse bool
storeResponseDir string
json bool
jsonReqResp bool
timestamp bool
noMetadata bool
matcherStatus bool
mutex *sync.Mutex
aurora aurora.Aurora
outputFile io.WriteCloser
traceFile io.WriteCloser
errorFile io.WriteCloser
severityColors func(severity.Severity) string
storeResponse bool
storeResponseDir string
}

var decolorizerRegex = regexp.MustCompile(`\x1B\[[0-9;]*[a-zA-Z]`)
Expand Down Expand Up @@ -187,21 +187,20 @@ func NewStandardWriter(options *types.Options) (*StandardWriter, error) {
gologger.Fatal().Msgf("Could not create output directory '%s': %s\n", options.StoreResponseDir, err)
}
}

writer := &StandardWriter{
json: options.JSONL,
jsonReqResp: options.JSONRequests,
noMetadata: options.NoMeta,
matcherStatus: options.MatcherStatus || options.MatchStatusPerRequest,
timestamp: options.Timestamp,
aurora: auroraColorizer,
mutex: &sync.Mutex{},
outputFile: outputFile,
traceFile: traceOutput,
errorFile: errorOutput,
severityColors: colorizer.New(auroraColorizer),
storeResponse: options.StoreResponse,
storeResponseDir: options.StoreResponseDir,
json: options.JSONL,
jsonReqResp: options.JSONRequests,
noMetadata: options.NoMeta,
matcherStatus: options.MatcherStatus,
timestamp: options.Timestamp,
aurora: auroraColorizer,
mutex: &sync.Mutex{},
outputFile: outputFile,
traceFile: traceOutput,
errorFile: errorOutput,
severityColors: colorizer.New(auroraColorizer),
storeResponse: options.StoreResponse,
storeResponseDir: options.StoreResponseDir,
}
return writer, nil
}
Expand Down
31 changes: 7 additions & 24 deletions v2/pkg/protocols/common/executer/executer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,6 @@ func (e *Executer) Execute(input *contextargs.Context) (bool, error) {
})
}
previous := make(map[string]interface{})

var lastMatcherEvent *output.InternalWrappedEvent
writeFailureCallback := func(event *output.InternalWrappedEvent, matcherStatusPerReq, matcherStatus bool) {
if matcherStatusPerReq || matcherStatus {
results.CompareAndSwap(false, true)
}
if matcherStatus {
lastMatcherEvent = event
return
}
if matcherStatusPerReq {
if err := e.options.Output.WriteFailure(event.InternalEvent); err != nil {
gologger.Warning().Msgf("Could not write failure event to output: %s\n", err)
}
}
}

for _, req := range e.requests {
inputItem := input.Clone()
if e.options.InputHelper != nil && input.MetaInput.Input != "" {
Expand All @@ -110,13 +93,17 @@ func (e *Executer) Execute(input *contextargs.Context) (bool, error) {
// If no results were found, and also interactsh is not being used
// in that case we can skip it, otherwise we've to show failure in
// case of matcher-status flag.
if !event.HasOperatorResult() && !event.UsesInteractsh && e.options.Options.MatchStatusPerRequest {
writeFailureCallback(event, e.options.Options.MatchStatusPerRequest, e.options.Options.MatcherStatus)
if !event.HasOperatorResult() && !event.UsesInteractsh {
if err := e.options.Output.WriteFailure(event.InternalEvent); err != nil {
gologger.Warning().Msgf("Could not write failure event to output: %s\n", err)
}
} else {
if writer.WriteResult(event, e.options.Output, e.options.Progress, e.options.IssuesClient) {
results.CompareAndSwap(false, true)
} else {
writeFailureCallback(event, e.options.Options.MatchStatusPerRequest, e.options.Options.MatcherStatus)
if err := e.options.Output.WriteFailure(event.InternalEvent); err != nil {
gologger.Warning().Msgf("Could not write failure event to output: %s\n", err)
}
}
}
})
Expand All @@ -131,10 +118,6 @@ func (e *Executer) Execute(input *contextargs.Context) (bool, error) {
break
}
}

if lastMatcherEvent != nil {
writeFailureCallback(lastMatcherEvent, true, false)
}
return results.Load(), nil
}

Expand Down
2 changes: 1 addition & 1 deletion v2/pkg/testutils/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func RunNucleiBareArgsAndGetResults(debug bool, extra ...string) ([]string, erro
if debug {
fmt.Println(string(data))
}
if len(data) < 1 && err != nil {
if err != nil {
return nil, fmt.Errorf("%v: %v", err.Error(), string(data))
}
var parts []string
Expand Down
2 changes: 0 additions & 2 deletions v2/pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,6 @@ type Options struct {
EnvironmentVariables bool
// MatcherStatus displays optional status for the failed matches as well
MatcherStatus bool
// MatchStatusPerRequest displays optional status for the failed matches per request
MatchStatusPerRequest bool
// ClientCertFile client certificate file (PEM-encoded) used for authenticating against scanned hosts
ClientCertFile string
// ClientKeyFile client key file (PEM-encoded) used for authenticating against scanned hosts
Expand Down

0 comments on commit b5983ca

Please sign in to comment.