-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
99 lines (79 loc) · 3.06 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
//"flag"
"github.com/boltdb/bolt"
"github.com/sec51/goconf"
"github.com/sec51/honeymail/api"
"github.com/sec51/honeymail/envelope"
"github.com/sec51/honeymail/geoip"
logmail "github.com/sec51/honeymail/logging"
"github.com/sec51/honeymail/models"
"github.com/sec51/honeymail/processing"
"github.com/sec51/honeymail/processor"
"github.com/sec51/honeymail/smtpd"
"github.com/sec51/honeymail/storage"
"log"
)
func main() {
// define configurations
dbPath := goconf.AppConf.DefaultString("maxmind.db.path", "GeoLite2-City.mmdb")
ip := goconf.AppConf.DefaultString("smtp.listen_to", "0.0.0.0")
serverName := goconf.AppConf.DefaultString("smtp.server_name", "localhost")
smtpPort := goconf.AppConf.DefaultString("smtp.port", "10025")
smtpSecurePort := goconf.AppConf.DefaultString("smtp.secure_port", "10026")
certificate := goconf.AppConf.DefaultString("smtp.tls.public_key", "")
privateKey := goconf.AppConf.DefaultString("smtp.tls.private_key", "")
apiHost := goconf.AppConf.DefaultString("http.listen_to", "0.0.0.0")
apiPort := goconf.AppConf.DefaultString("http.port", "8080")
// ===========================
// DB STORAGE for emails
db, err := bolt.Open("mail.db", 0600, nil)
if err != nil {
log.Fatal(err)
}
defer db.Close()
// GeoIP Resolution
err = geoip.InitGeoDb(dbPath)
if err != nil {
log.Fatal(err)
}
defer geoip.Resolver().Close()
// ==========================================
// channel for processing the envelopes
envelopeChannel := make(chan envelope.Envelope)
// channel for storing the envelopes
storageChannel := make(chan envelope.Envelope)
// channel for sending the emails to the honeymaster
emailChan := make(chan models.Email)
// channel for sending the bruteforce attacksd to the honeymaster
bruteChan := make(chan models.BruteforceAttack)
// ============================
// Honeymaster processing service
honeymasterService := processing.NewProcessingService(bruteChan, emailChan)
honeymasterService.Start()
// ============================
// Storage service
storageService := storage.NewStorageService(db, storageChannel)
storageService.Start()
// ============================
// Processing service - caluclates the stats and extract additional info from each envelope
// the passes it onto the storage channel for storing the results
processorService := processor.NewProcessorService(envelopeChannel, storageChannel, emailChan)
processorService.Start()
// DEBUG ONLY
if todayEmails, err := storageService.ViewTodayEnvelopes(); err == nil {
for _, envelope := range todayEmails {
logmail.Info.Printf("Id: %s => From: %s => To: %s\n%s", envelope.Id, envelope.From.String(), envelope.To.String(), envelope.Message)
}
}
// ============================
withTLS := certificate != "" && privateKey != ""
smtpServer, err := smtpd.NewTCPServer(ip, smtpPort, smtpSecurePort, serverName, certificate, privateKey, withTLS, envelopeChannel, bruteChan)
if err != nil {
log.Fatal(err)
}
smtpServer.Start()
// API
apiService := api.NewAPIService(apiHost, apiPort, storageService)
apiService.Start()
}