mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
5e5d0494a9 | |||
d77aa0c8a0 | |||
3733c902b9 |
@ -1,8 +1,10 @@
|
|||||||
# Beelzebub
|
# Beelzebub
|
||||||
|
|
||||||
[](https://github.com/mariocandela/beelzebub/actions/workflows/ci.yml) [](https://github.com/mariocandela/beelzebub/actions/workflows/docker-image.yml) [](https://github.com/mariocandela/beelzebub/actions/workflows/codeql.yml)
|
[](https://github.com/mariocandela/beelzebub/actions/workflows/ci.yml) [](https://github.com/mariocandela/beelzebub/actions/workflows/docker-image.yml) [](https://github.com/mariocandela/beelzebub/actions/workflows/codeql.yml)
|
||||||
[](https://goreportcard.com/report/github.com/mariocandela/beelzebub)
|
[](https://goreportcard.com/report/github.com/mariocandela/beelzebub/v3)
|
||||||
[](https://codecov.io/gh/mariocandela/beelzebub)
|
[](https://codecov.io/gh/mariocandela/beelzebub)
|
||||||
|
[](https://pkg.go.dev/github.com/mariocandela/beelzebub/v3)
|
||||||
|
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
|
2
go.mod
2
go.mod
@ -30,7 +30,7 @@ require (
|
|||||||
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
|
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
|
||||||
github.com/prometheus/common v0.44.0 // indirect
|
github.com/prometheus/common v0.44.0 // indirect
|
||||||
github.com/prometheus/procfs v0.11.1 // indirect
|
github.com/prometheus/procfs v0.11.1 // indirect
|
||||||
golang.org/x/net v0.15.0 // indirect
|
golang.org/x/net v0.17.0 // indirect
|
||||||
golang.org/x/sys v0.13.0 // indirect
|
golang.org/x/sys v0.13.0 // indirect
|
||||||
golang.org/x/term v0.13.0 // indirect
|
golang.org/x/term v0.13.0 // indirect
|
||||||
google.golang.org/protobuf v1.31.0 // indirect
|
google.golang.org/protobuf v1.31.0 // indirect
|
||||||
|
3
go.sum
3
go.sum
@ -79,8 +79,9 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
|
|||||||
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
|
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
|
||||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||||
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
|
|
||||||
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
||||||
|
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||||
|
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// Package parser is responsible for parsing the configurations of the core and honeypot service
|
||||||
package parser
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -10,6 +11,7 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// BeelzebubCoreConfigurations is the struct that contains the configurations of the core
|
||||||
type BeelzebubCoreConfigurations struct {
|
type BeelzebubCoreConfigurations struct {
|
||||||
Core struct {
|
Core struct {
|
||||||
Logging Logging `yaml:"logging"`
|
Logging Logging `yaml:"logging"`
|
||||||
@ -18,6 +20,7 @@ type BeelzebubCoreConfigurations struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logging is the struct that contains the configurations of the logging
|
||||||
type Logging struct {
|
type Logging struct {
|
||||||
Debug bool `yaml:"debug"`
|
Debug bool `yaml:"debug"`
|
||||||
DebugReportCaller bool `yaml:"debugReportCaller"`
|
DebugReportCaller bool `yaml:"debugReportCaller"`
|
||||||
@ -25,6 +28,7 @@ type Logging struct {
|
|||||||
LogsPath string `yaml:"logsPath,omitempty"`
|
LogsPath string `yaml:"logsPath,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tracings is the struct that contains the configurations of the tracings
|
||||||
type Tracings struct {
|
type Tracings struct {
|
||||||
RabbitMQ `yaml:"rabbit-mq"`
|
RabbitMQ `yaml:"rabbit-mq"`
|
||||||
}
|
}
|
||||||
@ -42,6 +46,7 @@ type Plugin struct {
|
|||||||
OpenAPIChatGPTSecretKey string `yaml:"openAPIChatGPTSecretKey"`
|
OpenAPIChatGPTSecretKey string `yaml:"openAPIChatGPTSecretKey"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BeelzebubServiceConfiguration is the struct that contains the configurations of the honeypot service
|
||||||
type BeelzebubServiceConfiguration struct {
|
type BeelzebubServiceConfiguration struct {
|
||||||
ApiVersion string `yaml:"apiVersion"`
|
ApiVersion string `yaml:"apiVersion"`
|
||||||
Protocol string `yaml:"protocol"`
|
Protocol string `yaml:"protocol"`
|
||||||
@ -56,6 +61,7 @@ type BeelzebubServiceConfiguration struct {
|
|||||||
Plugin Plugin `yaml:"plugin"`
|
Plugin Plugin `yaml:"plugin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Command is the struct that contains the configurations of the commands
|
||||||
type Command struct {
|
type Command struct {
|
||||||
Regex string `yaml:"regex"`
|
Regex string `yaml:"regex"`
|
||||||
Handler string `yaml:"handler"`
|
Handler string `yaml:"handler"`
|
||||||
@ -85,6 +91,7 @@ func Init(configurationsCorePath, configurationsServicesDirectory string) *confi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadConfigurationsCore is the method that reads the configurations of the core from files
|
||||||
func (bp configurationsParser) ReadConfigurationsCore() (*BeelzebubCoreConfigurations, error) {
|
func (bp configurationsParser) ReadConfigurationsCore() (*BeelzebubCoreConfigurations, error) {
|
||||||
buf, err := bp.readFileBytesByFilePathDependency(bp.configurationsCorePath)
|
buf, err := bp.readFileBytesByFilePathDependency(bp.configurationsCorePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -100,6 +107,7 @@ func (bp configurationsParser) ReadConfigurationsCore() (*BeelzebubCoreConfigura
|
|||||||
return beelzebubConfiguration, nil
|
return beelzebubConfiguration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReadConfigurationsServices is the method that reads the configurations of the honeypot services from files
|
||||||
func (bp configurationsParser) ReadConfigurationsServices() ([]BeelzebubServiceConfiguration, error) {
|
func (bp configurationsParser) ReadConfigurationsServices() ([]BeelzebubServiceConfiguration, error) {
|
||||||
services, err := bp.gelAllFilesNameByDirNameDependency(bp.configurationsServicesDirectory)
|
services, err := bp.gelAllFilesNameByDirNameDependency(bp.configurationsServicesDirectory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// Package protocols is responsible for managing the different protocols
|
||||||
package protocols
|
package protocols
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -5,6 +6,7 @@ import (
|
|||||||
"github.com/mariocandela/beelzebub/v3/tracer"
|
"github.com/mariocandela/beelzebub/v3/tracer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ServiceStrategy is the common interface that each protocol honeypot implements
|
||||||
type ServiceStrategy interface {
|
type ServiceStrategy interface {
|
||||||
Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tracer tracer.Tracer) error
|
Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tracer tracer.Tracer) error
|
||||||
}
|
}
|
||||||
@ -14,10 +16,11 @@ type ProtocolManager struct {
|
|||||||
tracer tracer.Tracer
|
tracer tracer.Tracer
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitProtocolManager(tracerStrategy tracer.Strategy, strategy ServiceStrategy) *ProtocolManager {
|
// 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 {
|
||||||
return &ProtocolManager{
|
return &ProtocolManager{
|
||||||
tracer: tracer.GetInstance(tracerStrategy),
|
tracer: tracer.GetInstance(tracerStrategy),
|
||||||
strategy: strategy,
|
strategy: serviceStrategy,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,6 +28,7 @@ func (pm *ProtocolManager) SetProtocolStrategy(strategy ServiceStrategy) {
|
|||||||
pm.strategy = strategy
|
pm.strategy = strategy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InitService is the method that initializes the honeypot
|
||||||
func (pm *ProtocolManager) InitService(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration) error {
|
func (pm *ProtocolManager) InitService(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration) error {
|
||||||
return pm.strategy.Init(beelzebubServiceConfiguration, pm.tracer)
|
return pm.strategy.Init(beelzebubServiceConfiguration, pm.tracer)
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// Package tracer is responsible for tracing the events that occur in the honeypots
|
||||||
package tracer
|
package tracer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -9,6 +10,7 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Workers is the number of workers that will
|
||||||
const Workers = 5
|
const Workers = 5
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
@ -78,14 +80,14 @@ type tracer struct {
|
|||||||
var lock = &sync.Mutex{}
|
var lock = &sync.Mutex{}
|
||||||
var singleton *tracer
|
var singleton *tracer
|
||||||
|
|
||||||
func GetInstance(strategy Strategy) *tracer {
|
func GetInstance(defaultStrategy Strategy) *tracer {
|
||||||
if singleton == nil {
|
if singleton == nil {
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
defer lock.Unlock()
|
defer lock.Unlock()
|
||||||
// This is to prevent expensive lock operations every time the GetInstance method is called
|
// This is to prevent expensive lock operations every time the GetInstance method is called
|
||||||
if singleton == nil {
|
if singleton == nil {
|
||||||
singleton = &tracer{
|
singleton = &tracer{
|
||||||
strategy: strategy,
|
strategy: defaultStrategy,
|
||||||
eventsChan: make(chan Event, Workers),
|
eventsChan: make(chan Event, Workers),
|
||||||
eventsTotal: promauto.NewCounter(prometheus.CounterOpts{
|
eventsTotal: promauto.NewCounter(prometheus.CounterOpts{
|
||||||
Namespace: "beelzebub",
|
Namespace: "beelzebub",
|
||||||
@ -111,7 +113,7 @@ func GetInstance(strategy Strategy) *tracer {
|
|||||||
|
|
||||||
for i := 0; i < Workers; i++ {
|
for i := 0; i < Workers; i++ {
|
||||||
go func(i int) {
|
go func(i int) {
|
||||||
log.Debug("GetInstance trace worker: ", i)
|
log.Debug("Trace worker: ", i)
|
||||||
for event := range singleton.eventsChan {
|
for event := range singleton.eventsChan {
|
||||||
singleton.strategy(event)
|
singleton.strategy(event)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user