package main import ( "fmt" "io/ioutil" "log" "net/http" "strings" ) func httpRequest(channels channels, threadNr int) { for { // replace the first instance of "FUZZ" in the given url by the next // value from the wordlistChannel fuzzWord := <-channels.wordlistChannel requestURL := strings.Replace(url, "FUZZ", fuzzWord, 1) // make the http get request resp, err := http.Get(requestURL) if err != nil { log.Println(err) } else { defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Println(err) } responseLines := len(strings.Split(string(body), "\n")) - 1 responseWords := len(strings.Split(string(body), " ")) responseChars := len(string(body)) // define the response var response = Response{ StatusCode: resp.StatusCode, ResponseLines: responseLines, ResponseWords: responseWords, ResponseChars: responseChars, FuzzWord: fuzzWord, } // insert the response into the print channel for further printing channels.printChannel <- response } } if channels.doneChannel != nil { channels.doneChannel <- threadNr } } func httpHandler(channels channels) { 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(channels, 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(channels, i) } log.Printf("%s Done starting %d threads", green("[i]"), threads) for i := 0; i < threads; i++ { threadNum := <-channels.doneChannel fmt.Printf("Thread %d done!\n", threadNum) } } log.Printf("%s Done starting the http handlers", boldGreen("[+]")) }