mirror of https://github.com/daffainfo/nuclei.git
Adjusting packages for more API-type design
parent
1ca2cf3bea
commit
5393cc4cd5
|
@ -1,7 +1,6 @@
|
||||||
package testutils
|
package testutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/logrusorgru/aurora"
|
|
||||||
"go.uber.org/ratelimit"
|
"go.uber.org/ratelimit"
|
||||||
|
|
||||||
"github.com/projectdiscovery/gologger/levels"
|
"github.com/projectdiscovery/gologger/levels"
|
||||||
|
@ -60,41 +59,6 @@ var DefaultOptions = &types.Options{
|
||||||
CustomHeaders: []string{},
|
CustomHeaders: []string{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// MockOutputWriter is a mocked output writer.
|
|
||||||
type MockOutputWriter struct {
|
|
||||||
aurora aurora.Aurora
|
|
||||||
RequestCallback func(templateID, url, requestType string, err error)
|
|
||||||
WriteCallback func(o *output.ResultEvent)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMockOutputWriter creates a new mock output writer
|
|
||||||
func NewMockOutputWriter() *MockOutputWriter {
|
|
||||||
return &MockOutputWriter{aurora: aurora.NewAurora(false)}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close closes the output writer interface
|
|
||||||
func (m *MockOutputWriter) Close() {}
|
|
||||||
|
|
||||||
// Colorizer returns the colorizer instance for writer
|
|
||||||
func (m *MockOutputWriter) Colorizer() aurora.Aurora {
|
|
||||||
return m.aurora
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write writes the event to file and/or screen.
|
|
||||||
func (m *MockOutputWriter) Write(result *output.ResultEvent) error {
|
|
||||||
if m.WriteCallback != nil {
|
|
||||||
m.WriteCallback(result)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Request writes a log the requests trace log
|
|
||||||
func (m *MockOutputWriter) Request(templateID, url, requestType string, err error) {
|
|
||||||
if m.RequestCallback != nil {
|
|
||||||
m.RequestCallback(templateID, url, requestType, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TemplateInfo contains info for a mock executed template.
|
// TemplateInfo contains info for a mock executed template.
|
||||||
type TemplateInfo struct {
|
type TemplateInfo struct {
|
||||||
ID string
|
ID string
|
||||||
|
@ -109,7 +73,7 @@ func NewMockExecuterOptions(options *types.Options, info *TemplateInfo) *protoco
|
||||||
TemplateID: info.ID,
|
TemplateID: info.ID,
|
||||||
TemplateInfo: info.Info,
|
TemplateInfo: info.Info,
|
||||||
TemplatePath: info.Path,
|
TemplatePath: info.Path,
|
||||||
Output: NewMockOutputWriter(),
|
Output: output.NewMockOutputWriter(),
|
||||||
Options: options,
|
Options: options,
|
||||||
Progress: progressImpl,
|
Progress: progressImpl,
|
||||||
ProjectFile: nil,
|
ProjectFile: nil,
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package inputs
|
||||||
|
|
||||||
|
type SimpleInputProvider struct {
|
||||||
|
Inputs []string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the number of items for input provider
|
||||||
|
func (s *SimpleInputProvider) Count() int64 {
|
||||||
|
return int64(len(s.Inputs))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan calls a callback function till the input provider is exhausted
|
||||||
|
func (s *SimpleInputProvider) Scan(callback func(value string)) {
|
||||||
|
for _, v := range s.Inputs {
|
||||||
|
callback(v)
|
||||||
|
}
|
||||||
|
}
|
|
@ -209,3 +209,38 @@ func (w *StandardWriter) Close() {
|
||||||
w.traceFile.Close()
|
w.traceFile.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MockOutputWriter is a mocked output writer.
|
||||||
|
type MockOutputWriter struct {
|
||||||
|
aurora aurora.Aurora
|
||||||
|
RequestCallback func(templateID, url, requestType string, err error)
|
||||||
|
WriteCallback func(o *ResultEvent)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockOutputWriter creates a new mock output writer
|
||||||
|
func NewMockOutputWriter() *MockOutputWriter {
|
||||||
|
return &MockOutputWriter{aurora: aurora.NewAurora(false)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close closes the output writer interface
|
||||||
|
func (m *MockOutputWriter) Close() {}
|
||||||
|
|
||||||
|
// Colorizer returns the colorizer instance for writer
|
||||||
|
func (m *MockOutputWriter) Colorizer() aurora.Aurora {
|
||||||
|
return m.aurora
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write writes the event to file and/or screen.
|
||||||
|
func (m *MockOutputWriter) Write(result *ResultEvent) error {
|
||||||
|
if m.WriteCallback != nil {
|
||||||
|
m.WriteCallback(result)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Request writes a log the requests trace log
|
||||||
|
func (m *MockOutputWriter) Request(templateID, url, requestType string, err error) {
|
||||||
|
if m.RequestCallback != nil {
|
||||||
|
m.RequestCallback(templateID, url, requestType, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -247,3 +247,27 @@ func (p *StatsTicker) Stop() {
|
||||||
_ = p.server.Shutdown(context.Background())
|
_ = p.server.Shutdown(context.Background())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MockProgressClient struct{}
|
||||||
|
|
||||||
|
// Stop stops the progress recorder.
|
||||||
|
func (m *MockProgressClient) Stop() {}
|
||||||
|
|
||||||
|
// Init inits the progress bar with initial details for scan
|
||||||
|
func (m *MockProgressClient) Init(hostCount int64, rulesCount int, requestCount int64) {}
|
||||||
|
|
||||||
|
// AddToTotal adds a value to the total request count
|
||||||
|
func (m *MockProgressClient) AddToTotal(delta int64) {}
|
||||||
|
|
||||||
|
// IncrementRequests increments the requests counter by 1.
|
||||||
|
func (m *MockProgressClient) IncrementRequests() {}
|
||||||
|
|
||||||
|
// IncrementMatched increments the matched counter by 1.
|
||||||
|
func (m *MockProgressClient) IncrementMatched() {}
|
||||||
|
|
||||||
|
// IncrementErrorsBy increments the error counter by count.
|
||||||
|
func (m *MockProgressClient) IncrementErrorsBy(count int64) {}
|
||||||
|
|
||||||
|
// IncrementFailedRequestsBy increments the number of requests counter by count
|
||||||
|
// along with errors.
|
||||||
|
func (m *MockProgressClient) IncrementFailedRequestsBy(count int64) {}
|
||||||
|
|
|
@ -103,6 +103,20 @@ func New(options *Options) (*Client, error) {
|
||||||
return interactClient, nil
|
return interactClient, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewDefaultOptions returns the default options for interactsh client
|
||||||
|
func NewDefaultOptions(output output.Writer, reporting *reporting.Client, progress progress.Progress) *Options {
|
||||||
|
return &Options{
|
||||||
|
ServerURL: "https://interactsh.com",
|
||||||
|
CacheSize: 5000,
|
||||||
|
Eviction: 60 * time.Second,
|
||||||
|
ColldownPeriod: 5 * time.Second,
|
||||||
|
PollDuration: 5 * time.Second,
|
||||||
|
Output: output,
|
||||||
|
IssuesClient: reporting,
|
||||||
|
Progress: progress,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) firstTimeInitializeClient() error {
|
func (c *Client) firstTimeInitializeClient() error {
|
||||||
interactsh, err := client.New(&client.Options{
|
interactsh, err := client.New(&client.Options{
|
||||||
ServerURL: c.options.ServerURL,
|
ServerURL: c.options.ServerURL,
|
||||||
|
|
|
@ -181,3 +181,17 @@ func (options *Options) AddVarPayload(key string, value interface{}) {
|
||||||
func (options *Options) VarsPayload() map[string]interface{} {
|
func (options *Options) VarsPayload() map[string]interface{} {
|
||||||
return options.varsPayload
|
return options.varsPayload
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DefaultOptions returns default options for nuclei
|
||||||
|
func DefaultOptions() *Options {
|
||||||
|
return &Options{
|
||||||
|
RateLimit: 150,
|
||||||
|
BulkSize: 25,
|
||||||
|
TemplateThreads: 25,
|
||||||
|
HeadlessBulkSize: 10,
|
||||||
|
HeadlessTemplateThreads: 10,
|
||||||
|
Timeout: 5,
|
||||||
|
Retries: 1,
|
||||||
|
MaxHostError: 30,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue