Merge branch 'dev' into issue-1594-regexp

dev
Sandeep Singh 2022-03-08 10:05:06 +05:30 committed by GitHub
commit ce2a5c3d81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 0 deletions

View File

@ -194,6 +194,7 @@ on extensive configurability, massive extensibility and ease of use.`)
flagSet.BoolVar(&options.Version, "version", false, "show nuclei version"),
flagSet.BoolVarP(&options.Verbose, "verbose", "v", false, "show verbose output"),
flagSet.BoolVar(&options.VerboseVerbose, "vv", false, "display templates loaded for scan"),
flagSet.BoolVar(&options.EnablePprof, "enable-pprof", false, "enable pprof debugging server"),
flagSet.BoolVarP(&options.TemplatesVersion, "templates-version", "tv", false, "shows the version of the installed nuclei-templates"),
)

View File

@ -2,7 +2,11 @@ package runner
import (
"bufio"
"context"
"encoding/json"
"io/ioutil"
"net/http"
_ "net/http/pprof"
"os"
"path/filepath"
"strings"
@ -57,8 +61,11 @@ type Runner struct {
ratelimiter ratelimit.Limiter
hostErrors *hosterrorscache.Cache
resumeCfg *types.ResumeCfg
pprofServer *http.Server
}
const pprofServerAddress = "127.0.0.1:8086"
// New creates a new client for running enumeration process.
func New(options *types.Options) (*Runner, error) {
runner := &Runner{
@ -112,6 +119,17 @@ func New(options *types.Options) (*Runner, error) {
runner.listAvailableTemplates()
os.Exit(0)
}
if options.EnablePprof {
server := &http.Server{
Addr: pprofServerAddress,
Handler: http.DefaultServeMux,
}
gologger.Info().Msgf("Listening pprof debug server on: %s", pprofServerAddress)
runner.pprofServer = server
go func() {
_ = server.ListenAndServe()
}()
}
if (len(options.Templates) == 0 || !options.NewTemplates || (options.TargetsFilePath == "" && !options.Stdin && len(options.Targets) == 0)) && options.UpdateTemplates {
os.Exit(0)
@ -246,6 +264,9 @@ func (r *Runner) Close() {
}
r.hmapInputProvider.Close()
protocolinit.Close()
if r.pprofServer != nil {
_ = r.pprofServer.Shutdown(context.Background())
}
}
// RunEnumeration sets up the input layer for giving input nuclei.

View File

@ -198,6 +198,8 @@ type Options struct {
ClientCAFile string
// Use ZTLS library
ZTLS bool
// EnablePprof enables exposing pprof runtime information with a webserver.
EnablePprof bool
}
func (options *Options) AddVarPayload(key string, value interface{}) {