From 0f603e6501ee5c7d3ccb2076bf1014b4e927ff29 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 29 Jun 2014 16:44:16 -0500 Subject: [PATCH] Added http handler for phishing endpoint - Will add content soon Updated config.go to reflect the new changes --- config.json | 3 ++- config/config.go | 7 ++++--- controllers/route.go | 16 ++++++++++++++-- gophish.go | 12 ++++++------ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/config.json b/config.json index ca489a80..148dd219 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,6 @@ { - "url" : "localhost:3333", + "admin_url" : "127.0.0.1:3333", + "phish_url" : "0.0.0.0:80", "smtp" : { "host" : "smtp.example.com:25", "user" : "username", diff --git a/config/config.go b/config/config.go index a92e3a41..a9d11381 100644 --- a/config/config.go +++ b/config/config.go @@ -14,9 +14,10 @@ type SMTPServer struct { // Config represents the configuration information. type Config struct { - URL string `json:"url"` - SMTP SMTPServer `json:"smtp"` - DBPath string `json:"dbpath"` + AdminURL string `json:"admin_url"` + PhishURL string `json:"phish_url"` + SMTP SMTPServer `json:"smtp"` + DBPath string `json:"dbpath"` } var Conf Config diff --git a/controllers/route.go b/controllers/route.go index 7b8775ad..b5cac4cb 100644 --- a/controllers/route.go +++ b/controllers/route.go @@ -18,7 +18,7 @@ import ( var templateDelims = []string{"{{%", "%}}"} var Logger = log.New(os.Stdout, " ", log.Ldate|log.Ltime|log.Lshortfile) -func CreateRouter() *nosurf.CSRFHandler { +func CreateAdminRouter() http.Handler { router := mux.NewRouter() // Base Front-end routes router.HandleFunc("/login", Login) @@ -51,7 +51,19 @@ func CreateRouter() *nosurf.CSRFHandler { csrfHandler.ExemptGlob("/api/templates/*") csrfHandler.ExemptGlob("/api/import/*") csrfHandler.ExemptGlob("/static/*") - return csrfHandler + return Use(csrfHandler.ServeHTTP, mid.GetContext) +} + +//CreateEndpointRouter creates the router that handles phishing connections. +func CreatePhishingRouter() http.Handler { + router := mux.NewRouter() + router.PathPrefix("/static").Handler(http.FileServer(http.Dir("./static/endpoint/"))) + router.HandleFunc("/{path:.*}", PhishHandler) + return router +} + +func PhishHandler(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("It Works!")) } // Use allows us to stack middleware to process the request diff --git a/gophish.go b/gophish.go index 858e5cef..3e83147f 100644 --- a/gophish.go +++ b/gophish.go @@ -33,18 +33,18 @@ import ( "github.com/gorilla/handlers" "github.com/jordan-wright/gophish/config" "github.com/jordan-wright/gophish/controllers" - "github.com/jordan-wright/gophish/middleware" "github.com/jordan-wright/gophish/models" ) func main() { - //Setup the global variables and settings + // Setup the global variables and settings err := models.Setup() - //defer models.db.DB().Close() if err != nil { fmt.Println(err) } - fmt.Printf("Gophish server started at http://%s\n", config.Conf.URL) - http.Handle("/", handlers.CombinedLoggingHandler(os.Stdout, controllers.Use(controllers.CreateRouter().ServeHTTP, middleware.GetContext))) - http.ListenAndServe(config.Conf.URL, nil) + // Start the web servers + fmt.Printf("Admin server started at http://%s\n", config.Conf.AdminURL) + go http.ListenAndServe(config.Conf.AdminURL, handlers.CombinedLoggingHandler(os.Stdout, controllers.CreateAdminRouter())) + fmt.Printf("Phishing server started at http://%s\n", config.Conf.PhishURL) + http.ListenAndServe(config.Conf.PhishURL, handlers.CombinedLoggingHandler(os.Stdout, controllers.CreatePhishingRouter())) }