about summary refs log tree commit diff
path: root/src/main.go
blob: f64df593b92361831f8b6524b80e6d26a6a60137 (plain)
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
package main

import (
	"fmt"
	"log"
	"net/http"
	"strings"
)

func main() {
	// pase the command line aguments
	registerFlags()

	fmt.Printf(red("asd"))
	fmt.Printf(boldRed("asd"))
	fmt.Printf(green("asd"))
	fmt.Printf(boldGreen("asd"))
	fmt.Printf(yellow("asd"))
	fmt.Printf(boldYellow("asd"))
	fmt.Printf(blue("asd"))
	fmt.Printf(boldBlue("asd"))
	fmt.Printf(magenta("asd"))
	fmt.Printf(boldMagenta("asd"))
	fmt.Printf(cyan("asd"))
	fmt.Printf(boldCyan("asd") + "\n")

	// read the wordlist from a file
	log.Println("reading the wordlist from a file")
	wordlist, err := readWordlist(wordlist)
	if err != nil {
		log.Println(err)
	}
	log.Println(green("[+] ") + "done reading the wordlist from a file")

	// define a channel to store the wordlist in
	wordlistChannel := make(chan string)

	// define a channel in which the response gets written into from the go
	// routines
	printChannel := make(chan Response)

	// write all the words from the wordlist into the wordlistChannel
	go func() {
		for _, line := range wordlist {
			wordlistChannel <- line
		}
	}()

	fmt.Println(url)

	go func() {
		var i int
		for {
			// read a response from the printChannel for further usage
			response := <-printChannel

			// define a postfix: a string attached to the end of all printed
			// string set in the section filtering the status code cases
			var postfix string
			var prefix string

			// define what color should be used to print the individual status
			// codes
			var statusCode string
			switch response.StatusCode {
			case 200:
				prefix = "\r\033[K"
				statusCode = green(fmt.Sprintf("%d", response.StatusCode))
				postfix = "\n"
			case 404:
				statusCode = red(fmt.Sprintf("%d", response.StatusCode))
				postfix = "\033[K\r"
			}

			// print the foo
			fmt.Printf("%s%.7d:   %s    %s%s", prefix, i, statusCode, response.FuzzWord, postfix)
			i++
		}
	}()

	if threads > 1 {
		fmt.Println("threaded")
		httpRequest(wordlistChannel, printChannel)
	} else {

		// loop over all the threads starting a go routine fetching a word from
		// the wordlistChannel, making the request and inserting the result into
		// the printChannel
		for i := 0; i < threads; i++ {
			go httpRequest(wordlistChannel, printChannel)
		}
	}

}

func httpRequest(wordlistChannel chan string, printChannel chan Response) {
	for {
		// replace the first instance of "FUZZ" in the given url by the next
		// value from the wordlistChannel
		fuzzWord := <-wordlistChannel
		requestURL := strings.Replace(url, "FUZZ", fuzzWord, 1)

		// make the http get request
		resp, err := http.Get("https://" + requestURL)
		if err != nil {
			log.Println(err)
		}

		// define the response
		var response = Response{
			StatusCode: resp.StatusCode,
			FuzzWord:   fuzzWord,
		}

		// insert the response into the print channel for further printing
		printChannel <- response
	}
}