mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2026-01-31 15:53:10 +08:00
Use integer IDs for scan tasks
This commit is contained in:
@@ -40,7 +40,8 @@ func (r *Runner) getScanList(limit int) error {
|
||||
}
|
||||
|
||||
func (r *Runner) deleteScan(id string) error {
|
||||
deleted, err := r.cloudClient.DeleteScan(id)
|
||||
ID, _ := strconv.ParseInt(id, 10, 64)
|
||||
deleted, err := r.cloudClient.DeleteScan(ID)
|
||||
if !deleted.OK {
|
||||
gologger.Error().Msgf("Error in deleting the scan %s.", id)
|
||||
} else {
|
||||
@@ -50,7 +51,8 @@ func (r *Runner) deleteScan(id string) error {
|
||||
}
|
||||
|
||||
func (r *Runner) getResults(id string, limit int) error {
|
||||
err := r.cloudClient.GetResults(id, func(re *output.ResultEvent) {
|
||||
ID, _ := strconv.ParseInt(id, 10, 64)
|
||||
err := r.cloudClient.GetResults(ID, func(re *output.ResultEvent) {
|
||||
if outputErr := r.output.Write(re); outputErr != nil {
|
||||
gologger.Warning().Msgf("Could not write output: %s", outputErr)
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ func (r *Runner) runCloudEnumeration(store *loader.Store, cloudTemplates, cloudT
|
||||
if err != nil {
|
||||
return results, err
|
||||
}
|
||||
gologger.Info().Msgf("Created task with ID: %s", taskID)
|
||||
gologger.Info().Msgf("Created task with ID: %d", taskID)
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
err = r.cloudClient.GetResults(taskID, func(re *output.ResultEvent) {
|
||||
|
||||
@@ -48,25 +48,25 @@ func New(baseURL, apiKey string) *Client {
|
||||
}
|
||||
|
||||
// AddScan adds a scan for templates and target to nuclei server
|
||||
func (c *Client) AddScan(req *AddScanRequest) (string, error) {
|
||||
func (c *Client) AddScan(req *AddScanRequest) (int64, error) {
|
||||
var buf bytes.Buffer
|
||||
if err := jsoniter.NewEncoder(&buf).Encode(req); err != nil {
|
||||
return "", errors.Wrap(err, "could not encode request")
|
||||
return 0, errors.Wrap(err, "could not encode request")
|
||||
}
|
||||
httpReq, err := retryablehttp.NewRequest(http.MethodPost, fmt.Sprintf("%s/scan", c.baseURL), bytes.NewReader(buf.Bytes()))
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "could not make request")
|
||||
return 0, errors.Wrap(err, "could not make request")
|
||||
}
|
||||
|
||||
resp, err := c.sendRequest(httpReq)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(err, "could not do request")
|
||||
return 0, errors.Wrap(err, "could not do request")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var data map[string]string
|
||||
var data map[string]int64
|
||||
if err := jsoniter.NewDecoder(resp.Body).Decode(&data); err != nil {
|
||||
return "", errors.Wrap(err, "could not decode resp")
|
||||
return 0, errors.Wrap(err, "could not decode resp")
|
||||
}
|
||||
id := data["id"]
|
||||
return id, nil
|
||||
@@ -74,11 +74,11 @@ func (c *Client) AddScan(req *AddScanRequest) (string, error) {
|
||||
|
||||
// GetResults gets results from nuclei server for an ID
|
||||
// until there are no more results left to retrieve.
|
||||
func (c *Client) GetResults(ID string, callback func(*output.ResultEvent), checkProgress bool, limit int) error {
|
||||
func (c *Client) GetResults(ID int64, callback func(*output.ResultEvent), checkProgress bool, limit int) error {
|
||||
lastID := int64(0)
|
||||
|
||||
for {
|
||||
uri := fmt.Sprintf("%s/results?id=%s&from=%d&size=%d", c.baseURL, ID, lastID, limit)
|
||||
uri := fmt.Sprintf("%s/results?id=%d&from=%d&size=%d", c.baseURL, ID, lastID, limit)
|
||||
httpReq, err := retryablehttp.NewRequest(http.MethodGet, uri, nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not make request")
|
||||
@@ -140,9 +140,9 @@ func (c *Client) GetScans(limit int, from string) ([]GetScanRequest, error) {
|
||||
}
|
||||
|
||||
// Delete a scan and it's issues by the scan id.
|
||||
func (c *Client) DeleteScan(id string) (DeleteScanResults, error) {
|
||||
func (c *Client) DeleteScan(id int64) (DeleteScanResults, error) {
|
||||
deletescan := DeleteScanResults{}
|
||||
httpReq, err := retryablehttp.NewRequest(http.MethodDelete, fmt.Sprintf("%s/scan?id=%s", c.baseURL, id), nil)
|
||||
httpReq, err := retryablehttp.NewRequest(http.MethodDelete, fmt.Sprintf("%s/scan?id=%d", c.baseURL, id), nil)
|
||||
if err != nil {
|
||||
return deletescan, errors.Wrap(err, "could not make request")
|
||||
}
|
||||
|
||||
@@ -14,5 +14,5 @@ func DisplayScanListInJson(output ListScanOutput) {
|
||||
}
|
||||
|
||||
func DisplayScanList(output ListScanOutput) {
|
||||
gologger.Silent().Msgf("%s [%s] [STATUS: %s] [MATCHED: %d] [TARGETS: %d] [TEMPLATES: %d] [DURATION: %s]\n", output.Timestamp, output.ScanID, strings.ToUpper(output.ScanStatus), output.ScanResult, output.Target, output.Template, output.ScanTime)
|
||||
gologger.Silent().Msgf("%s [%d] [STATUS: %s] [MATCHED: %d] [TARGETS: %d] [TEMPLATES: %d] [DURATION: %s]\n", output.Timestamp, output.ScanID, strings.ToUpper(output.ScanStatus), output.ScanResult, output.Target, output.Template, output.ScanTime)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ type GetResultsResponse struct {
|
||||
}
|
||||
|
||||
type GetScanRequest struct {
|
||||
Id string `json:"id"`
|
||||
Id int64 `json:"id"`
|
||||
Total int32 `json:"total"`
|
||||
Current int32 `json:"current"`
|
||||
Finished bool `json:"finished"`
|
||||
@@ -109,7 +109,7 @@ type AddItemResponse struct {
|
||||
|
||||
type ListScanOutput struct {
|
||||
Timestamp string `json:"timestamp"`
|
||||
ScanID string `json:"scan_id"`
|
||||
ScanID int64 `json:"scan_id"`
|
||||
ScanTime string `json:"scan_time"`
|
||||
ScanResult int `json:"scan_result"`
|
||||
ScanStatus string `json:"scan_status"`
|
||||
|
||||
@@ -418,10 +418,6 @@ func (r *Runner) RunEnumeration() error {
|
||||
if err := r.initializeCloudDataSources(); err != nil {
|
||||
return errors.Wrap(err, "could not init cloud data sources")
|
||||
}
|
||||
// Only update if asked
|
||||
if r.options.UpdateTemplates {
|
||||
return nil
|
||||
}
|
||||
|
||||
// hook template loading
|
||||
store.NotFoundCallback = func(template string) bool {
|
||||
|
||||
Reference in New Issue
Block a user