Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
projectdiscovery
GitHub Repository: projectdiscovery/nuclei
Path: blob/dev/pkg/core/engine.go
2070 views
1
package core
2
3
import (
4
"github.com/projectdiscovery/gologger"
5
"github.com/projectdiscovery/nuclei/v3/pkg/output"
6
"github.com/projectdiscovery/nuclei/v3/pkg/protocols"
7
"github.com/projectdiscovery/nuclei/v3/pkg/types"
8
)
9
10
// Engine is an executer for running Nuclei Templates/Workflows.
11
//
12
// The engine contains multiple thread pools which allow using different
13
// concurrency values per protocol executed.
14
//
15
// The engine does most of the heavy lifting of execution, from clustering
16
// templates to leading to the final execution by the work pool, it is
17
// handled by the engine.
18
type Engine struct {
19
workPool *WorkPool
20
options *types.Options
21
executerOpts *protocols.ExecutorOptions
22
Callback func(*output.ResultEvent) // Executed on results
23
Logger *gologger.Logger
24
}
25
26
// New returns a new Engine instance
27
func New(options *types.Options) *Engine {
28
engine := &Engine{
29
options: options,
30
Logger: options.Logger,
31
}
32
engine.workPool = engine.GetWorkPool()
33
return engine
34
}
35
36
func (e *Engine) GetWorkPoolConfig() WorkPoolConfig {
37
config := WorkPoolConfig{
38
InputConcurrency: e.options.BulkSize,
39
TypeConcurrency: e.options.TemplateThreads,
40
HeadlessInputConcurrency: e.options.HeadlessBulkSize,
41
HeadlessTypeConcurrency: e.options.HeadlessTemplateThreads,
42
}
43
return config
44
}
45
46
// GetWorkPool returns a workpool from options
47
func (e *Engine) GetWorkPool() *WorkPool {
48
return NewWorkPool(e.GetWorkPoolConfig())
49
}
50
51
// SetExecuterOptions sets the executer options for the engine. This is required
52
// before using the engine to perform any execution.
53
func (e *Engine) SetExecuterOptions(options *protocols.ExecutorOptions) {
54
e.executerOpts = options
55
}
56
57
// ExecuterOptions returns protocols.ExecutorOptions for nuclei engine.
58
func (e *Engine) ExecuterOptions() *protocols.ExecutorOptions {
59
return e.executerOpts
60
}
61
62
// WorkPool returns the worker pool for the engine
63
func (e *Engine) WorkPool() *WorkPool {
64
// resize check point - nop if there are no changes
65
e.workPool.RefreshWithConfig(e.GetWorkPoolConfig())
66
return e.workPool
67
}
68
69