-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscanner.go
More file actions
75 lines (62 loc) · 1.88 KB
/
scanner.go
File metadata and controls
75 lines (62 loc) · 1.88 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
package main
import (
"bufio"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"sync"
)
var wg sync.WaitGroup
// This function will make request to the target URL with provided options
func makeRequest(preparedURL string, word string, showSuccessful bool) {
// Scanning for GET Method
req, errReq := http.NewRequest(http.MethodGet, preparedURL, nil)
if errReq != nil {
PrintLog("request error", "There was an error while making request to this URL: "+preparedURL+"\nERROR: "+errReq.Error())
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
PrintLog("respose error", "There was an error encounted while making GET request to this URL: "+preparedURL+"\nERROR: "+err.Error())
} else {
if resp.StatusCode != 200 && showSuccessful {
return
}
PrintLog(strconv.Itoa(resp.StatusCode), "[Method: GET] "+preparedURL)
}
// TODO: Scanning for POST Method
// resp, err = http.Post(requestURL, "json")
// if err != nil {
// PrintLog("response error", )
// }
}
func Scanner(targetURL string, showSuccessful bool, wordlistFile *os.File, secure bool) {
_, err := url.Parse(targetURL)
if err != nil {
PrintLog("error", "The provided target URL is not valid!")
os.Exit(1)
}
if wordlistFile == nil {
PrintLog("error", "The provided wordlist file is nil!")
return
}
scanner := bufio.NewScanner(wordlistFile)
for scanner.Scan() {
line := scanner.Text()
wg.Add(1)
throwProtocol := func() string {
if secure {
return "https://"
} else {
return "http://"
}
}()
requestURL := throwProtocol + strings.Replace(targetURL, "FUZZTHIS", line, -1)
go func(url string, word string, showSuccessful bool) {
defer wg.Done() // Decrement the WaitGroup counter when the goroutine completes
makeRequest(url, word, showSuccessful)
}(requestURL, line, showSuccessful)
}
wg.Wait()
}