I encountered some issues while using the nuclei SDK. #6781
Replies: 3 comments 1 reply
-
|
The error ne, err := nuclei.NewNucleiEngineCtx(
ctx,
nuclei.WithTemplateFilters(nuclei.TemplateFilters{
Tags: []string{"struts"},
}),
)
if err != nil {
log.Fatal(err)
}
defer ne.Close()
ne.LoadTargets([]string{"123.58.224.8:29067"}, false)
err = ne.ExecuteWithCallback(func(event *output.ResultEvent) {
fmt.Printf("Found: %s\n", event.TemplateID)
})Key fixes:
|
Beta Was this translation helpful? Give feedback.
-
|
The error indicates improper engine initialization. Use nuclei.WithTemplateFilters() instead of nuclei.WithOptions(). Also ensure templates are downloaded with nuclei -update-templates. Move defer ne.Close() right after engine creation, not at the end of main(). |
Beta Was this translation helpful? Give feedback.
-
|
Building on the answers above -- the core issue is that package main
import (
"context"
"fmt"
"log"
"time"
nuclei "github.com/projectdiscovery/nuclei/v3/lib"
"github.com/projectdiscovery/nuclei/v3/pkg/output"
)
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
ne, err := nuclei.NewNucleiEngineCtx(
ctx,
// Use WithTemplateFilters instead of raw WithOptions
nuclei.WithTemplateFilters(nuclei.TemplateFilters{
Tags: []string{"struts"},
}),
// Always set rate limiting - prevents resource exhaustion
nuclei.WithGlobalRateLimitCtx(ctx, 150, time.Second),
nuclei.WithConcurrency(nuclei.Concurrency{
TemplateConcurrency: 25,
HostConcurrency: 10,
}),
)
if err != nil {
log.Fatal(err)
}
defer ne.Close() // Always defer Close immediately after creation
ne.LoadTargets([]string{"123.58.224.8:29067"}, false)
err = ne.ExecuteWithCallback(func(event *output.ResultEvent) {
fmt.Printf("[%s] %s @ %s\n",
event.Info.SeverityHolder.Severity,
event.TemplateID,
event.Host,
)
})
if err != nil {
log.Fatal(err)
}
}Key Fixes
If You Must Use WithOptionsAs you discovered, you need to manually set opts := types.DefaultOptions() // Use DefaultOptions, not empty Options{}
opts.ExecutionId = uuid.New().String()
opts.Templates = []string{"path/to/templates"}
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am on the Windows platform.
# nuclei version: github.com/projectdiscovery/nuclei/v3 v3.6.2 go gun main.gothis is code:
The code cannot be executed.
error:
Beta Was this translation helpful? Give feedback.
All reactions