mirror of https://github.com/daffainfo/nuclei.git
Merge pull request #1639 from projectdiscovery/random-resume-file
Allow random resume file generation on conflict + made resume stringdev
commit
156d5baf69
|
@ -50,7 +50,7 @@ func main() {
|
||||||
nucleiRunner.Close()
|
nucleiRunner.Close()
|
||||||
if options.ShouldSaveResume() {
|
if options.ShouldSaveResume() {
|
||||||
gologger.Info().Msgf("Creating resume file: %s\n", resumeFileName)
|
gologger.Info().Msgf("Creating resume file: %s\n", resumeFileName)
|
||||||
err := nucleiRunner.SaveResumeConfig()
|
err := nucleiRunner.SaveResumeConfig(resumeFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gologger.Error().Msgf("Couldn't create resume file: %s\n", err)
|
gologger.Error().Msgf("Couldn't create resume file: %s\n", err)
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ on extensive configurability, massive extensibility and ease of use.`)
|
||||||
createGroup(flagSet, "input", "Target",
|
createGroup(flagSet, "input", "Target",
|
||||||
flagSet.StringSliceVarP(&options.Targets, "target", "u", []string{}, "target URLs/hosts to scan"),
|
flagSet.StringSliceVarP(&options.Targets, "target", "u", []string{}, "target URLs/hosts to scan"),
|
||||||
flagSet.StringVarP(&options.TargetsFilePath, "list", "l", "", "path to file containing a list of target URLs/hosts to scan (one per line)"),
|
flagSet.StringVarP(&options.TargetsFilePath, "list", "l", "", "path to file containing a list of target URLs/hosts to scan (one per line)"),
|
||||||
flagSet.BoolVar(&options.Resume, "resume", false, "Resume scan using resume.cfg (clustering will be disabled)"),
|
flagSet.StringVar(&options.Resume, "resume", "", "Resume scan using resume.cfg (clustering will be disabled)"),
|
||||||
)
|
)
|
||||||
|
|
||||||
createGroup(flagSet, "templates", "Templates",
|
createGroup(flagSet, "templates", "Templates",
|
||||||
|
|
|
@ -158,7 +158,7 @@ func New(options *types.Options) (*Runner, error) {
|
||||||
resumeCfg := types.NewResumeCfg()
|
resumeCfg := types.NewResumeCfg()
|
||||||
if runner.options.ShouldLoadResume() {
|
if runner.options.ShouldLoadResume() {
|
||||||
gologger.Info().Msg("Resuming from save checkpoint")
|
gologger.Info().Msg("Resuming from save checkpoint")
|
||||||
file, err := ioutil.ReadFile(types.DefaultResumeFilePath())
|
file, err := ioutil.ReadFile(runner.options.Resume)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,6 @@ func New(options *types.Options) (*Runner, error) {
|
||||||
}
|
}
|
||||||
resumeCfg.Compile()
|
resumeCfg.Compile()
|
||||||
}
|
}
|
||||||
|
|
||||||
runner.resumeCfg = resumeCfg
|
runner.resumeCfg = resumeCfg
|
||||||
|
|
||||||
opts := interactsh.NewDefaultOptions(runner.output, runner.issuesClient, runner.progress)
|
opts := interactsh.NewDefaultOptions(runner.output, runner.issuesClient, runner.progress)
|
||||||
|
@ -496,10 +495,10 @@ func isTemplate(filename string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveResumeConfig to file
|
// SaveResumeConfig to file
|
||||||
func (r *Runner) SaveResumeConfig() error {
|
func (r *Runner) SaveResumeConfig(path string) error {
|
||||||
resumeCfg := types.NewResumeCfg()
|
resumeCfg := types.NewResumeCfg()
|
||||||
resumeCfg.ResumeFrom = r.resumeCfg.Current
|
resumeCfg.ResumeFrom = r.resumeCfg.Current
|
||||||
data, _ := json.MarshalIndent(resumeCfg, "", "\t")
|
data, _ := json.MarshalIndent(resumeCfg, "", "\t")
|
||||||
|
|
||||||
return os.WriteFile(types.DefaultResumeFilePath(), data, os.ModePerm)
|
return os.WriteFile(path, data, os.ModePerm)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,25 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/rs/xid"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Default resume file
|
// Default resume file
|
||||||
const DefaultResumeFileName = "resume.cfg"
|
const DefaultResumeFileName = "resume-%s.cfg"
|
||||||
|
|
||||||
func DefaultResumeFilePath() string {
|
func DefaultResumeFilePath() string {
|
||||||
home, err := os.UserHomeDir()
|
home, err := os.UserHomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return DefaultResumeFileName
|
return fmt.Sprintf("resume-%s.cfg", xid.New().String())
|
||||||
}
|
}
|
||||||
return filepath.Join(home, ".config", "nuclei", DefaultResumeFileName)
|
resumeFile := filepath.Join(home, ".config", "nuclei", fmt.Sprintf("resume-%s.cfg", xid.New().String()))
|
||||||
|
return resumeFile
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResumeCfg contains the scan progression
|
// ResumeCfg contains the scan progression
|
||||||
|
|
|
@ -64,7 +64,7 @@ type Options struct {
|
||||||
// TargetsFilePath specifies the targets from a file to scan using templates.
|
// TargetsFilePath specifies the targets from a file to scan using templates.
|
||||||
TargetsFilePath string
|
TargetsFilePath string
|
||||||
// Resume the scan from the state stored in the resume config file
|
// Resume the scan from the state stored in the resume config file
|
||||||
Resume bool
|
Resume string
|
||||||
// Output is the file to write found results to.
|
// Output is the file to write found results to.
|
||||||
Output string
|
Output string
|
||||||
// List of HTTP(s)/SOCKS5 proxy to use (comma separated or file input)
|
// List of HTTP(s)/SOCKS5 proxy to use (comma separated or file input)
|
||||||
|
@ -214,7 +214,7 @@ func (options *Options) VarsPayload() map[string]interface{} {
|
||||||
|
|
||||||
// ShouldLoadResume resume file
|
// ShouldLoadResume resume file
|
||||||
func (options *Options) ShouldLoadResume() bool {
|
func (options *Options) ShouldLoadResume() bool {
|
||||||
return options.Resume && fileutil.FileExists(DefaultResumeFilePath())
|
return options.Resume != "" && fileutil.FileExists(options.Resume)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShouldSaveResume file
|
// ShouldSaveResume file
|
||||||
|
|
Loading…
Reference in New Issue