-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
176 lines (157 loc) · 5.04 KB
/
Copy pathmain.go
File metadata and controls
176 lines (157 loc) · 5.04 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package main
import (
"bufio"
"flag"
"fmt"
"os"
"strings"
"time"
)
var version = "3.0.0"
func main() {
// Flags — short and long forms
urlFlag := flag.String("u", "", "Single JS URL to scan")
listFlag := flag.String("l", "", "File containing list of JS URLs")
outputFlag := flag.String("o", "", "Output file (plain text, colors stripped)")
regexFlag := flag.String("r", "", "Custom regex pattern")
headersFlag := flag.String("headers", "", "Custom headers: 'Key1:Val1,Key2:Val2'")
baseFlag := flag.String("base", "", "Base URL to resolve relative endpoints")
proxyFlag := flag.String("proxy", "", "HTTP proxy (e.g., http://127.0.0.1:8080)")
concFlag := flag.Int("c", 10, "Max concurrent requests")
timeoutFlag := flag.Int("t", 15, "HTTP timeout in seconds")
retriesFlag := flag.Int("retries", 2, "Number of retries on failure")
jsonFlag := flag.Bool("json", false, "Output as JSON")
contextFlag := flag.Bool("ctx", false, "Show surrounding code context for matches")
verboseFlag := flag.Bool("v", false, "Verbose: show errors and retries")
noColorArg := flag.Bool("nocolor", false, "Disable colored output")
sevFlag := flag.String("severity", "info", "Minimum severity to show: critical, high, medium, low, info")
versionFlag := flag.Bool("version", false, "Print version and exit")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "%s\n", color("jsfuzzer v"+version+" — JS Analysis for Bug Bounty", Bold+Cyan))
fmt.Fprintf(os.Stderr, "%s\n\n", color("Extracts secrets, sinks, sources, endpoints, subdomains from JS files", Dim))
fmt.Fprintf(os.Stderr, "Usage:\n")
fmt.Fprintf(os.Stderr, " jsfuzzer -u <url> Scan single JS URL\n")
fmt.Fprintf(os.Stderr, " jsfuzzer -l <file> Scan list of JS URLs\n")
fmt.Fprintf(os.Stderr, " cat urls.txt | jsfuzzer Scan from stdin\n")
fmt.Fprintf(os.Stderr, "\nFlags:\n")
flag.PrintDefaults()
}
flag.Parse()
if *versionFlag {
fmt.Println("jsfuzzer v" + version)
os.Exit(0)
}
// Set global color state
noColor = *noColorArg
// Set log writer for verbose output
logWriter = os.Stderr
// Parse minimum severity
minSev := parseSeverity(*sevFlag)
// Collect URLs
var urls []string
if *urlFlag != "" {
urls = append(urls, *urlFlag)
} else if *listFlag != "" {
file, err := os.Open(*listFlag)
if err != nil {
fmt.Fprintf(os.Stderr, "%s %v\n", color("[ERR]", Red), err)
os.Exit(1)
}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
if u := strings.TrimSpace(scanner.Text()); u != "" && !strings.HasPrefix(u, "#") {
urls = append(urls, u)
}
}
file.Close()
} else {
stat, _ := os.Stdin.Stat()
if (stat.Mode() & os.ModeCharDevice) == 0 {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
if u := strings.TrimSpace(scanner.Text()); u != "" && !strings.HasPrefix(u, "#") {
urls = append(urls, u)
}
}
}
}
if len(urls) == 0 {
fmt.Fprintf(os.Stderr, "%s No URLs provided. Use -u, -l, or pipe via stdin.\n", color("[ERR]", Red))
flag.Usage()
os.Exit(1)
}
// Build fetch config
cfg := FetchConfig{
Headers: ParseHeaders(*headersFlag),
Proxy: *proxyFlag,
Timeout: time.Duration(*timeoutFlag) * time.Second,
Retries: *retriesFlag,
Concurrency: *concFlag,
Verbose: *verboseFlag,
UserAgent: "Mozilla/5.0 (compatible; jsfuzzer/" + version + ")",
}
if !*jsonFlag {
fmt.Fprintf(os.Stderr, "%s Scanning %s URL(s) [concurrency=%d, timeout=%ds]\n",
color("[*]", Bold+Blue), color(fmt.Sprintf("%d", len(urls)), Bold+White), *concFlag, *timeoutFlag)
if *proxyFlag != "" {
fmt.Fprintf(os.Stderr, "%s Proxy: %s\n", color("[*]", Bold+Blue), *proxyFlag)
}
}
// Run scans
results := RunScans(urls, cfg, *baseFlag, *regexFlag, *contextFlag)
// Collect and output results
var allResults []ScanResult
var fileBuffer strings.Builder
for r := range results {
allResults = append(allResults, r)
if !*jsonFlag {
formatted := FormatPretty(r, *contextFlag, minSev)
fmt.Print(formatted)
if *outputFlag != "" {
fileBuffer.WriteString(StripANSI(formatted))
}
}
}
// JSON output
if *jsonFlag {
jsonStr, err := FormatJSON(allResults)
if err != nil {
fmt.Fprintf(os.Stderr, "%s JSON error: %v\n", color("[ERR]", Red), err)
os.Exit(1)
}
fmt.Println(jsonStr)
if *outputFlag != "" {
fileBuffer.WriteString(jsonStr)
}
} else {
// Print summary
summary := FormatSummary(allResults)
fmt.Print(summary)
if *outputFlag != "" {
fileBuffer.WriteString(StripANSI(summary))
}
}
// Write to file
if *outputFlag != "" {
err := os.WriteFile(*outputFlag, []byte(fileBuffer.String()), 0644)
if err != nil {
fmt.Fprintf(os.Stderr, "%s writing file: %v\n", color("[ERR]", Red), err)
} else if !*jsonFlag {
fmt.Fprintf(os.Stderr, "%s Results saved to %s\n", color("[+]", Green), *outputFlag)
}
}
}
func parseSeverity(s string) Severity {
switch strings.ToLower(strings.TrimSpace(s)) {
case "critical":
return SevCritical
case "high":
return SevHigh
case "medium", "med":
return SevMedium
case "low":
return SevLow
default:
return SevInfo
}
}