2022-10-29 07:51:43 +05:30
|
|
|
package nucleicloud
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
2022-12-21 22:48:43 +05:30
|
|
|
"time"
|
2022-10-29 07:51:43 +05:30
|
|
|
|
2023-10-17 17:44:13 +05:30
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/catalog/config"
|
2022-10-29 07:51:43 +05:30
|
|
|
)
|
|
|
|
|
|
2022-12-21 22:48:43 +05:30
|
|
|
const DDMMYYYYhhmmss = "2006-01-02 15:04:05"
|
|
|
|
|
|
2022-10-29 07:51:43 +05:30
|
|
|
// ReadCatalogChecksum reads catalog checksum from nuclei-templates repository
|
|
|
|
|
func ReadCatalogChecksum() map[string]string {
|
2023-04-19 21:58:48 +05:30
|
|
|
config := config.DefaultConfig
|
2022-10-29 07:51:43 +05:30
|
|
|
|
|
|
|
|
checksumFile := filepath.Join(config.TemplatesDirectory, "templates-checksum.txt")
|
|
|
|
|
file, err := os.Open(checksumFile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
|
|
checksums := make(map[string]string)
|
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
|
for scanner.Scan() {
|
|
|
|
|
text := strings.SplitN(scanner.Text(), ":", 2)
|
|
|
|
|
if len(text) < 2 {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2022-12-07 22:28:45 +05:30
|
|
|
path := strings.TrimPrefix(text[0], "nuclei-templates/")
|
|
|
|
|
if strings.HasPrefix(path, ".") {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
checksums[path] = text[1]
|
2022-10-29 07:51:43 +05:30
|
|
|
}
|
|
|
|
|
return checksums
|
|
|
|
|
}
|
2022-12-21 22:48:43 +05:30
|
|
|
|
|
|
|
|
func PrepareScanListOutput(v GetScanRequest) ListScanOutput {
|
|
|
|
|
output := ListScanOutput{}
|
|
|
|
|
loc, _ := time.LoadLocation("Local")
|
|
|
|
|
status := "finished"
|
|
|
|
|
|
|
|
|
|
t := v.FinishedAt
|
|
|
|
|
duration := t.Sub(v.CreatedAt)
|
|
|
|
|
|
|
|
|
|
if !v.Finished {
|
|
|
|
|
status = "running"
|
|
|
|
|
t = time.Now().UTC()
|
|
|
|
|
duration = t.Sub(v.CreatedAt).Round(60 * time.Second)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val := v.CreatedAt.In(loc).Format(DDMMYYYYhhmmss)
|
|
|
|
|
|
|
|
|
|
output.Timestamp = val
|
|
|
|
|
output.ScanID = v.Id
|
|
|
|
|
output.ScanTime = duration.String()
|
|
|
|
|
output.ScanResult = int(v.Matches)
|
|
|
|
|
output.ScanStatus = status
|
|
|
|
|
output.Target = int(v.Targets)
|
|
|
|
|
output.Template = int(v.Templates)
|
|
|
|
|
return output
|
|
|
|
|
}
|