2023-10-15 20:54:53 +02:00
|
|
|
// Package protocols is responsible for managing the different protocols
|
2022-05-08 20:49:53 +02:00
|
|
|
package protocols
|
|
|
|
|
2022-05-09 23:19:19 +02:00
|
|
|
import (
|
2023-10-08 17:45:31 +02:00
|
|
|
"github.com/mariocandela/beelzebub/v3/parser"
|
|
|
|
"github.com/mariocandela/beelzebub/v3/tracer"
|
2022-05-09 23:19:19 +02:00
|
|
|
)
|
2022-05-08 20:49:53 +02:00
|
|
|
|
2023-10-15 20:54:53 +02:00
|
|
|
// ServiceStrategy is the common interface that each protocol honeypot implements
|
2022-05-11 22:58:03 +02:00
|
|
|
type ServiceStrategy interface {
|
|
|
|
Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tracer tracer.Tracer) error
|
|
|
|
}
|
|
|
|
|
2022-05-08 20:49:53 +02:00
|
|
|
type ProtocolManager struct {
|
|
|
|
strategy ServiceStrategy
|
2022-06-04 17:14:46 +02:00
|
|
|
tracer tracer.Tracer
|
2022-05-08 20:49:53 +02:00
|
|
|
}
|
|
|
|
|
2023-10-15 20:54:53 +02:00
|
|
|
// InitProtocolManager is the method that initializes the protocol manager, receving the concrete tracer and the concrete service
|
|
|
|
func InitProtocolManager(tracerStrategy tracer.Strategy, serviceStrategy ServiceStrategy) *ProtocolManager {
|
2022-05-09 23:19:19 +02:00
|
|
|
return &ProtocolManager{
|
2023-10-09 01:16:53 +02:00
|
|
|
tracer: tracer.GetInstance(tracerStrategy),
|
2023-10-15 20:54:53 +02:00
|
|
|
strategy: serviceStrategy,
|
2022-05-09 23:19:19 +02:00
|
|
|
}
|
2022-05-08 20:49:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (pm *ProtocolManager) SetProtocolStrategy(strategy ServiceStrategy) {
|
|
|
|
pm.strategy = strategy
|
|
|
|
}
|
|
|
|
|
2023-10-15 20:54:53 +02:00
|
|
|
// InitService is the method that initializes the honeypot
|
2022-05-08 20:49:53 +02:00
|
|
|
func (pm *ProtocolManager) InitService(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration) error {
|
2022-06-04 17:14:46 +02:00
|
|
|
return pm.strategy.Init(beelzebubServiceConfiguration, pm.tracer)
|
2022-05-08 20:49:53 +02:00
|
|
|
}
|