-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
177 lines (151 loc) · 4.94 KB
/
main.go
File metadata and controls
177 lines (151 loc) · 4.94 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
177
package main
import (
"context"
"flag"
"fmt"
"github.com/dsecuredcom/xssscan/internal/report"
"log"
"math/rand"
"os"
"os/signal"
"syscall"
"time"
"github.com/dsecuredcom/xssscan/internal/batcher"
"github.com/dsecuredcom/xssscan/internal/io"
"github.com/dsecuredcom/xssscan/internal/scanner"
"github.com/dsecuredcom/xssscan/internal/util"
)
type Config struct {
PathsFile string
ParametersFile string
Method string
Concurrency int
ParameterBatch int
Timeout time.Duration
Proxy string
Workers int
Insecure bool
Retries int
Verbose bool
}
func main() {
config := &Config{}
flag.StringVar(&config.PathsFile, "paths", "", "File with target URLs (one per line)")
flag.StringVar(&config.ParametersFile, "parameters", "", "File with parameter names (one per line)")
flag.StringVar(&config.Method, "method", "GET", "HTTP method (GET or POST)")
flag.IntVar(&config.Concurrency, "concurrency", 20, "Max requests per second")
flag.IntVar(&config.ParameterBatch, "parameter-batch", 5, "Number of parameters per request")
flag.DurationVar(&config.Timeout, "timeout", 15*time.Second, "Client timeout per request")
flag.StringVar(&config.Proxy, "proxy", "", "Optional upstream proxy")
flag.IntVar(&config.Workers, "workers", 0, "Number of workers (default: concurrency)")
flag.BoolVar(&config.Insecure, "insecure", false, "Ignore TLS certificate errors")
flag.IntVar(&config.Retries, "retries", 0, "Number of retries on failure")
flag.BoolVar(&config.Verbose, "verbose", false, "Show all requests and HTTP status codes")
flag.Parse()
if err := validateConfig(config); err != nil {
log.Fatalf("Configuration error: %v", err)
}
if config.Workers == 0 {
config.Workers = config.Concurrency
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Handle graceful shutdown
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigChan
fmt.Println("\n[!] Received interrupt signal, shutting down gracefully...")
cancel()
}()
if err := run(ctx, config); err != nil {
log.Fatalf("Scan failed: %v", err)
}
}
func validateConfig(config *Config) error {
if config.PathsFile == "" {
return fmt.Errorf("paths file is required")
}
if config.ParametersFile == "" {
return fmt.Errorf("parameters file is required")
}
if config.Method != "GET" && config.Method != "POST" {
return fmt.Errorf("method must be GET or POST")
}
if config.Concurrency <= 0 {
return fmt.Errorf("concurrency must be positive")
}
if config.ParameterBatch <= 0 {
return fmt.Errorf("parameter-batch must be positive")
}
return nil
}
func run(ctx context.Context, config *Config) error {
// Load input files
fmt.Print("[+] Loading input files...")
paths, err := io.LoadPaths(config.PathsFile)
if err != nil {
return fmt.Errorf("loading paths: %w", err)
}
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(paths), func(i, j int) {
paths[i], paths[j] = paths[j], paths[i]
})
parameters, err := io.LoadParameters(config.ParametersFile)
if err != nil {
return fmt.Errorf("loading parameters: %w", err)
}
fmt.Printf(" Done\n")
// Create parameter batches
batches := batcher.CreateBatches(parameters, config.ParameterBatch)
pathsCh := make(chan string, 128) // kleiner Puffer
go func() {
defer close(pathsCh)
for _, p := range paths {
select {
case pathsCh <- p: // weitergeben
case <-ctx.Done():
return // sauber beenden, falls Ctrl-C
}
}
}()
// Calculate total HTTP requests
totalHTTPRequests := len(paths) * len(batches) * 2
rep := report.New(totalHTTPRequests)
defer rep.Close()
fmt.Printf("[+] Loaded:\n")
fmt.Printf(" • %d paths\n", len(paths))
fmt.Printf(" • %d parameters\n", len(parameters))
fmt.Printf(" • %d chunks (parameters/chunk size: %d/%d)\n", len(batches), len(parameters), config.ParameterBatch)
fmt.Printf(" • %d HTTP requests total (%d paths × %d chunks × 2 variants)\n",
totalHTTPRequests, len(paths), len(batches))
// Initialize HTTP client
httpClient := util.NewHTTPClient(util.HTTPConfig{
Timeout: config.Timeout,
Proxy: config.Proxy,
Insecure: config.Insecure,
MaxConns: config.Workers,
})
// Create scanner configuration - NO REPORTER
scanConfig := scanner.Config{
Method: config.Method,
Concurrency: config.Concurrency,
Workers: config.Workers,
Retries: config.Retries,
HTTPClient: httpClient,
Verbose: config.Verbose,
Reporter: rep,
}
// Start scanning
fmt.Printf("[+] Starting %d RPS with %d workers...\n", config.Concurrency, config.Workers)
if config.Verbose {
fmt.Printf("[+] Verbose mode enabled - showing all requests\n")
}
fmt.Printf("[+] Reflections will be reported immediately as found:\n")
if err := scanner.Run(ctx, scanConfig, pathsCh, batches); err != nil {
return fmt.Errorf("scanning failed: %w", err)
}
// Simple completion message - no summary
fmt.Printf("\n[+] Scan completed.\n")
return nil
}