This commit is contained in:
Ice3man543 2021-06-05 20:08:52 +05:30
parent d3b2c8fee0
commit e09f16b68c

View File

@ -14,6 +14,7 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/types"
)
// Exporter is an exporter for nuclei sarif output format.
type Exporter struct {
sarif *sarif.Report
run *sarif.Run
@ -45,10 +46,8 @@ func New(options *Options) (*Exporter, error) {
return &Exporter{options: options, home: templatePath, sarif: report, run: run, mutex: &sync.Mutex{}}, nil
}
// Export exports a passed result event to disk
// Export exports a passed result event to sarif structure
func (i *Exporter) Export(event *output.ResultEvent) error {
i.mutex.Lock()
defer i.mutex.Unlock()
templatePath := strings.TrimPrefix(event.TemplatePath, i.home)
description := getSarifResultMessage(event, templatePath)
@ -81,6 +80,9 @@ func (i *Exporter) Export(event *output.ResultEvent) error {
}
ruleHelp := builder.String()
i.mutex.Lock()
defer i.mutex.Unlock()
_ = i.run.AddRule(event.TemplateID).
WithDescription(ruleName).
WithHelp(ruleHelp).
@ -183,6 +185,9 @@ func getSarifResultMessage(event *output.ResultEvent, templatePath string) strin
// Close closes the exporter after operation
func (i *Exporter) Close() error {
i.mutex.Lock()
defer i.mutex.Unlock()
i.sarif.AddRun(i.run)
file, err := os.Create(i.options.File)