RES-84 # Improve Nuclei CLI interface

* fixed issues reported by the linter
dev
forgedhallpass 2021-07-19 21:04:08 +03:00
parent 795978c78f
commit 5d89bb8056
45 changed files with 189 additions and 153 deletions

View File

@ -2,13 +2,14 @@ package main
import (
"fmt"
"os"
"path"
"github.com/projectdiscovery/goflags"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/nuclei/v2/internal/runner"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
"os"
"path"
)
var (

View File

@ -1,6 +1,8 @@
package colorizer
import (
"fmt"
"github.com/logrusorgru/aurora"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
@ -10,7 +12,7 @@ const (
fgOrange uint8 = 208
)
func GetColor(colorizer aurora.Aurora, templateSeverity severity.Severity) string {
func GetColor(colorizer aurora.Aurora, templateSeverity fmt.Stringer) string {
var method func(arg interface{}) aurora.Value
switch templateSeverity {
case severity.Info:
@ -31,8 +33,8 @@ func GetColor(colorizer aurora.Aurora, templateSeverity severity.Severity) strin
return method(templateSeverity.String()).String()
}
func New(aurora aurora.Aurora) func(severity.Severity) string {
func New(colorizer aurora.Aurora) func(severity.Severity) string {
return func(severity severity.Severity) string {
return GetColor(aurora, severity)
return GetColor(colorizer, severity)
}
}

View File

@ -3,9 +3,6 @@ package runner
import (
"bufio"
"fmt"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/parsers"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
"os"
"path"
"strings"
@ -13,13 +10,21 @@ import (
"github.com/logrusorgru/aurora"
"github.com/pkg/errors"
"github.com/remeh/sizedwaitgroup"
"github.com/rs/xid"
"go.uber.org/atomic"
"go.uber.org/ratelimit"
"gopkg.in/yaml.v2"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/hmap/store/hybrid"
"github.com/projectdiscovery/nuclei/v2/internal/colorizer"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/catalog"
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/config"
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/loader"
"github.com/projectdiscovery/nuclei/v2/pkg/output"
"github.com/projectdiscovery/nuclei/v2/pkg/parsers"
"github.com/projectdiscovery/nuclei/v2/pkg/progress"
"github.com/projectdiscovery/nuclei/v2/pkg/projectfile"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
@ -32,11 +37,7 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/exporters/sarif"
"github.com/projectdiscovery/nuclei/v2/pkg/templates"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
"github.com/remeh/sizedwaitgroup"
"github.com/rs/xid"
"go.uber.org/atomic"
"go.uber.org/ratelimit"
"gopkg.in/yaml.v2"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
)
// Runner is a client for running the enumeration process.

View File

@ -3,16 +3,17 @@ package runner
import (
"bytes"
"fmt"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"io/ioutil"
"os"
"strings"
"github.com/karrick/godirwalk"
"gopkg.in/yaml.v2"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/templates"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
"gopkg.in/yaml.v2"
)
// parseTemplateFile returns the parsed template file
@ -36,13 +37,13 @@ func (r *Runner) parseTemplateFile(file string) (*templates.Template, error) {
return template, nil
}
func (r *Runner) templateLogMsg(id string, name string, author string, severity severity.Severity) string {
func (r *Runner) templateLogMsg(id, name, author string, templateSeverity severity.Severity) string {
// Display the message for the template
return fmt.Sprintf("[%s] %s (%s) [%s]",
r.colorizer.BrightBlue(id).String(),
r.colorizer.Bold(name).String(),
r.colorizer.BrightYellow(appendAtSignToAuthors(author)).String(),
r.addColor(severity))
r.addColor(templateSeverity))
}
// appendAtSignToAuthors appends @ before each author and returns final string

View File

@ -1,7 +1,6 @@
package severity
import (
"errors"
"fmt"
"strings"
@ -14,6 +13,7 @@ func (severities Severities) String() string {
return strings.Join(severities.ToStringArray(), ", ")
}
//nolint:indent-error-flow,revive //reducing the scope of the variables
func (severities *Severities) Set(value string) error {
if inputSeverities, err := goflags.ToStringSlice(value); err != nil {
return err
@ -30,8 +30,9 @@ func (severities *Severities) Set(value string) error {
func setSeverity(severities *Severities, value string) error {
computedSeverity, err := toSeverity(value)
if err != nil {
return errors.New(fmt.Sprintf("'%s' is not a valid severity!", value))
return fmt.Errorf("'%s' is not a valid severity", value)
}
// TODO change the Severities type to map[Severity]interface{}, where the values are struct{}{}, to "simulates" a "set" data structure
*severities = append(*severities, computedSeverity)
return nil

View File

@ -2,8 +2,9 @@ package severity
import (
"encoding/json"
"github.com/pkg/errors"
"strings"
"github.com/pkg/errors"
)
type Severity int
@ -47,14 +48,12 @@ func normalizeValue(value string) string {
return strings.TrimSpace(strings.ToLower(value))
}
func (severity Severity) normalize() string {
return normalizeValue(severity.String())
}
func (severity Severity) String() string {
return severityMappings[severity]
}
//nolint:exported,revive //prefer to be explicit about the name, and make it refactor-safe
//goland:noinspection GoNameStartsWithPackageName
type SeverityHolder struct {
Severity Severity
}
@ -62,17 +61,17 @@ type SeverityHolder struct {
func (severityHolder SeverityHolder) MarshalYAML() (interface{}, error) {
if value, found := severityMappings[severityHolder.Severity]; found {
return &struct{ Severity string }{value}, nil // TODO see if the new struct can be dynamically created using reflection to make it refactor safe
} else {
panic("Invalid field to marshall")
}
panic("Invalid field to marshall")
}
func (severityHolder SeverityHolder) MarshalJSON() ([]byte, error) {
if value, found := severityMappings[severityHolder.Severity]; found {
return json.Marshal(&struct{ Severity string }{value}) // TODO see if the new struct can be dynamically created using reflection to make it refactor safe
} else {
panic("Invalid field to marshall")
}
panic("Invalid field to marshall")
}
func (severityHolder *SeverityHolder) UnmarshalYAML(unmarshal func(interface{}) error) error {
@ -96,20 +95,21 @@ func (severityHolder *SeverityHolder) UnmarshalJSON(data []byte) error {
return err
}
return mapToSeverity(objMap, severityHolder)
return severityHolder.mapToSeverity(objMap)
}
func mapToSeverity(objMap map[string]string, severity *SeverityHolder) error {
func (severityHolder *SeverityHolder) mapToSeverity(objMap map[string]string) error {
if len(objMap) != 1 {
return errors.New("There can only be one severity defined")
}
stringSeverity := getFirstValue(objMap)
if readableSeverity, err := toSeverity(stringSeverity); err == nil {
severity = &SeverityHolder{readableSeverity}
return nil
} else {
readableSeverity, err := toSeverity(stringSeverity)
if err != nil {
return err
}
*severityHolder = SeverityHolder{readableSeverity}
return nil
}
func getFirstValue(stringMap map[string]string) string {

View File

@ -3,26 +3,28 @@ package severity
import (
"encoding/json"
"fmt"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
"testing"
"gopkg.in/yaml.v2"
"github.com/stretchr/testify/assert"
)
func TestJsonUnmarshal(t *testing.T) {
testUnmarshal(t, json.Unmarshal, createJson)
testUnmarshal(t, json.Unmarshal, createJSON)
}
// TODO
//func TestYamlUnmarshal(t *testing.T) {
// testUnmarshal(t, yaml.Unmarshal, createYaml)
//}
// func TestYamlUnmarshal(t *testing.T) {
// testUnmarshal(t, yaml.Unmarshal, createYAML)
// }
func TestJsonUnmarshalFail(t *testing.T) {
testUnmarshalFail(t, json.Unmarshal, createJson)
testUnmarshalFail(t, json.Unmarshal, createJSON)
}
func TestYamlUnmarshalFail(t *testing.T) {
testUnmarshalFail(t, yaml.Unmarshal, createYaml)
testUnmarshalFail(t, yaml.Unmarshal, createYAML)
}
func TestJsonMarshalFails(t *testing.T) {
@ -34,11 +36,11 @@ func TestYamlMarshalFails(t *testing.T) {
}
func TestJsonMarshalSucceed(t *testing.T) {
testMarshal(t, json.Marshal, createJson)
testMarshal(t, json.Marshal, createJSON)
}
func TestYamlMarshal(t *testing.T) {
testMarshal(t, yaml.Marshal, createYaml)
testMarshal(t, yaml.Marshal, createYAML)
}
func testUnmarshal(t *testing.T, unmarshaller func(data []byte, v interface{}) error, payloadCreator func(value string) string) {
@ -50,7 +52,7 @@ func testUnmarshal(t *testing.T, unmarshaller func(data []byte, v interface{}) e
payloadCreator(" INFO "),
}
for _, payload := range payloads {
for _, payload := range payloads { // nolint:scopelint // false-positive
t.Run(payload, func(t *testing.T) {
result := unmarshal(payload, unmarshaller)
assert.Equal(t, result.Severity, Info)
@ -66,12 +68,12 @@ func testMarshal(t *testing.T, marshaller func(v interface{}) ([]byte, error), p
}
}
func testUnmarshalFail(t *testing.T, unmarshaller func(data []byte, v interface{}) error, payloadCreator func(value string) string) bool {
return assert.Panics(t, func() { unmarshal(payloadCreator("invalid"), unmarshaller) })
func testUnmarshalFail(t *testing.T, unmarshaller func(data []byte, v interface{}) error, payloadCreator func(value string) string) {
assert.Panics(t, func() { unmarshal(payloadCreator("invalid"), unmarshaller) })
}
func testMarshallerFails(t *testing.T, marshaller func(v interface{}) ([]byte, error)) {
assert.Panics(t, func() { marshaller(&SeverityHolder{Severity: 13}) })
assert.Panics(t, func() { _, _ = marshaller(&SeverityHolder{Severity: 13}) })
}
func unmarshal(value string, unmarshaller func(data []byte, v interface{}) error) SeverityHolder {
@ -83,10 +85,10 @@ func unmarshal(value string, unmarshaller func(data []byte, v interface{}) error
return severityStruct
}
func createJson(severityString string) string {
func createJSON(severityString string) string {
return fmt.Sprintf(`{"Severity":"%s"}`, severityString)
}
func createYaml(value string) string {
func createYAML(value string) string {
return "severity: " + value + "\n"
}

View File

@ -28,7 +28,7 @@ type Config struct {
const nucleiConfigFilename = ".templates-config.json"
// Version is the current version of nuclei
const Version = `2.4.0`
const Version = `2.4.x`
func getConfigDetails() (string, error) {
homeDir, err := os.UserHomeDir()

View File

@ -2,9 +2,10 @@ package filter
import (
"errors"
"strings"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
"strings"
)
// TagFilter is used to filter nuclei templates for tag based execution
@ -27,7 +28,7 @@ var ErrExcluded = errors.New("the template was excluded")
// matchAllows section.
//
// It returns true if the tag is specified, or false.
func (tagFilter *TagFilter) Match(templateTags, templateAuthors []string, severity severity.Severity) (bool, error) {
func (tagFilter *TagFilter) Match(templateTags, templateAuthors []string, templateSeverity severity.Severity) (bool, error) {
for _, templateTag := range templateTags {
_, blocked := tagFilter.block[templateTag]
_, allowed := tagFilter.matchAllows[templateTag]
@ -46,7 +47,7 @@ func (tagFilter *TagFilter) Match(templateTags, templateAuthors []string, severi
}
if utils.IsNotEmpty(tagFilter.severities) {
if _, ok := tagFilter.severities[severity]; !ok {
if _, ok := tagFilter.severities[templateSeverity]; !ok {
return false, nil
}
}
@ -57,16 +58,18 @@ func (tagFilter *TagFilter) Match(templateTags, templateAuthors []string, severi
func isAuthorMatch(templateAuthors []string, tagFilter *TagFilter) bool {
if utils.IsEmpty(tagFilter.authors) {
return true
} else {
for _, templateAuthor := range templateAuthors {
if _, ok := tagFilter.authors[templateAuthor]; ok {
return true
}
}
for _, templateAuthor := range templateAuthors {
if _, ok := tagFilter.authors[templateAuthor]; ok {
return true
}
}
return false
}
//nolint:indent-error-flow,revive // keeping conditions together
func isTagMatch(templateTags []string, tagFilter *TagFilter) bool {
if utils.IsEmpty(tagFilter.allowedTags) {
return true
@ -80,10 +83,8 @@ func isTagMatch(templateTags []string, tagFilter *TagFilter) bool {
return false
}
// MatchWithWorkflowTags takes an addition list of allowed tags
// and returns true if the match was successful.
// MatchWithWorkflowTags takes an addition list of allowed tags and returns true if the match was successful.
func (tagFilter *TagFilter) MatchWithWorkflowTags(templateTags, templateAuthors []string, templateSeverity severity.Severity, workflowTags []string) (bool, error) {
workflowAllowedTagMap := make(map[string]struct{})
for _, workflowTag := range workflowTags {
if _, ok := workflowAllowedTagMap[workflowTag]; !ok {
@ -114,8 +115,8 @@ func (tagFilter *TagFilter) MatchWithWorkflowTags(templateTags, templateAuthors
return false, nil
}
}
}
if utils.IsNotEmpty(tagFilter.severities) {
if _, ok := tagFilter.severities[templateSeverity]; !ok {
return false, nil

View File

@ -1,10 +1,11 @@
package filter
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"testing"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
)
func TestTagBasedFilter(t *testing.T) {

View File

@ -1,17 +1,16 @@
package loader
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
"strings"
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/catalog"
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/loader/filter"
"github.com/projectdiscovery/nuclei/v2/pkg/parsers"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
"github.com/projectdiscovery/nuclei/v2/pkg/templates"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
)
// Config contains the configuration options for the loader

View File

@ -1,9 +1,10 @@
package model
import (
"strings"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
"strings"
)
type Info struct {

View File

@ -2,6 +2,7 @@ package operators
import (
"github.com/pkg/errors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
)

View File

@ -2,6 +2,7 @@ package output
import (
"bytes"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
)

View File

@ -1,18 +1,20 @@
package output
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"os"
"regexp"
"sync"
"time"
"github.com/pkg/errors"
jsoniter "github.com/json-iterator/go"
"github.com/logrusorgru/aurora"
"github.com/pkg/errors"
"github.com/projectdiscovery/interactsh/pkg/server"
"github.com/projectdiscovery/nuclei/v2/internal/colorizer"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
)

View File

@ -2,21 +2,21 @@ package parsers
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/loader/filter"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/templates"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
)
const mandatoryFieldMissingTemplate = "mandatory '%s' field is missing"
// Load loads a template by parsing metadata and running
// all tag and path based filters on the template.
// Load loads a template by parsing metadata and running all tag and path based filters on the template.
func Load(templatePath string, isWorkflow bool, workflowTags []string, tagFilter *filter.TagFilter) (bool, error) {
template, templateParseError := parseTemplate(templatePath)
if templateParseError != nil {
@ -24,24 +24,24 @@ func Load(templatePath string, isWorkflow bool, workflowTags []string, tagFilter
}
templateInfo := template.Info
if validationError := validateMandatoryInfoFields(templateInfo); validationError != nil {
if validationError := validateMandatoryInfoFields(&templateInfo); validationError != nil {
return false, validationError
}
if utils.IsNotEmpty(template.Workflows) {
if isWorkflow {
return true, nil // if a workflow is declared and this template is a workflow, then load
} else {
} else { //nolint:indent-error-flow,revive // preferred: readability and extensibility
return false, nil // if a workflow is declared and this template is not a workflow then do not load
}
} else if isWorkflow {
return false, nil // if no workflows are declared and this template is a workflow then do not load
} else { // if workflows are not declared and the template is not a workflow then parse it
return isInfoMetadataMatch(tagFilter, templateInfo, workflowTags)
return isInfoMetadataMatch(tagFilter, &templateInfo, workflowTags)
}
}
func isInfoMetadataMatch(tagFilter *filter.TagFilter, templateInfo model.Info, workflowTags []string) (bool, error) {
func isInfoMetadataMatch(tagFilter *filter.TagFilter, templateInfo *model.Info, workflowTags []string) (bool, error) {
templateTags := templateInfo.Tags.ToSlice()
templateAuthors := templateInfo.Authors.ToSlice()
templateSeverity := templateInfo.SeverityHolder.Severity
@ -61,18 +61,18 @@ func isInfoMetadataMatch(tagFilter *filter.TagFilter, templateInfo model.Info, w
return match, nil
}
func validateMandatoryInfoFields(info model.Info) error {
if utils.IsEmpty(info) {
return errors.New(fmt.Sprintf(mandatoryFieldMissingTemplate, "info"))
func validateMandatoryInfoFields(info *model.Info) error {
if utils.IsEmpty(&info) {
return fmt.Errorf(mandatoryFieldMissingTemplate, "info")
}
if utils.IsEmpty(info.Name) {
return errors.New(fmt.Sprintf(mandatoryFieldMissingTemplate, "name"))
if utils.IsEmpty(&info.Name) {
return fmt.Errorf(mandatoryFieldMissingTemplate, "name")
}
authors := info.Authors.ToSlice()
if utils.IsEmpty(authors) {
return errors.New(fmt.Sprintf(mandatoryFieldMissingTemplate, "author"))
if utils.IsEmpty(&authors) {
return fmt.Errorf(mandatoryFieldMissingTemplate, "author")
}
return nil
}

View File

@ -1,12 +1,13 @@
package dns
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"testing"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
)
func TestDNSCompileMake(t *testing.T) {

View File

@ -2,10 +2,11 @@ package dns
import (
"bytes"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"time"
"github.com/miekg/dns"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
"github.com/projectdiscovery/nuclei/v2/pkg/output"

View File

@ -1,19 +1,20 @@
package dns
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"net"
"strconv"
"testing"
"github.com/miekg/dns"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
"github.com/projectdiscovery/nuclei/v2/pkg/output"
"github.com/stretchr/testify/require"
)
func TestResponseToDSLMap(t *testing.T) {

View File

@ -1,16 +1,17 @@
package dns
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"testing"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
"github.com/projectdiscovery/nuclei/v2/pkg/output"
"github.com/stretchr/testify/require"
)
func TestDNSExecuteWithResults(t *testing.T) {

View File

@ -1,12 +1,13 @@
package file
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"testing"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
)
func TestFileCompile(t *testing.T) {

View File

@ -1,15 +1,16 @@
package file
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"io/ioutil"
"os"
"path"
"testing"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
)
func TestFindInputPaths(t *testing.T) {

View File

@ -2,10 +2,10 @@ package file
import (
"bufio"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"strings"
"time"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
"github.com/projectdiscovery/nuclei/v2/pkg/output"

View File

@ -1,16 +1,17 @@
package file
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"testing"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
"github.com/projectdiscovery/nuclei/v2/pkg/output"
"github.com/stretchr/testify/require"
)
func TestResponseToDSLMap(t *testing.T) {

View File

@ -1,14 +1,14 @@
package file
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"io/ioutil"
"os"
"path"
"testing"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"

View File

@ -1,9 +1,9 @@
package headless
import (
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"time"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
"github.com/projectdiscovery/nuclei/v2/pkg/output"

View File

@ -1,12 +1,12 @@
package http
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"net/url"
"testing"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/stretchr/testify/require"
)

View File

@ -1,12 +1,13 @@
package http
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"testing"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
)
func TestHTTPCompile(t *testing.T) {

View File

@ -1,11 +1,11 @@
package http
import (
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"net/http"
"strings"
"time"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
"github.com/projectdiscovery/nuclei/v2/pkg/output"

View File

@ -1,18 +1,19 @@
package http
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"net/http"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
"github.com/projectdiscovery/nuclei/v2/pkg/output"
"github.com/stretchr/testify/require"
)
func TestResponseToDSLMap(t *testing.T) {

View File

@ -1,12 +1,13 @@
package network
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"testing"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
)
func TestNetworkCompileMake(t *testing.T) {

View File

@ -1,9 +1,9 @@
package network
import (
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"time"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
"github.com/projectdiscovery/nuclei/v2/pkg/output"

View File

@ -1,16 +1,17 @@
package network
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"testing"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
"github.com/projectdiscovery/nuclei/v2/pkg/output"
"github.com/stretchr/testify/require"
)
func TestResponseToDSLMap(t *testing.T) {

View File

@ -3,19 +3,20 @@ package network
import (
"encoding/hex"
"fmt"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
"github.com/projectdiscovery/nuclei/v2/pkg/output"
"github.com/stretchr/testify/require"
)
func TestNetworkExecuteWithResults(t *testing.T) {

View File

@ -1,16 +1,17 @@
package offlinehttp
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"io/ioutil"
"os"
"path"
"testing"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
)
func TestFindResponses(t *testing.T) {

View File

@ -1,11 +1,11 @@
package offlinehttp
import (
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"net/http"
"strings"
"time"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
"github.com/projectdiscovery/nuclei/v2/pkg/output"

View File

@ -1,18 +1,19 @@
package offlinehttp
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"net/http"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/internal/testutils"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/extractors"
"github.com/projectdiscovery/nuclei/v2/pkg/operators/matchers"
"github.com/projectdiscovery/nuclei/v2/pkg/output"
"github.com/stretchr/testify/require"
)
func TestResponseToDSLMap(t *testing.T) {

View File

@ -3,8 +3,6 @@ package sarif
import (
"crypto/sha1"
"encoding/hex"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
"os"
"path"
"strings"
@ -12,8 +10,11 @@ import (
"github.com/owenrumney/go-sarif/sarif"
"github.com/pkg/errors"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/output"
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/format"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
)
// Exporter is an exporter for nuclei sarif output format.

View File

@ -3,12 +3,12 @@ package format
import (
"bytes"
"fmt"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
"reflect"
"strings"
"github.com/projectdiscovery/nuclei/v2/pkg/output"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
)
// Summary returns a formatted built one line summary of the event

View File

@ -1,12 +1,13 @@
package reporting
import (
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
"strings"
"github.com/pkg/errors"
"go.uber.org/multierr"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"github.com/projectdiscovery/nuclei/v2/pkg/model"
"github.com/projectdiscovery/nuclei/v2/pkg/output"
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/dedupe"
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/exporters/disk"
@ -14,7 +15,7 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/trackers/github"
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/trackers/gitlab"
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/trackers/jira"
"go.uber.org/multierr"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
)
// Options is a configuration file for nuclei reporting module
@ -58,10 +59,10 @@ func isTagMatch(event *output.ResultEvent, filter *Filter) bool {
}
func isSeverityMatch(event *output.ResultEvent, filter *Filter) bool {
severity := event.Info.SeverityHolder.Severity // TODO review
resultEventSeverity := event.Info.SeverityHolder.Severity // TODO review
if utils.IsNotEmpty(filter.Severities) {
for _, current := range filter.Severities {
if current == severity {
if current == resultEventSeverity {
return true
}
}

View File

@ -3,15 +3,16 @@ package jira
import (
"bytes"
"fmt"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
"io/ioutil"
"reflect"
"strings"
jira "github.com/andygrunwald/go-jira"
"github.com/andygrunwald/go-jira"
"github.com/projectdiscovery/nuclei/v2/pkg/output"
"github.com/projectdiscovery/nuclei/v2/pkg/reporting/format"
"github.com/projectdiscovery/nuclei/v2/pkg/types"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
)
// Integration is a client for a issue tracker integration

View File

@ -3,17 +3,18 @@ package templates
import (
"bytes"
"fmt"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
"io/ioutil"
"os"
"strings"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
"github.com/projectdiscovery/nuclei/v2/pkg/operators"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/executer"
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/offlinehttp"
"gopkg.in/yaml.v2"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
)
// Parse parses a yaml request template file

View File

@ -4,9 +4,10 @@ package types
import (
"fmt"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
"strconv"
"strings"
"github.com/projectdiscovery/nuclei/v2/internal/severity"
)
// ToString converts an interface to string in a quick way

View File

@ -13,6 +13,7 @@ func isEmpty(value interface{}) bool {
reflectValue := reflect.ValueOf(value)
actualValueInterface := reflectValue.Interface()
// nolint:exhaustive //default branch handles other cases
switch reflect.TypeOf(value).Kind() {
case reflect.String:
reflectedValue := actualValueInterface.(string)

View File

@ -2,10 +2,12 @@ package utils
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
"github.com/stretchr/testify/assert"
)
//nolint:scopelint //false-positive
func TestIsEmpty(t *testing.T) {
testCases := [...][2]interface{}{
{"", true},