Skip to content

Commit

Permalink
Feature: non-blocking tracer, changed license (#57)
Browse files Browse the repository at this point in the history
* refactor tracer, introduce worker to avoid un-blocker trace strategy

* fixed unit test and refactor dockerFile

* buffered events chan

* refactor yaml API core, initial web hook tracing implementations

* added banner

* changed license from GPL 3 to MIT

* Edit readme
  • Loading branch information
mariocandela committed Aug 30, 2023
1 parent 345e9ef commit 0794736
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 642 deletions.
14 changes: 4 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,21 @@ RUN apk add git

WORKDIR /build

# Copy and download dependency using go mod
COPY go.mod .
COPY go.sum .
# Download dependency
COPY . .
RUN go mod download

# Copy the code into the container
COPY . .

# Build the application
# Build
RUN go build -o main .

# Move to /dist directory as the place for resulting binary folder
WORKDIR /dist

# Copy binary from build to main folder
RUN cp /build/main .

# Build a small image
# Use scratch image as finally tiny container
FROM scratch

# copy the ca-certificate.crt from the builder stage
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /dist/main /

Expand Down
617 changes: 21 additions & 596 deletions LICENSE

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@

## Overview

Beelzebub is an advanced honeypot framework designed to provide a highly secure environment for detecting and analyzing cyber attacks. It offers a low code approach for easy implementation and utilizes virtualization techniques powered by GPT-3, the OpenAI language model.
Beelzebub is an advanced honeypot framework designed to provide a highly secure environment for detecting and analyzing cyber attacks. It offers a low code approach for easy implementation and utilizes virtualization techniques powered by OpenAI Generative Pre-trained Transformer.

![Beelzebub Logo](https://i.postimg.cc/KvbsJFp3/logo-1.png)

## OpenAI GPT Integration

Learn how to integrate Beelzebub with OpenAI GPT-3 by referring to our comprehensive guide on Medium: [Medium Article](https://medium.com/@mario.candela.personal/how-to-build-a-highly-effective-honeypot-with-beelzebub-and-chatgpt-a2f0f05b3e1)

For a visual representation of the integration, you can explore the following diagram:

[![OpenAI Integration Diagram](https://static.swimlanes.io/24d6634a381aa8eb0decf5bac7ae214d.png)](https://static.swimlanes.io/24d6634a381aa8eb0decf5bac7ae214d.png)

## Telegram Bot for Real-Time Attacks

Stay updated on real-time attacks by joining our dedicated Telegram channel: [Telegram Channel](https://t.me/beelzebubhoneypot)
Expand Down Expand Up @@ -243,7 +239,7 @@ passwordRegex: "^(root|qwerty|Smoker666)$"
deadlineTimeoutSeconds: 60
```

![Screenshot](https://i.postimg.cc/jdpfT0LB/Schermata-2022-06-02-alle-12-46-50.png)
[![asciicast](https://asciinema.org/a/604522.svg)](https://asciinema.org/a/604522)

## Roadmap

Expand All @@ -257,6 +253,6 @@ Happy hacking!

## License

Beelzebub is licensed under the [GNU GPL 3 License](LICENSE).
Beelzebub is licensed under the [MIT License](LICENSE).

[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/donate/?business=P75FH5LXKQTAC&no_recurring=0&currency_code=EUR)
8 changes: 8 additions & 0 deletions builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ func (b *Builder) Close() error {
}

func (b *Builder) Run() error {
fmt.Println(
`
██████ ███████ ███████ ██ ███████ ███████ ██████ ██ ██ ██████
██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ██
██████ █████ █████ ██ ███ █████ ██████ ██ ██ ██████
██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ██
██████ ███████ ███████ ███████ ███████ ███████ ██████ ██████ ██████
Honeypot Framework, happy hacking!`)
// Init Prometheus openmetrics
go func() {
if (b.beelzebubCoreConfigurations.Core.Prometheus != parser.Prometheus{}) {
Expand Down
4 changes: 2 additions & 2 deletions builder/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func (d *Director) BuildBeelzebub(beelzebubCoreConfigurations *parser.BeelzebubC

d.builder.setTraceStrategy(d.standardOutStrategy)

if beelzebubCoreConfigurations.Core.Tracing.RabbitMQEnabled {
if beelzebubCoreConfigurations.Core.Tracings.RabbitMQ.Enabled {
d.builder.setTraceStrategy(d.rabbitMQTraceStrategy)
err := d.builder.buildRabbitMQ(beelzebubCoreConfigurations.Core.Tracing.RabbitMQURI)
err := d.builder.buildRabbitMQ(beelzebubCoreConfigurations.Core.Tracings.RabbitMQ.URI)
if err != nil {
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions configurations/beelzebub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ core:
debugReportCaller: false
logDisableTimestamp: true
logsPath: ./logs
tracing:
rabbitMQEnabled: false
rabbitMQURI: ""
tracings:
rabbit-mq:
enabled: false
uri: ""
prometheus:
path: "/metrics"
port: ":2112"
Expand Down
7 changes: 4 additions & 3 deletions integration_test/configurations/beelzebub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ core:
debugReportCaller: false
logDisableTimestamp: true
logsPath: ./logs
tracing:
rabbitMQEnabled: true
rabbitMQURI: "amqp://integration:integration@localhost:5672/"
tracings:
rabbit-mq:
enabled: true
uri: "amqp://integration:integration@localhost:5672/"
prometheus:
path: "/metrics"
port: ":2112"
2 changes: 1 addition & 1 deletion integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (suite *IntegrationTestSuite) SetupSuite() {

coreConfigurations, err := parser.ReadConfigurationsCore()
suite.Require().NoError(err)
suite.rabbitMQURI = coreConfigurations.Core.Tracing.RabbitMQURI
suite.rabbitMQURI = coreConfigurations.Core.Tracings.RabbitMQ.URI

beelzebubServicesConfiguration, err := parser.ReadConfigurationsServices()
suite.Require().NoError(err)
Expand Down
11 changes: 7 additions & 4 deletions parser/configurations_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
type BeelzebubCoreConfigurations struct {
Core struct {
Logging Logging `yaml:"logging"`
Tracing Tracing `yaml:"tracing"`
Tracings Tracings `yaml:"tracings"`
Prometheus Prometheus `yaml:"prometheus"`
}
}
Expand All @@ -26,11 +26,14 @@ type Logging struct {
LogsPath string `yaml:"logsPath,omitempty"`
}

type Tracing struct {
RabbitMQEnabled bool `yaml:"rabbitMQEnabled"`
RabbitMQURI string `yaml:"rabbitMQURI"`
type Tracings struct {
RabbitMQ `yaml:"rabbit-mq"`
}

type RabbitMQ struct {
Enabled bool `yaml:"enabled"`
URI string `yaml:"uri"`
}
type Prometheus struct {
Path string `yaml:"path"`
Port string `yaml:"port"`
Expand Down
14 changes: 8 additions & 6 deletions parser/configurations_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package parser

import (
"errors"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func mockReadfilebytesConfigurationsCore(filePath string) ([]byte, error) {
Expand All @@ -14,9 +15,10 @@ core:
debugReportCaller: false
logDisableTimestamp: true
logsPath: ./logs
tracing:
rabbitMQEnabled: true
rabbitMQURI: provaMock`)
tracings:
rabbit-mq:
enabled: true
uri: "amqp://user:password@localhost/"`)
return configurationsCoreBytes, nil
}

Expand Down Expand Up @@ -80,8 +82,8 @@ func TestReadConfigurationsCoreValid(t *testing.T) {
assert.Equal(t, coreConfigurations.Core.Logging.LogDisableTimestamp, true)
assert.Equal(t, coreConfigurations.Core.Logging.DebugReportCaller, false)
assert.Equal(t, coreConfigurations.Core.Logging.LogsPath, "./logs")
assert.Equal(t, coreConfigurations.Core.Tracing.RabbitMQEnabled, true)
assert.Equal(t, coreConfigurations.Core.Tracing.RabbitMQURI, "provaMock")
assert.Equal(t, coreConfigurations.Core.Tracings.RabbitMQ.Enabled, true)
assert.Equal(t, coreConfigurations.Core.Tracings.RabbitMQ.URI, "amqp://user:password@localhost/")
}

func TestReadConfigurationsServicesFail(t *testing.T) {
Expand Down
31 changes: 25 additions & 6 deletions tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import (

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
log "github.com/sirupsen/logrus"
)

const Workers = 5

type Event struct {
DateTime string
RemoteAddr string
Expand All @@ -32,7 +35,7 @@ type Event struct {

type (
Protocol int
Status int
Status int
)

const (
Expand Down Expand Up @@ -63,7 +66,8 @@ type Tracer interface {
}

type tracer struct {
strategy Strategy
strategy Strategy
eventsChan chan Event
}

var (
Expand All @@ -90,17 +94,32 @@ var (
)

func Init(strategy Strategy) *tracer {
return &tracer{
strategy: strategy,
tracer := &tracer{
strategy: strategy,
eventsChan: make(chan Event, Workers),
}

for i := 0; i < Workers; i++ {
go func(i int) {
log.Debug("Init trace worker: ", i)
for event := range tracer.eventsChan {
tracer.strategy(event)
}
}(i)
}

return tracer
}

func (tracer *tracer) setStrategy(strategy Strategy) {
tracer.strategy = strategy
}

func (tracer *tracer) TraceEvent(event Event) {
event.DateTime = time.Now().UTC().Format(time.RFC3339)

tracer.strategy(event)
tracer.eventsChan <- event

//Openmetrics
eventsTotal.Inc()

switch event.Protocol {
Expand Down
43 changes: 39 additions & 4 deletions tracer/tracer_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package tracer

import (
"github.com/stretchr/testify/assert"
"sync"
"testing"

"github.com/stretchr/testify/assert"
)

func TestInit(t *testing.T) {
Expand All @@ -15,23 +17,56 @@ func TestInit(t *testing.T) {

func TestTraceEvent(t *testing.T) {
eventCalled := Event{}
var wg sync.WaitGroup

mockStrategy := func(event Event) {
defer wg.Done()

eventCalled = event
}

tracer := Init(mockStrategy)

wg.Add(1)
tracer.TraceEvent(Event{
ID: "mockID",
Protocol: HTTP.String(),
Status: Stateless.String(),
})
wg.Wait()

assert.NotNil(t, eventCalled.ID)
assert.Equal(t, "mockID", eventCalled.ID)
assert.Equal(t, HTTP.String(), eventCalled.Protocol)
assert.Equal(t, Stateless.String(), eventCalled.Status)
}

func TestSetStrategy(t *testing.T) {
eventCalled := Event{}
var wg sync.WaitGroup

mockStrategy := func(event Event) {
defer wg.Done()

eventCalled = event
}

tracer := Init(mockStrategy)

tracer.setStrategy(mockStrategy)

wg.Add(1)
tracer.TraceEvent(Event{
ID: "mockID",
Protocol: HTTP.String(),
Status: Stateless.String(),
})
wg.Wait()

assert.NotNil(t, eventCalled.ID)
assert.Equal(t, eventCalled.ID, "mockID")
assert.Equal(t, eventCalled.Protocol, HTTP.String())
assert.Equal(t, eventCalled.Status, Stateless.String())
assert.Equal(t, "mockID", eventCalled.ID)
assert.Equal(t, HTTP.String(), eventCalled.Protocol)
assert.Equal(t, Stateless.String(), eventCalled.Status)
}

func TestStringStatus(t *testing.T) {
Expand Down

0 comments on commit 0794736

Please sign in to comment.