-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
84 lines (69 loc) · 2.02 KB
/
main.go
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
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"strings"
"time"
"github.com/Lercas/SneakPeeker/report"
"github.com/Lercas/SneakPeeker/scanner"
)
var (
removeCanary = flag.Bool("f", false, "Remove canary tokens from files")
reportFile = flag.String("r", "report.json", "Report file name")
verbose = flag.Bool("v", false, "Enable verbose output")
dryRun = flag.Bool("dry-run", false, "Do not modify any files, just report")
ignoreDomains = flag.String("ignore", "", "Comma-separated list of domains to ignore")
workersNum = flag.Int("w", 5, "Number of workers for parallel scan")
)
func printBanner() {
banner := `
_____ _ _____ _
| __|___ ___ ___| |_| _ |___ ___| |_ ___ ___
|__ | | -_| .'| '_| __| -_| -_| '_| -_| _|
|_____|_|_|___|__,|_,_|__| |___|___|_,_|___|_|
By @belka_e
`
fmt.Println(banner)
}
func main() {
printBanner()
flag.Parse()
if len(flag.Args()) != 1 {
fmt.Println("Usage: go run main.go [options] FILE_OR_DIRECTORY_PATH")
flag.PrintDefaults()
return
}
scanner.InitLogger(*verbose)
path := flag.Args()[0]
var ignoredDomains []string
if *ignoreDomains != "" {
ignoredDomains = strings.Split(*ignoreDomains, ",")
for i, d := range ignoredDomains {
ignoredDomains[i] = strings.TrimSpace(d)
}
}
start := time.Now()
reports, summary, err := scanner.ScanPath(path, ignoredDomains, *removeCanary, *dryRun, *verbose, *workersNum)
if err != nil {
scanner.Logger.Errorf("Error scanning path: %v", err)
return
}
finalReport := report.FinalReport{
Reports: reports,
Summary: summary,
}
reportData, err := json.MarshalIndent(finalReport, "", " ")
if err != nil {
scanner.Logger.Errorf("Error marshalling report data: %v", err)
return
}
err = os.WriteFile(*reportFile, reportData, 0644)
if err != nil {
scanner.Logger.Errorf("Error writing report file: %v", err)
} else {
scanner.Logger.Infof("Report written to %s", *reportFile)
}
scanner.Logger.Infof("Scanning completed in %s", time.Since(start))
}