mirror of https://github.com/daffainfo/nuclei.git
Added default config generation for reporting options (#2605)
parent
06dcee0704
commit
fc27fc94a5
|
@ -34,5 +34,5 @@ func (h *customConfigDirTest) Execute(filePath string) error {
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
fileNames = append(fileNames, file.Name())
|
fileNames = append(fileNames, file.Name())
|
||||||
}
|
}
|
||||||
return expectResultsCount(fileNames, 3)
|
return expectResultsCount(fileNames, 4)
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,6 +122,9 @@ func New(options *types.Options) (*Runner, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := reporting.CreateConfigIfNotExists(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
reportingOptions, err := createReportingOptions(options)
|
reportingOptions, err := createReportingOptions(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -33,7 +33,8 @@ type Options struct {
|
||||||
Password string `yaml:"password" validate:"required"`
|
Password string `yaml:"password" validate:"required"`
|
||||||
// IndexName is the name of the elasticsearch index
|
// IndexName is the name of the elasticsearch index
|
||||||
IndexName string `yaml:"index-name" validate:"required"`
|
IndexName string `yaml:"index-name" validate:"required"`
|
||||||
HttpClient *retryablehttp.Client
|
|
||||||
|
HttpClient *retryablehttp.Client `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type data struct {
|
type data struct {
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
package reporting
|
package reporting
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"go.uber.org/multierr"
|
"go.uber.org/multierr"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
|
||||||
|
"github.com/projectdiscovery/fileutil"
|
||||||
|
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/config"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/model/types/severity"
|
"github.com/projectdiscovery/nuclei/v2/pkg/model/types/severity"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/model/types/stringslice"
|
"github.com/projectdiscovery/nuclei/v2/pkg/model/types/stringslice"
|
||||||
"github.com/projectdiscovery/nuclei/v2/pkg/output"
|
"github.com/projectdiscovery/nuclei/v2/pkg/output"
|
||||||
|
@ -37,7 +42,8 @@ type Options struct {
|
||||||
SarifExporter *sarif.Options `yaml:"sarif"`
|
SarifExporter *sarif.Options `yaml:"sarif"`
|
||||||
// ElasticsearchExporter contains configuration options for Elasticsearch Exporter Module
|
// ElasticsearchExporter contains configuration options for Elasticsearch Exporter Module
|
||||||
ElasticsearchExporter *es.Options `yaml:"elasticsearch"`
|
ElasticsearchExporter *es.Options `yaml:"elasticsearch"`
|
||||||
HttpClient *retryablehttp.Client
|
|
||||||
|
HttpClient *retryablehttp.Client `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter filters the received event and decides whether to perform
|
// Filter filters the received event and decides whether to perform
|
||||||
|
@ -114,6 +120,7 @@ type Client struct {
|
||||||
// New creates a new nuclei issue tracker reporting client
|
// New creates a new nuclei issue tracker reporting client
|
||||||
func New(options *Options, db string) (*Client, error) {
|
func New(options *Options, db string) (*Client, error) {
|
||||||
client := &Client{options: options}
|
client := &Client{options: options}
|
||||||
|
|
||||||
if options.GitHub != nil {
|
if options.GitHub != nil {
|
||||||
options.GitHub.HttpClient = options.HttpClient
|
options.GitHub.HttpClient = options.HttpClient
|
||||||
tracker, err := github.New(options.GitHub)
|
tracker, err := github.New(options.GitHub)
|
||||||
|
@ -169,6 +176,39 @@ func New(options *Options, db string) (*Client, error) {
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateConfigIfNotExists creates report-config if it doesn't exists
|
||||||
|
func CreateConfigIfNotExists() error {
|
||||||
|
config, err := config.GetConfigDir()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "could not get config directory")
|
||||||
|
}
|
||||||
|
reportingConfig := filepath.Join(config, "report-config.yaml")
|
||||||
|
|
||||||
|
if fileutil.FileExists(reportingConfig) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
values := stringslice.StringSlice{Value: []string{}}
|
||||||
|
|
||||||
|
options := &Options{
|
||||||
|
AllowList: &Filter{Tags: values},
|
||||||
|
DenyList: &Filter{Tags: values},
|
||||||
|
GitHub: &github.Options{},
|
||||||
|
GitLab: &gitlab.Options{},
|
||||||
|
Jira: &jira.Options{},
|
||||||
|
MarkdownExporter: &markdown.Options{},
|
||||||
|
SarifExporter: &sarif.Options{},
|
||||||
|
ElasticsearchExporter: &es.Options{},
|
||||||
|
}
|
||||||
|
reportingFile, err := os.Create(reportingConfig)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "could not create config file")
|
||||||
|
}
|
||||||
|
defer reportingFile.Close()
|
||||||
|
|
||||||
|
err = yaml.NewEncoder(reportingFile).Encode(options)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// RegisterTracker registers a custom tracker to the reporter
|
// RegisterTracker registers a custom tracker to the reporter
|
||||||
func (c *Client) RegisterTracker(tracker Tracker) {
|
func (c *Client) RegisterTracker(tracker Tracker) {
|
||||||
c.trackers = append(c.trackers, tracker)
|
c.trackers = append(c.trackers, tracker)
|
||||||
|
|
|
@ -41,7 +41,8 @@ type Options struct {
|
||||||
// SeverityAsLabel (optional) sends the severity as the label of the created
|
// SeverityAsLabel (optional) sends the severity as the label of the created
|
||||||
// issue.
|
// issue.
|
||||||
SeverityAsLabel bool `yaml:"severity-as-label"`
|
SeverityAsLabel bool `yaml:"severity-as-label"`
|
||||||
HttpClient *retryablehttp.Client
|
|
||||||
|
HttpClient *retryablehttp.Client `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new issue tracker integration client based on options.
|
// New creates a new issue tracker integration client based on options.
|
||||||
|
|
|
@ -32,7 +32,8 @@ type Options struct {
|
||||||
// SeverityAsLabel (optional) sends the severity as the label of the created
|
// SeverityAsLabel (optional) sends the severity as the label of the created
|
||||||
// issue.
|
// issue.
|
||||||
SeverityAsLabel bool `yaml:"severity-as-label"`
|
SeverityAsLabel bool `yaml:"severity-as-label"`
|
||||||
HttpClient *retryablehttp.Client
|
|
||||||
|
HttpClient *retryablehttp.Client `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new issue tracker integration client based on options.
|
// New creates a new issue tracker integration client based on options.
|
||||||
|
|
|
@ -43,9 +43,9 @@ type Options struct {
|
||||||
// SeverityAsLabel (optional) sends the severity as the label of the created
|
// SeverityAsLabel (optional) sends the severity as the label of the created
|
||||||
// issue.
|
// issue.
|
||||||
SeverityAsLabel bool `yaml:"severity-as-label"`
|
SeverityAsLabel bool `yaml:"severity-as-label"`
|
||||||
HttpClient *retryablehttp.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
|
HttpClient *retryablehttp.Client `yaml:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
// New creates a new issue tracker integration client based on options.
|
// New creates a new issue tracker integration client based on options.
|
||||||
func New(options *Options) (*Integration, error) {
|
func New(options *Options) (*Integration, error) {
|
||||||
|
|
Loading…
Reference in New Issue