Add ports listener feature

This commit is contained in:
2021-10-21 10:33:28 +02:00
parent 94e7faae78
commit bc9c5dbe0e
8 changed files with 286 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ import (
"github.com/urfave/cli/v2"
"github.uio.no/torjus/apiary"
"github.uio.no/torjus/apiary/config"
"github.uio.no/torjus/apiary/honeypot/ports"
"github.uio.no/torjus/apiary/honeypot/ssh"
"github.uio.no/torjus/apiary/honeypot/ssh/store"
"github.uio.no/torjus/apiary/web"
@@ -113,6 +114,25 @@ func ActionServe(c *cli.Context) error {
rootCtx, rootCancel := context.WithCancel(c.Context)
serversCtx, serversCancel := context.WithCancel(rootCtx)
// Setup portlistener, if configured
if cfg.Ports.Enable {
portsCtx, cancel := context.WithCancel(rootCtx)
defer cancel()
// TODO: Add more stores
store := &ports.MemoryStore{}
portsServer := ports.New(store)
portsServer.Logger = loggers.portsLogger
for _, port := range cfg.Ports.TCPPorts {
portsServer.AddTCPPort(port)
}
go func() {
loggers.rootLogger.Info("Starting ports server")
portsServer.Start(portsCtx)
}()
}
// Handle interrupt
go func() {
<-interruptChan
@@ -171,6 +191,7 @@ type loggerCollection struct {
honeypotLogger *zap.SugaredLogger
webAccessLogger *zap.SugaredLogger
webServerLogger *zap.SugaredLogger
portsLogger *zap.SugaredLogger
}
func setupLoggers(cfg config.Config) *loggerCollection {
@@ -198,6 +219,7 @@ func setupLoggers(cfg config.Config) *loggerCollection {
honeypotLogger: rootLogger.Named("HON").Sugar(),
webAccessLogger: rootLogger.Named("ACC").Sugar(),
webServerLogger: rootLogger.Named("WEB").Sugar(),
portsLogger: rootLogger.Named("PRT").Sugar(),
}
}