@@ -15,23 +15,23 @@ import (
15
15
)
16
16
17
17
type Options struct {
18
- TlsEnabled bool
19
- Regex string
20
- InvalidCode []string
18
+ Concurrents int
19
+ TlsEnabled bool
20
+ Regex , Domain , RequestFile , WordlistFile string
21
+ InvalidCode , Encoders []string
21
22
}
22
23
23
24
type Pool struct {
24
- concurrents int
25
- wordlists , flags []string
26
- deflenght int
27
- req * template.Template
28
- Options Options
25
+ wordlists []string
26
+ default_length int
27
+ req * template.Template
28
+ options Options
29
29
}
30
30
31
- func NewPool (wordlist , reqfile string , concurrents int ) (* Pool , error ) {
31
+ func NewPool (options Options ) (* Pool , error ) {
32
32
var pool Pool
33
- pool .concurrents = concurrents
34
- file , err := os .Open (wordlist )
33
+ pool .options = options
34
+ file , err := os .Open (options . WordlistFile )
35
35
if err != nil {
36
36
return nil , err
37
37
}
@@ -40,34 +40,33 @@ func NewPool(wordlist, reqfile string, concurrents int) (*Pool, error) {
40
40
for reader .Scan () {
41
41
pool .wordlists = append (pool .wordlists , reader .Text ())
42
42
}
43
- pool .req , err = template .ParseFiles (reqfile )
44
- pool .deflenght = formatter .CountDefaultContentLenght ( reqfile )
43
+ pool .req , err = template .ParseFiles (options . RequestFile )
44
+ pool .default_length = formatter .CountDefaultContentLength ( options . RequestFile )
45
45
if err != nil {
46
46
return nil , err
47
47
}
48
48
return & pool , nil
49
49
}
50
50
51
- func (p * Pool ) AddFlags (flags []string ) {
52
- p .flags = flags
53
- }
54
-
55
- func (p * Pool ) worker (wg * sync.WaitGroup , wordlist []string , domain string ) {
51
+ func (p * Pool ) worker (wg * sync.WaitGroup , chunked_wordlist []string ) {
56
52
defer wg .Done ()
57
- re := regexp .MustCompile (p .Options .Regex )
58
- for _ , value := range wordlist {
53
+ re := regexp .MustCompile (p .options .Regex )
54
+ for _ , value := range chunked_wordlist {
59
55
var buf bytes.Buffer
60
- payload := formatter .NewPayload (value , p .flags )
61
- payload .AddDefaultContentLenght ( p . deflenght )
56
+ payload := formatter .NewPayload (value , p .options . Encoders )
57
+ payload .DefaultContentLength = p . default_length
62
58
payload .CreatePayload ()
63
59
p .req .Execute (& buf , payload )
64
- worker := reqgen .NewWorker (p .Options .TlsEnabled , bufio .NewReader (& buf ), domain )
60
+ worker := reqgen .NewWorker (p .options .TlsEnabled , bufio .NewReader (& buf ), p . options . Domain )
65
61
resp , err := worker .MakeRequest ()
62
+
63
+ // Io.WriteString is necessary because it immediately writes to stdout
64
+ // with fmt.Println there are problems and it may not output all
66
65
io .WriteString (os .Stdout , buf .String ())
67
66
if err != nil {
68
67
io .WriteString (os .Stdout , err .Error ())
69
68
return
70
- } else if ! slices .Contains (p .Options .InvalidCode , fmt .Sprint (resp .Status )) && re .MatchString (resp .BodyData ) {
69
+ } else if ! slices .Contains (p .options .InvalidCode , fmt .Sprint (resp .Status )) && re .MatchString (resp .BodyData ) {
71
70
var formatted_code string
72
71
if resp .Status >= 200 && resp .Status < 300 {
73
72
formatted_code = fmt .Sprintf ("\033 [92m%d\033 [0m" , resp .Status )
@@ -81,18 +80,18 @@ func (p *Pool) worker(wg *sync.WaitGroup, wordlist []string, domain string) {
81
80
}
82
81
}
83
82
84
- func (p * Pool ) Fuzz (domain string ) {
83
+ func (p * Pool ) Fuzz () {
85
84
var wg sync.WaitGroup
86
- chunks := len (p .wordlists ) / p .concurrents
87
- for i := 0 ; i < p .concurrents ; i ++ {
85
+ chunks := len (p .wordlists ) / p .options . Concurrents
86
+ for i := 0 ; i < p .options . Concurrents ; i ++ {
88
87
var chunked_wordlist []string
89
- if i != p .concurrents - 1 {
88
+ if i != p .options . Concurrents - 1 {
90
89
chunked_wordlist = p .wordlists [i * chunks : (i + 1 )* chunks ]
91
90
} else {
92
91
chunked_wordlist = p .wordlists [i * chunks :]
93
92
}
94
93
wg .Add (1 )
95
- go p .worker (& wg , chunked_wordlist , domain )
94
+ go p .worker (& wg , chunked_wordlist )
96
95
}
97
96
wg .Wait ()
98
97
}
0 commit comments