diff options
-rw-r--r-- | src/http.go | 58 |
1 files changed, 33 insertions, 25 deletions
diff --git a/src/http.go b/src/http.go index 12a8a6d..1caa14a 100644 --- a/src/http.go +++ b/src/http.go @@ -1,35 +1,43 @@ package main import ( + "fmt" "log" "net/http" - "strings" + + "github.com/gorilla/mux" ) -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 - } +// setupHTTPServer sets up a http server +func setupHTTPServer() http.Server { + r := mux.NewRouter() + + r.HandleFunc("/", indexHandler) + r.HandleFunc("/api/found", apiFoundHandler) - if doneChannel != nil { - doneChannel <- threadNr + return http.Server{ + Addr: fmt.Sprintf("0.0.0.0:%d", httpServerPort), + Handler: r, } } + +// indexHandler handles requests to the / endpoint +func indexHandler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "%s", "FUZZ!") +} + +// httpStartServer starts the http server +func httpStartServer() { + log.Printf("%s Starting the http server", green("[i]")) + + // setup the http server and start it + httpServer := setupHTTPServer() + log.Fatalln(httpServer.ListenAndServe()) + + log.Printf("%s Done starting the http server", boldGreen("[+]")) +} + +// handle requests to the /api/found endpoint +func apiFoundHandler() { + w.Header().Set("Content-Type", "application/json") +} |