|
| 1 | +/* |
| 2 | +·━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━· |
| 3 | +: : |
| 4 | +: █▀ █ █▀▀ · Blazing-fast pentesting suite : |
| 5 | +: ▄█ █ █▀ · BSD 3-Clause License : |
| 6 | +: : |
| 7 | +: (c) 2022-2025 vmfunc (Celeste Hickenlooper), xyzeva, : |
| 8 | +: lunchcat alumni & contributors : |
| 9 | +: : |
| 10 | +·━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━· |
| 11 | +*/ |
| 12 | + |
| 13 | +package builtin |
| 14 | + |
| 15 | +import ( |
| 16 | + "context" |
| 17 | + "fmt" |
| 18 | + "github.com/dropalldatabases/sif/internal/modules" |
| 19 | + "github.com/dropalldatabases/sif/internal/scan" |
| 20 | +) |
| 21 | + |
| 22 | +type NucleiModule struct{} |
| 23 | + |
| 24 | +func (m *NucleiModule) Info() modules.Info { |
| 25 | + return modules.Info{ |
| 26 | + ID: "nuclei-scan", |
| 27 | + Name: "Nuclei Vulnerability Scanner", |
| 28 | + Author: "sif", |
| 29 | + Severity: "high", |
| 30 | + Description: "Runs Nuclei vulnerability scanning templates against target", |
| 31 | + Tags: []string{"vuln", "nuclei", "cve"}, |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +func (m *NucleiModule) Type() modules.ModuleType { |
| 36 | + return modules.TypeScript |
| 37 | +} |
| 38 | + |
| 39 | +func (m *NucleiModule) Execute(ctx context.Context, target string, opts modules.Options) (*modules.Result, error) { |
| 40 | + // Call existing legacy scan.Nuclei function |
| 41 | + nucleiResults, err := scan.Nuclei(target, opts.Timeout, opts.Threads, opts.LogDir) |
| 42 | + |
| 43 | + if err != nil { |
| 44 | + return nil, err |
| 45 | + } |
| 46 | + |
| 47 | + result := &modules.Result{ |
| 48 | + ModuleID: m.Info().ID, |
| 49 | + Target: target, |
| 50 | + Findings: make([]modules.Finding, 0, len(nucleiResults)), |
| 51 | + } |
| 52 | + |
| 53 | + // Process nuclei results into module findings |
| 54 | + for _, event := range nucleiResults { |
| 55 | + severity := "info" |
| 56 | + |
| 57 | + switch event.Info.SeverityHolder.Severity.String() { |
| 58 | + case "critical": |
| 59 | + severity = "critical" |
| 60 | + case "high": |
| 61 | + severity = "high" |
| 62 | + case "medium": |
| 63 | + severity = "medium" |
| 64 | + case "low": |
| 65 | + severity = "low" |
| 66 | + } |
| 67 | + |
| 68 | + evidence := fmt.Sprintf("[%s] %s", event.TemplateID, event.Info.Name) |
| 69 | + if event.Matched != "" { |
| 70 | + evidence = fmt.Sprintf("[%s] %s - matched: %s", event.TemplateID, event.Info.Name, event.Matched) |
| 71 | + } |
| 72 | + |
| 73 | + finding := modules.Finding{ |
| 74 | + URL: event.Host, |
| 75 | + Severity: severity, |
| 76 | + Evidence: evidence, |
| 77 | + Extracted: map[string]string{ |
| 78 | + "template_id": event.TemplateID, |
| 79 | + "template_name": event.Info.Name, |
| 80 | + "severity": event.Info.SeverityHolder.Severity.String(), |
| 81 | + }, |
| 82 | + } |
| 83 | + |
| 84 | + // Template info |
| 85 | + if event.Type != "" { |
| 86 | + finding.Extracted["type"] = event.Type |
| 87 | + } |
| 88 | + |
| 89 | + // Matcher name |
| 90 | + if event.MatcherName != "" { |
| 91 | + finding.Extracted["matcher_name"] = event.MatcherName |
| 92 | + } |
| 93 | + |
| 94 | + // Extractor name |
| 95 | + if event.ExtractorName != "" { |
| 96 | + finding.Extracted["extractor_name"] = event.ExtractorName |
| 97 | + } |
| 98 | + |
| 99 | + // Matched line/data |
| 100 | + if event.Matched != "" { |
| 101 | + finding.Extracted["matched"] = event.Matched |
| 102 | + } |
| 103 | + |
| 104 | + // Metadata |
| 105 | + if len(event.Info.Metadata) > 0 { |
| 106 | + for key, value := range event.Info.Metadata { |
| 107 | + finding.Extracted[fmt.Sprintf("metadata_%s", key)] = fmt.Sprintf("%v", value) |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + // Tags |
| 112 | + if !event.Info.Tags.IsEmpty() { |
| 113 | + tagStr := "" |
| 114 | + for _, tag := range event.Info.Tags.ToSlice() { |
| 115 | + if tagStr != "" { |
| 116 | + tagStr += ", " |
| 117 | + } |
| 118 | + tagStr += tag |
| 119 | + } |
| 120 | + |
| 121 | + finding.Extracted["tags"] = tagStr |
| 122 | + } |
| 123 | + |
| 124 | + // Reference |
| 125 | + if event.Info.Reference != nil && !event.Info.Reference.IsEmpty() { |
| 126 | + refStr := "" |
| 127 | + for _, ref := range event.Info.Reference.ToSlice() { |
| 128 | + if refStr != "" { |
| 129 | + refStr += "; " |
| 130 | + } |
| 131 | + refStr += ref |
| 132 | + } |
| 133 | + |
| 134 | + finding.Extracted["references"] = refStr |
| 135 | + } |
| 136 | + |
| 137 | + result.Findings = append(result.Findings, finding) |
| 138 | + } |
| 139 | + |
| 140 | + return result, nil |
| 141 | +} |
0 commit comments