github.com/amar224/phishing-tool@v0.9.0/gophish.go (about) 1 package main 2 3 /* 4 gophish - Open-Source Phishing Framework 5 6 The MIT License (MIT) 7 8 Copyright (c) 2013 Jordan Wright 9 10 Permission is hereby granted, free of charge, to any person obtaining a copy 11 of this software and associated documentation files (the "Software"), to deal 12 in the Software without restriction, including without limitation the rights 13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 copies of the Software, and to permit persons to whom the Software is 15 furnished to do so, subject to the following conditions: 16 17 The above copyright notice and this permission notice shall be included in 18 all copies or substantial portions of the Software. 19 20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 26 THE SOFTWARE. 27 */ 28 import ( 29 "io/ioutil" 30 "os" 31 "os/signal" 32 33 "gopkg.in/alecthomas/kingpin.v2" 34 35 "github.com/gophish/gophish/config" 36 "github.com/gophish/gophish/controllers" 37 "github.com/gophish/gophish/imap" 38 log "github.com/gophish/gophish/logger" 39 "github.com/gophish/gophish/middleware" 40 "github.com/gophish/gophish/models" 41 ) 42 43 var ( 44 configPath = kingpin.Flag("config", "Location of config.json.").Default("./config.json").String() 45 disableMailer = kingpin.Flag("disable-mailer", "Disable the mailer (for use with multi-system deployments)").Bool() 46 ) 47 48 func main() { 49 // Load the version 50 51 version, err := ioutil.ReadFile("./VERSION") 52 if err != nil { 53 log.Fatal(err) 54 } 55 kingpin.Version(string(version)) 56 57 // Parse the CLI flags and load the config 58 kingpin.CommandLine.HelpFlag.Short('h') 59 kingpin.Parse() 60 61 // Load the config 62 conf, err := config.LoadConfig(*configPath) 63 // Just warn if a contact address hasn't been configured 64 if err != nil { 65 log.Fatal(err) 66 } 67 if conf.ContactAddress == "" { 68 log.Warnf("No contact address has been configured.") 69 log.Warnf("Please consider adding a contact_address entry in your config.json") 70 } 71 config.Version = string(version) 72 73 err = log.Setup(conf.Logging) 74 if err != nil { 75 log.Fatal(err) 76 } 77 78 // Provide the option to disable the built-in mailer 79 // Setup the global variables and settings 80 err = models.Setup(conf) 81 if err != nil { 82 log.Fatal(err) 83 } 84 85 // Unlock any maillogs that may have been locked for processing 86 // when Gophish was last shutdown. 87 err = models.UnlockAllMailLogs() 88 if err != nil { 89 log.Fatal(err) 90 } 91 92 // Create our servers 93 adminOptions := []controllers.AdminServerOption{} 94 if *disableMailer { 95 adminOptions = append(adminOptions, controllers.WithWorker(nil)) 96 } 97 adminConfig := conf.AdminConf 98 adminServer := controllers.NewAdminServer(adminConfig, adminOptions...) 99 middleware.Store.Options.Secure = adminConfig.UseTLS 100 101 phishConfig := conf.PhishConf 102 phishServer := controllers.NewPhishingServer(phishConfig) 103 104 imapMonitor := imap.NewMonitor() 105 106 go adminServer.Start() 107 go phishServer.Start() 108 go imapMonitor.Start() 109 110 // Handle graceful shutdown 111 c := make(chan os.Signal, 1) 112 signal.Notify(c, os.Interrupt) 113 <-c 114 log.Info("CTRL+C Received... Gracefully shutting down servers") 115 adminServer.Shutdown() 116 phishServer.Shutdown() 117 imapMonitor.Shutdown() 118 119 }