Skip to content

Commit d8ab3f8

Browse files
authored
Merge branch 'main' into feat/builtin-shodan
2 parents e3a7123 + c988e54 commit d8ab3f8

File tree

3 files changed

+159
-8
lines changed

3 files changed

+159
-8
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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+
}

internal/scan/builtin/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ import "github.com/dropalldatabases/sif/internal/modules"
1818
// Allows complex Go scans to participate in the module system
1919
func Register() {
2020
modules.Register(&ShodanModule{})
21+
modules.Register(&NucleiModule{})
2122
}

internal/scan/nuclei.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/dropalldatabases/sif/internal/nuclei/format"
2424
"github.com/dropalldatabases/sif/internal/nuclei/templates"
2525
sifoutput "github.com/dropalldatabases/sif/internal/output"
26+
"github.com/logrusorgru/aurora"
2627
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/config"
2728
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/disk"
2829
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/loader"
@@ -59,6 +60,12 @@ func Nuclei(url string, timeout time.Duration, threads int, logdir string) ([]ou
5960
options.TemplateThreads = threads
6061
options.Timeout = int(timeout.Seconds())
6162

63+
if logdir != "" {
64+
options.ProjectPath = logdir
65+
}
66+
67+
options.Headless = false
68+
6269
// Get templates
6370
templates.Install(nucleilog)
6471
pwd, err := os.Getwd()
@@ -101,14 +108,16 @@ func Nuclei(url string, timeout time.Duration, threads int, logdir string) ([]ou
101108
protocolinit.Init(options)
102109

103110
executorOpts := protocols.ExecutorOptions{
104-
Output: outputWriter,
105-
Progress: progressClient,
106-
Catalog: catalog,
107-
Options: options,
108-
IssuesClient: reportingClient,
109-
RateLimiter: ratelimit.New(context.Background(), 150, time.Second),
110-
Interactsh: interactClient,
111-
ResumeCfg: types.NewResumeCfg(),
111+
Colorizer: aurora.NewAurora(false),
112+
Output: outputWriter,
113+
Progress: progressClient,
114+
Catalog: catalog,
115+
Options: options,
116+
IssuesClient: reportingClient,
117+
RateLimiter: ratelimit.New(context.Background(), 150, time.Second),
118+
Interactsh: interactClient,
119+
HostErrorsCache: cache,
120+
ResumeCfg: types.NewResumeCfg(),
112121
}
113122
engine := core.New(options)
114123
engine.SetExecuterOptions(executorOpts)

0 commit comments

Comments
 (0)