-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
73 lines (63 loc) · 1.58 KB
/
main.go
File metadata and controls
73 lines (63 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"encoding/json"
"fmt"
"os"
"path"
"regexp"
"strconv"
log "github.com/sirupsen/logrus"
flag "github.com/spf13/pflag"
"github.com/surface-security/scanner-go-entrypoint/scanner"
)
type MinimalResult struct {
Host string `json:"host"`
TemplateId string `json:"template-id"`
}
var FILENAME_RE = regexp.MustCompile(`[^\w\d-\._]`)
func main() {
s := scanner.Scanner{Name: "nuclei"}
options := s.BuildOptions()
concurrency := flag.IntP("concurrency", "c", 10, "Number of processes")
tests := flag.StringSliceP("tests", "t", nil, "tests to perform (as nuclei supports)")
debug := flag.BoolP("debug", "d", false, "print nuclei output instead of suppressing it")
scanner.ParseOptions(options)
if *debug {
log.SetLevel(log.DebugLevel)
}
err := os.MkdirAll(options.Output, 0755)
if err != nil {
log.Fatalf("%v", err)
}
args := []string{
"-c", strconv.Itoa(*concurrency),
"-jsonl",
"-l", options.Input,
}
if !*debug {
args = append(args, "-silent")
}
for _, test := range *tests {
args = append(args, "-t", test)
}
err = s.ExecCaptureOutput(
func(line string) {
if *debug {
log.Debugln(line)
}
var res MinimalResult
err := json.Unmarshal([]byte(line), &res)
if err != nil {
log.Errorf("error parsing: %s", line)
return
}
log.Infof("[+] Found %s", res.Host)
filename := FILENAME_RE.ReplaceAllString(fmt.Sprintf("%s-%s.json", res.Host, res.TemplateId), "_")
os.WriteFile(path.Join(options.Output, filename), []byte(line), 0666)
},
args...,
)
if err != nil {
log.Fatalf("Failed to run scanner: %v", err)
}
}