Review changes

dev
Ice3man 2022-12-20 00:31:13 +05:30
parent 8eda1a2458
commit 7b69b36a4f
5 changed files with 27 additions and 27 deletions

View File

@ -19,16 +19,16 @@ import (
// Get all the scan lists for a user/apikey.
func (r *Runner) getScanList(limit int) error {
lastTime := "2099-01-02 15:04:05 +0000 UTC"
header := []string{"ID", "Timestamp", "Status", "Matched", "Targets", "Templates", "Duration"}
var values [][]string
var count int
var e error
var (
values [][]string
count int
)
for {
items, err := r.cloudClient.GetScans(limit, lastTime)
if err != nil {
e = err
break
return err
}
if len(items) == 0 {
break
@ -46,9 +46,6 @@ func (r *Runner) getScanList(limit int) error {
}
}
}
if e != nil {
return e
}
if count == 0 {
return errors.New("no scan list found")
}
@ -81,7 +78,7 @@ func (r *Runner) listDatasources() error {
if !r.options.NoTables {
r.prettyPrintTable(header, values)
}
return err
return nil
}
func (r *Runner) listTargets() error {
@ -107,7 +104,7 @@ func (r *Runner) listTargets() error {
if !r.options.NoTables {
r.prettyPrintTable(header, values)
}
return err
return nil
}
func (r *Runner) listTemplates() error {
@ -133,7 +130,7 @@ func (r *Runner) listTemplates() error {
if !r.options.NoTables {
r.prettyPrintTable(header, values)
}
return err
return nil
}
func (r *Runner) prettyPrintTable(header []string, values [][]string) {
@ -156,11 +153,11 @@ func (r *Runner) deleteScan(id string) error {
func (r *Runner) getResults(id string, limit int) error {
ID, _ := strconv.ParseInt(id, 10, 64)
err := r.cloudClient.GetResults(ID, func(re *output.ResultEvent) {
err := r.cloudClient.GetResults(ID, false, limit, func(re *output.ResultEvent) {
if outputErr := r.output.Write(re); outputErr != nil {
gologger.Warning().Msgf("Could not write output: %s", outputErr)
}
}, false, limit)
})
return err
}
@ -173,7 +170,7 @@ func (r *Runner) getTarget(id string) error {
defer reader.Close()
_, _ = io.Copy(os.Stdout, reader)
return err
return nil
}
func (r *Runner) getTemplate(id string) error {
@ -185,7 +182,7 @@ func (r *Runner) getTemplate(id string) error {
defer reader.Close()
_, _ = io.Copy(os.Stdout, reader)
return err
return nil
}
func (r *Runner) removeDatasource(datasource string) error {
@ -207,7 +204,7 @@ func (r *Runner) addTemplate(location string) error {
if err != nil {
return err
}
if d.IsDir() || !strings.HasSuffix(path, ".yaml") {
if d.IsDir() || !strings.EqualFold(filepath.Ext(path), ".yaml") {
return nil
}
base := filepath.Base(path)
@ -227,7 +224,7 @@ func (r *Runner) addTarget(location string) error {
if err != nil {
return err
}
if d.IsDir() || !strings.HasSuffix(path, ".txt") {
if d.IsDir() || !strings.EqualFold(filepath.Ext(path), ".txt") {
return nil
}
base := filepath.Base(location)
@ -254,7 +251,7 @@ func (r *Runner) removeTarget(item string) error {
gologger.Info().Msgf("Target deleted %s", item.Reference)
}
}
return err
return nil
}
func (r *Runner) removeTemplate(item string) error {
@ -269,7 +266,7 @@ func (r *Runner) removeTemplate(item string) error {
gologger.Info().Msgf("Template deleted %s", item.Reference)
}
}
return err
return nil
}
// initializeCloudDataSources initializes cloud data sources

View File

@ -82,7 +82,7 @@ func (r *Runner) runCloudEnumeration(store *loader.Store, cloudTemplates, cloudT
}
time.Sleep(3 * time.Second)
err = r.cloudClient.GetResults(taskID, func(re *output.ResultEvent) {
err = r.cloudClient.GetResults(taskID, true, limit, func(re *output.ResultEvent) {
results.CompareAndSwap(false, true)
_ = count.Inc()
@ -94,7 +94,7 @@ func (r *Runner) runCloudEnumeration(store *loader.Store, cloudTemplates, cloudT
gologger.Warning().Msgf("Could not create issue on tracker: %s", err)
}
}
}, true, limit)
})
return results, err
}

View File

@ -86,7 +86,7 @@ func (c *Client) AddScan(req *AddScanRequest) (int64, error) {
// GetResults gets results from nuclei server for an ID
// until there are no more results left to retrieve.
func (c *Client) GetResults(ID int64, callback func(*output.ResultEvent), checkProgress bool, limit int) error {
func (c *Client) GetResults(ID int64, checkProgress bool, limit int, callback func(*output.ResultEvent)) error {
lastID := int64(0)
for {

View File

@ -194,11 +194,9 @@ func validateOptions(options *types.Options) error {
}
func validateCloudOptions(options *types.Options) error {
if options.ScanList || options.DeleteScan != "" || options.ScanOutput != "" || options.ListDatasources || options.ListTargets || options.ListTemplates || options.RemoveDatasource != "" || options.AddTarget != "" || options.AddTemplate != "" || options.RemoveTarget != "" || options.RemoveTemplate != "" || options.GetTarget != "" || options.GetTemplate != "" {
if !options.Cloud {
if options.HasCloudOptions() && !options.Cloud {
return errors.New("cloud flags cannot be used without cloud option")
}
}
if options.Cloud {
if options.CloudAPIKey == "" {
return errors.New("missing NUCLEI_CLOUD_API env variable")

View File

@ -378,3 +378,8 @@ func DefaultOptions() *Options {
MaxHostError: 30,
}
}
// HasCloudOptions returns true if cloud options have been specified
func (options *Options) HasCloudOptions() bool {
return options.ScanList || options.DeleteScan != "" || options.ScanOutput != "" || options.ListDatasources || options.ListTargets || options.ListTemplates || options.RemoveDatasource != "" || options.AddTarget != "" || options.AddTemplate != "" || options.RemoveTarget != "" || options.RemoveTemplate != "" || options.GetTarget != "" || options.GetTemplate != ""
}