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

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

func httpRequest(wordlistChannel chan string, printChannel chan Response, doneChannel chan int, threadNr int) {
	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
	}

	if doneChannel != nil {
		doneChannel <- threadNr
	}
}

func httpHandler(wordlistChannel chan string, printChannel chan Response, doneChannel chan int) {
	log.Printf("%s Starting the http handlers", green("[i]"))

	// handle one or more theads
	if threads <= 1 {
		log.Printf("%s 1 thread", yellow("[i]"))
		httpRequest(wordlistChannel, printChannel, nil, 0)
	} else {
		log.Printf("%s Starting %d threads...", yellow("[i]"), threads)

		// 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, doneChannel, i)
		}
		log.Printf("%s Done starting %d threads", green("[i]"), threads)

		for i := 0; i < threads; i++ {
			threadNum := <-doneChannel
			fmt.Printf("Thread %d done!\n", threadNum)
		}
	}

	log.Printf("%s Done starting the http handlers", boldGreen("[+]"))
}