Merge pull request #1639 from projectdiscovery/random-resume-file

Allow random resume file generation on conflict + made resume string
dev
Sandeep Singh 2022-02-25 17:14:12 +05:30 committed by GitHub
commit 156d5baf69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 11 deletions

View File

@ -50,7 +50,7 @@ func main() {
nucleiRunner.Close()
if options.ShouldSaveResume() {
gologger.Info().Msgf("Creating resume file: %s\n", resumeFileName)
err := nucleiRunner.SaveResumeConfig()
err := nucleiRunner.SaveResumeConfig(resumeFileName)
if err != nil {
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",
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.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",

View File

@ -158,7 +158,7 @@ func New(options *types.Options) (*Runner, error) {
resumeCfg := types.NewResumeCfg()
if runner.options.ShouldLoadResume() {
gologger.Info().Msg("Resuming from save checkpoint")
file, err := ioutil.ReadFile(types.DefaultResumeFilePath())
file, err := ioutil.ReadFile(runner.options.Resume)
if err != nil {
return nil, err
}
@ -168,7 +168,6 @@ func New(options *types.Options) (*Runner, error) {
}
resumeCfg.Compile()
}
runner.resumeCfg = resumeCfg
opts := interactsh.NewDefaultOptions(runner.output, runner.issuesClient, runner.progress)
@ -496,10 +495,10 @@ func isTemplate(filename string) bool {
}
// SaveResumeConfig to file
func (r *Runner) SaveResumeConfig() error {
func (r *Runner) SaveResumeConfig(path string) error {
resumeCfg := types.NewResumeCfg()
resumeCfg.ResumeFrom = r.resumeCfg.Current
data, _ := json.MarshalIndent(resumeCfg, "", "\t")
return os.WriteFile(types.DefaultResumeFilePath(), data, os.ModePerm)
return os.WriteFile(path, data, os.ModePerm)
}

View File

@ -1,21 +1,25 @@
package types
import (
"fmt"
"math"
"os"
"path/filepath"
"sync"
"github.com/rs/xid"
)
// Default resume file
const DefaultResumeFileName = "resume.cfg"
const DefaultResumeFileName = "resume-%s.cfg"
func DefaultResumeFilePath() string {
home, err := os.UserHomeDir()
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

View File

@ -64,7 +64,7 @@ type Options struct {
// TargetsFilePath specifies the targets from a file to scan using templates.
TargetsFilePath string
// 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 string
// 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
func (options *Options) ShouldLoadResume() bool {
return options.Resume && fileutil.FileExists(DefaultResumeFilePath())
return options.Resume != "" && fileutil.FileExists(options.Resume)
}
// ShouldSaveResume file