🎣 Open-Source Phishing Toolkit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
4.2 KiB

  1. package main
  2. /*
  3. gophish - Open-Source Phishing Framework
  4. The MIT License (MIT)
  5. Copyright (c) 2013 Jordan Wright
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. THE SOFTWARE.
  21. */
  22. import (
  23. "fmt"
  24. "io/ioutil"
  25. "net/http"
  26. "os"
  27. "os/signal"
  28. "gopkg.in/alecthomas/kingpin.v2"
  29. "github.com/gophish/gophish/config"
  30. "github.com/gophish/gophish/controllers"
  31. "github.com/gophish/gophish/dialer"
  32. "github.com/gophish/gophish/imap"
  33. log "github.com/gophish/gophish/logger"
  34. "github.com/gophish/gophish/middleware"
  35. "github.com/gophish/gophish/models"
  36. "github.com/gophish/gophish/webhook"
  37. )
  38. const (
  39. modeAll string = "all"
  40. modeAdmin string = "admin"
  41. modePhish string = "phish"
  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. mode = kingpin.Flag("mode", fmt.Sprintf("Run the binary in one of the modes (%s, %s or %s)", modeAll, modeAdmin, modePhish)).
  47. Default("all").Enum(modeAll, modeAdmin, modePhish)
  48. )
  49. func main() {
  50. // Load the version
  51. version, err := ioutil.ReadFile("./VERSION")
  52. if err != nil {
  53. log.Fatal(err)
  54. }
  55. kingpin.Version(string(version))
  56. // Parse the CLI flags and load the config
  57. kingpin.CommandLine.HelpFlag.Short('h')
  58. kingpin.Parse()
  59. // Load the config
  60. conf, err := config.LoadConfig(*configPath)
  61. // Just warn if a contact address hasn't been configured
  62. if err != nil {
  63. log.Fatal(err)
  64. }
  65. if conf.ContactAddress == "" {
  66. log.Warnf("No contact address has been configured.")
  67. log.Warnf("Please consider adding a contact_address entry in your config.json")
  68. }
  69. config.Version = string(version)
  70. // Configure our various upstream clients to make sure that we restrict
  71. // outbound connections as needed.
  72. dialer.SetAllowedHosts(conf.AdminConf.AllowedInternalHosts)
  73. webhook.SetTransport(&http.Transport{
  74. DialContext: dialer.Dialer().DialContext,
  75. })
  76. err = log.Setup(conf.Logging)
  77. if err != nil {
  78. log.Fatal(err)
  79. }
  80. // Provide the option to disable the built-in mailer
  81. // Setup the global variables and settings
  82. err = models.Setup(conf)
  83. if err != nil {
  84. log.Fatal(err)
  85. }
  86. // Unlock any maillogs that may have been locked for processing
  87. // when Gophish was last shutdown.
  88. err = models.UnlockAllMailLogs()
  89. if err != nil {
  90. log.Fatal(err)
  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. phishConfig := conf.PhishConf
  101. phishServer := controllers.NewPhishingServer(phishConfig)
  102. imapMonitor := imap.NewMonitor()
  103. if *mode == "admin" || *mode == "all" {
  104. go adminServer.Start()
  105. go imapMonitor.Start()
  106. }
  107. if *mode == "phish" || *mode == "all" {
  108. go phishServer.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. if *mode == modeAdmin || *mode == modeAll {
  116. adminServer.Shutdown()
  117. imapMonitor.Shutdown()
  118. }
  119. if *mode == modePhish || *mode == modeAll {
  120. phishServer.Shutdown()
  121. }
  122. }