From 319ac3d30db83acdb1d46bfab042ee468e7b29b0 Mon Sep 17 00:00:00 2001 From: Emile Date: Sat, 2 Nov 2019 21:10:41 +0100 Subject: http server --- src/http.go | 58 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 25 deletions(-) (limited to 'src/http.go') 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") +} -- cgit 1.4.1