Add SMTP Honeypot
This commit is contained in:
		| @@ -15,6 +15,7 @@ import ( | ||||
| 	"github.uio.no/torjus/apiary" | ||||
| 	"github.uio.no/torjus/apiary/config" | ||||
| 	"github.uio.no/torjus/apiary/honeypot/ports" | ||||
| 	"github.uio.no/torjus/apiary/honeypot/smtp" | ||||
| 	"github.uio.no/torjus/apiary/honeypot/ssh" | ||||
| 	"github.uio.no/torjus/apiary/honeypot/ssh/store" | ||||
| 	"github.uio.no/torjus/apiary/web" | ||||
| @@ -144,6 +145,39 @@ func ActionServe(c *cli.Context) error { | ||||
| 		}() | ||||
| 	} | ||||
|  | ||||
| 	// Setup smtp honeypot if enabled | ||||
| 	if cfg.SMTP.Enable { | ||||
| 		honeypot, err := smtp.NewSMTPHoneypot() | ||||
| 		if err != nil { | ||||
| 			loggers.rootLogger.Warnw("Error seting up SMTP honeypot", "error", err) | ||||
| 		} | ||||
| 		honeypot.Addr = cfg.SMTP.Addr | ||||
| 		honeypot.Logger = loggers.smtpLogger | ||||
| 		if cfg.SMTP.EnableMetrics { | ||||
| 			honeypot.Store = smtp.NewMetricsStore(&smtp.DiscardStore{}) | ||||
| 		} else { | ||||
| 			honeypot.Store = &smtp.DiscardStore{} | ||||
| 		} | ||||
|  | ||||
| 		// Start smtp honeypot | ||||
| 		go func() { | ||||
| 			loggers.rootLogger.Info("Starting SMTP server") | ||||
| 			if err := honeypot.ListenAndServe(); err != nil { | ||||
| 				loggers.rootLogger.Warnw("SMTP server returned error", "error", err) | ||||
| 			} | ||||
| 		}() | ||||
|  | ||||
| 		// Wait for smtp shutdown | ||||
| 		go func() { | ||||
| 			<-serversCtx.Done() | ||||
| 			loggers.rootLogger.Info("SMTP server shutdown started") | ||||
| 			if err := honeypot.Shutdown(); err != nil { | ||||
| 				loggers.rootLogger.Errorw("Error shutting down SMTP server", "error", err) | ||||
| 			} | ||||
| 			loggers.rootLogger.Info("SMTP server shutdown complete") | ||||
| 		}() | ||||
| 	} | ||||
|  | ||||
| 	// Handle interrupt | ||||
| 	go func() { | ||||
| 		<-interruptChan | ||||
| @@ -250,6 +284,7 @@ type loggerCollection struct { | ||||
| 	webAccessLogger *zap.SugaredLogger | ||||
| 	webServerLogger *zap.SugaredLogger | ||||
| 	portsLogger     *zap.SugaredLogger | ||||
| 	smtpLogger      *zap.SugaredLogger | ||||
| } | ||||
|  | ||||
| func setupLoggers(cfg config.Config) *loggerCollection { | ||||
| @@ -290,6 +325,7 @@ func setupLoggers(cfg config.Config) *loggerCollection { | ||||
| 		webAccessLogger: rootLogger.Named("ACC").Sugar(), | ||||
| 		webServerLogger: rootLogger.Named("WEB").Sugar(), | ||||
| 		portsLogger:     rootLogger.Named("PRT").Sugar(), | ||||
| 		smtpLogger:      rootLogger.Named("SMT").Sugar(), | ||||
| 	} | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user