mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
Compare commits
45 Commits
Author | SHA1 | Date | |
---|---|---|---|
a7c69c8849 | |||
7d46c9544c | |||
10d16d7dd1 | |||
48489e0abb | |||
ca51e076b6 | |||
9025edee1e | |||
853708a598 | |||
8d9f1b48da | |||
9d0a92e74e | |||
49a4022f56 | |||
fe6d95ecd6 | |||
d24a580a78 | |||
9a354add6f | |||
3652af6dc3 | |||
5532d3c629 | |||
97ab2f6e95 | |||
f50f5185df | |||
5a70e5c900 | |||
142dccabf1 | |||
8337281f21 | |||
1c402141bf | |||
9c9fd0b676 | |||
97cfdcc8af | |||
c7c169c96d | |||
f733a0ea96 | |||
31a75cc128 | |||
fd7db83fd8 | |||
1b01933946 | |||
6548cf62ce | |||
6468b5aa6f | |||
bbcc8c9094 | |||
6ff99e4eed | |||
0ebb6fa1e2 | |||
6f9781f06f | |||
e4ca84589b | |||
31f5ca9cb1 | |||
c6855e8511 | |||
6d2500d0f5 | |||
c98b888985 | |||
d062435818 | |||
9ddb076621 | |||
5bfdff7097 | |||
fa7d17f817 | |||
fafa2bcb05 | |||
3801628ef1 |
1
.github/FUNDING.yml
vendored
1
.github/FUNDING.yml
vendored
@ -1 +1,2 @@
|
||||
patreon: mariocandela
|
||||
custom: ["https://www.paypal.com/donate/?business=P75FH5LXKQTAC&no_recurring=0¤cy_code=EUR"]
|
||||
|
35
.github/workflows/ci.yml
vendored
35
.github/workflows/ci.yml
vendored
@ -8,7 +8,7 @@ on:
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
CI:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
@ -16,9 +16,9 @@ jobs:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 1.16
|
||||
go-version: 1.20.0
|
||||
|
||||
- name: Dependences
|
||||
- name: Dependencies
|
||||
run: go mod download
|
||||
|
||||
- name: Vet
|
||||
@ -30,7 +30,7 @@ jobs:
|
||||
|
||||
- name: Unit tests
|
||||
run: |
|
||||
go test ./... -coverprofile coverage.tmp.out -covermode count
|
||||
go test ./... -v -coverprofile coverage.tmp.out -covermode count
|
||||
go tool cover -func coverage.tmp.out
|
||||
|
||||
- name: Quality Gate - Test coverage shall be above threshold
|
||||
@ -39,8 +39,8 @@ jobs:
|
||||
run: |
|
||||
echo "Quality Gate: checking test coverage is above threshold ..."
|
||||
echo "Threshold : $TESTCOVERAGE_THRESHOLD %"
|
||||
# Excluded the concrete strategy
|
||||
cat coverage.tmp.out | grep -v "secureShellStrategy.go" | grep -v "hypertextTransferProtocolStrategy.go" | grep -v "transmissionControlProtocolStrategy.go" > coverage.out
|
||||
# Excluded the concrete strategy from the unit test coverage, because covered by integration tests
|
||||
cat coverage.tmp.out | grep -v "ssh.go" | grep -v "http.go" | grep -v "tcp.go" > coverage.out
|
||||
totalCoverage=`go tool cover -func=coverage.out | grep total | grep -Eo '[0-9]+\.[0-9]+'`
|
||||
echo "Current test coverage : $totalCoverage %"
|
||||
if (( $(echo "$totalCoverage $TESTCOVERAGE_THRESHOLD" | awk '{print ($1 > $2)}') )); then
|
||||
@ -50,3 +50,26 @@ jobs:
|
||||
echo "Failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Start integration test dependencies
|
||||
run: |
|
||||
make test.dependencies.start
|
||||
|
||||
- name: Wait for RabbitMQ to be ready
|
||||
run: |
|
||||
sleep 2
|
||||
count=0
|
||||
until docker exec rabbitmq rabbitmqctl list_queues > /dev/null 2>&1; do
|
||||
count=$((count+1))
|
||||
if [ $count -gt 10 ]; then
|
||||
echo "RabbitMQ did not start within the specified time"
|
||||
exit 1
|
||||
fi
|
||||
echo "Waiting for RabbitMQ to start..."
|
||||
sleep 5
|
||||
done
|
||||
|
||||
- name: Integration tests
|
||||
run: |
|
||||
make test.integration.verbose
|
||||
make test.dependencies.down
|
||||
|
40
.github/workflows/codeql.yml
vendored
Normal file
40
.github/workflows/codeql.yml
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
schedule:
|
||||
- cron: '36 10 * * 0'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'go' ]
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
|
||||
- name: Build beelzebub
|
||||
run: go build ./...
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
with:
|
||||
category: "/language:${{matrix.language}}"
|
37
.github/workflows/docker-image.yml
vendored
37
.github/workflows/docker-image.yml
vendored
@ -6,21 +6,26 @@ on:
|
||||
- 'v*.*.*'
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
|
||||
CD:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Docker login
|
||||
env:
|
||||
DOCKER_USER: ${{secrets.DOCKER_USER}}
|
||||
DOCKER_ACCESS_TOKEN: ${{secrets.DOCKER_ACCESS_TOKEN}}
|
||||
run: |
|
||||
docker login -u $DOCKER_USER -p $DOCKER_ACCESS_TOKEN
|
||||
- name: Build the Docker image
|
||||
run: docker build . --file Dockerfile --tag m4r10/beelzebub:${{ github.ref_name }}
|
||||
|
||||
- name: Docker Push
|
||||
run: docker push m4r10/beelzebub:${{ github.ref_name }}
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
-
|
||||
name: Login to Docker Hub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USER }}
|
||||
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
-
|
||||
name: Build and push
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
tags: m4r10/beelzebub:${{ github.ref_name }}
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
.DS_Store
|
||||
.idea
|
||||
logs
|
||||
.vscode
|
||||
.history
|
128
CODE_OF_CONDUCT.md
Normal file
128
CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,128 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, religion, or sexual identity
|
||||
and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
mario.candela.personal@gmail.com.
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series
|
||||
of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or
|
||||
permanent ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
the community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.0, available at
|
||||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||
|
||||
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||
enforcement ladder](https://github.com/mozilla/diversity).
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
https://www.contributor-covenant.org/faq. Translations are available at
|
||||
https://www.contributor-covenant.org/translations.
|
@ -29,6 +29,8 @@ RUN cp /build/main .
|
||||
# Build a small image
|
||||
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 /
|
||||
|
||||
ENTRYPOINT ["/main"]
|
38
Makefile
Normal file
38
Makefile
Normal file
@ -0,0 +1,38 @@
|
||||
DOCKER_COMPOSE := $(shell which docker-compose)
|
||||
|
||||
ifeq (${DOCKER_COMPOSE},)
|
||||
DOCKER_COMPOSE = docker compose
|
||||
endif
|
||||
|
||||
.PHONY: beelzebub.start
|
||||
beelzebub.start:
|
||||
${DOCKER_COMPOSE} build;
|
||||
${DOCKER_COMPOSE} up -d;
|
||||
|
||||
.PHONY: beelzebub.stop
|
||||
beelzebub.stop:
|
||||
${DOCKER_COMPOSE} down;
|
||||
|
||||
.PHONY: test.unit
|
||||
test.unit:
|
||||
go test ./...
|
||||
|
||||
.PHONY: test.unit.verbose
|
||||
test.unit.verbose:
|
||||
go test ./... -v
|
||||
|
||||
.PHONY: test.dependencies.start
|
||||
test.dependencies.start:
|
||||
${DOCKER_COMPOSE} -f ./integration_test/docker-compose.yml up -d
|
||||
|
||||
.PHONY: test.dependencies.down
|
||||
test.dependencies.down:
|
||||
${DOCKER_COMPOSE} -f ./integration_test/docker-compose.yml down
|
||||
|
||||
.PHONY: test.integration
|
||||
test.integration:
|
||||
INTEGRATION=1 go test ./...
|
||||
|
||||
.PHONY: test.integration.verbose
|
||||
test.integration.verbose:
|
||||
INTEGRATION=1 go test ./... -v
|
13
SECURITY.md
Normal file
13
SECURITY.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
| Version | Supported |
|
||||
| ------- | ------------------ |
|
||||
| >= 2.0.0 | :white_check_mark: |
|
||||
| < 2.0.0 | :x: |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Please report (suspected) security vulnerabilities to mario.candela.personal@gmail.com.
|
||||
You will receive a response from us within 48 hours. If the issue is confirmed, we will release a patch as soon as possible depending on complexity but historically within a few days.
|
141
builder/builder.go
Normal file
141
builder/builder.go
Normal file
@ -0,0 +1,141 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"beelzebub/parser"
|
||||
"beelzebub/protocols"
|
||||
"beelzebub/protocols/strategies"
|
||||
"beelzebub/tracer"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const RabbitmqQueueName = "event"
|
||||
|
||||
type Builder struct {
|
||||
beelzebubServicesConfiguration []parser.BeelzebubServiceConfiguration
|
||||
beelzebubCoreConfigurations *parser.BeelzebubCoreConfigurations
|
||||
traceStrategy tracer.Strategy
|
||||
rabbitMQChannel *amqp.Channel
|
||||
rabbitMQConnection *amqp.Connection
|
||||
logsFile *os.File
|
||||
}
|
||||
|
||||
func (b *Builder) setTraceStrategy(traceStrategy tracer.Strategy) {
|
||||
b.traceStrategy = traceStrategy
|
||||
}
|
||||
|
||||
func (b *Builder) buildLogger(configurations parser.Logging) error {
|
||||
logsFile, err := os.OpenFile(configurations.LogsPath, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.SetOutput(io.MultiWriter(os.Stdout, logsFile))
|
||||
|
||||
log.SetFormatter(&log.JSONFormatter{
|
||||
DisableTimestamp: configurations.LogDisableTimestamp,
|
||||
})
|
||||
log.SetReportCaller(configurations.DebugReportCaller)
|
||||
if configurations.Debug {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
} else {
|
||||
log.SetLevel(log.InfoLevel)
|
||||
}
|
||||
b.logsFile = logsFile
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Builder) buildRabbitMQ(rabbitMQURI string) error {
|
||||
rabbitMQConnection, err := amqp.Dial(rabbitMQURI)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.rabbitMQChannel, err = rabbitMQConnection.Channel()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//creates a queue if it doesn't already exist, or ensures that an existing queue matches the same parameters.
|
||||
if _, err = b.rabbitMQChannel.QueueDeclare(RabbitmqQueueName, false, false, false, false, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.rabbitMQConnection = rabbitMQConnection
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Builder) Close() error {
|
||||
if b.rabbitMQConnection != nil {
|
||||
if err := b.rabbitMQChannel.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := b.rabbitMQConnection.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Builder) Run() error {
|
||||
// Init Prometheus openmetrics
|
||||
go func() {
|
||||
if (b.beelzebubCoreConfigurations.Core.Prometheus != parser.Prometheus{}) {
|
||||
http.Handle(b.beelzebubCoreConfigurations.Core.Prometheus.Path, promhttp.Handler())
|
||||
|
||||
if err := http.ListenAndServe(b.beelzebubCoreConfigurations.Core.Prometheus.Port, nil); err != nil {
|
||||
log.Fatalf("Error init Prometheus: %s", err.Error())
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Init Protocol strategies
|
||||
secureShellStrategy := &strategies.SSHStrategy{}
|
||||
hypertextTransferProtocolStrategy := &strategies.HTTPStrategy{}
|
||||
transmissionControlProtocolStrategy := &strategies.TCPStrategy{}
|
||||
|
||||
// Init Tracer strategies, and set the trace strategy default HTTP
|
||||
protocolManager := protocols.InitProtocolManager(b.traceStrategy, hypertextTransferProtocolStrategy)
|
||||
|
||||
for _, beelzebubServiceConfiguration := range b.beelzebubServicesConfiguration {
|
||||
switch beelzebubServiceConfiguration.Protocol {
|
||||
case "http":
|
||||
protocolManager.SetProtocolStrategy(hypertextTransferProtocolStrategy)
|
||||
break
|
||||
case "ssh":
|
||||
protocolManager.SetProtocolStrategy(secureShellStrategy)
|
||||
break
|
||||
case "tcp":
|
||||
protocolManager.SetProtocolStrategy(transmissionControlProtocolStrategy)
|
||||
break
|
||||
default:
|
||||
log.Fatalf("Protocol %s not managed", beelzebubServiceConfiguration.Protocol)
|
||||
continue
|
||||
}
|
||||
|
||||
if err := protocolManager.InitService(beelzebubServiceConfiguration); err != nil {
|
||||
return errors.New(fmt.Sprintf("Error during init protocol: %s, %s", beelzebubServiceConfiguration.Protocol, err.Error()))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *Builder) build() *Builder {
|
||||
return &Builder{
|
||||
beelzebubServicesConfiguration: b.beelzebubServicesConfiguration,
|
||||
traceStrategy: b.traceStrategy,
|
||||
beelzebubCoreConfigurations: b.beelzebubCoreConfigurations,
|
||||
}
|
||||
}
|
||||
|
||||
func NewBuilder() *Builder {
|
||||
return &Builder{}
|
||||
}
|
68
builder/director.go
Normal file
68
builder/director.go
Normal file
@ -0,0 +1,68 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"beelzebub/parser"
|
||||
"beelzebub/tracer"
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Director struct {
|
||||
builder *Builder
|
||||
}
|
||||
|
||||
func NewDirector(builder *Builder) *Director {
|
||||
return &Director{
|
||||
builder: builder,
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Director) BuildBeelzebub(beelzebubCoreConfigurations *parser.BeelzebubCoreConfigurations, beelzebubServicesConfiguration []parser.BeelzebubServiceConfiguration) (*Builder, error) {
|
||||
d.builder.beelzebubServicesConfiguration = beelzebubServicesConfiguration
|
||||
d.builder.beelzebubCoreConfigurations = beelzebubCoreConfigurations
|
||||
if err := d.builder.buildLogger(beelzebubCoreConfigurations.Core.Logging); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
d.builder.setTraceStrategy(d.standardOutStrategy)
|
||||
|
||||
if beelzebubCoreConfigurations.Core.Tracing.RabbitMQEnabled {
|
||||
d.builder.setTraceStrategy(d.rabbitMQTraceStrategy)
|
||||
err := d.builder.buildRabbitMQ(beelzebubCoreConfigurations.Core.Tracing.RabbitMQURI)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return d.builder.build(), nil
|
||||
}
|
||||
|
||||
func (d *Director) standardOutStrategy(event tracer.Event) {
|
||||
log.WithFields(log.Fields{
|
||||
"status": event.Status,
|
||||
"event": event,
|
||||
}).Info("New Event")
|
||||
}
|
||||
|
||||
func (d *Director) rabbitMQTraceStrategy(event tracer.Event) {
|
||||
log.WithFields(log.Fields{
|
||||
"status": event.Status,
|
||||
"event": event,
|
||||
}).Info("New Event")
|
||||
|
||||
log.Debug("Push Event on queue")
|
||||
eventJSON, err := json.Marshal(event)
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
publishing := amqp.Publishing{ContentType: "application/json", Body: eventJSON}
|
||||
|
||||
if err = d.builder.rabbitMQChannel.PublishWithContext(context.TODO(), "", RabbitmqQueueName, false, false, publishing); err != nil {
|
||||
log.Error(err.Error())
|
||||
}
|
||||
}
|
@ -7,3 +7,7 @@ core:
|
||||
tracing:
|
||||
rabbitMQEnabled: false
|
||||
rabbitMQURI: ""
|
||||
prometheus:
|
||||
path: "/metrics"
|
||||
port: ":2112"
|
||||
|
||||
|
13
configurations/services/ssh-2222.yaml
Normal file
13
configurations/services/ssh-2222.yaml
Normal file
@ -0,0 +1,13 @@
|
||||
apiVersion: "v1"
|
||||
protocol: "ssh"
|
||||
address: ":2222"
|
||||
description: "SSH interactive ChatGPT"
|
||||
commands:
|
||||
- regex: "^(.+)$"
|
||||
plugin: "OpenAIGPTLinuxTerminal"
|
||||
serverVersion: "OpenSSH"
|
||||
serverName: "ubuntu"
|
||||
passwordRegex: "^(root|qwerty|Smoker666|123456|jenkins|minecraft|sinus|alex|postgres|Ly123456)$"
|
||||
deadlineTimeoutSeconds: 60
|
||||
plugin:
|
||||
openAPIChatGPTSecretKey: ""
|
@ -8,9 +8,11 @@ services:
|
||||
restart: always
|
||||
ports: # Remove me, if you use configuration network_mode: host
|
||||
- "22:22"
|
||||
- "2222:2222"
|
||||
- "8080:8080"
|
||||
- "80:80"
|
||||
- "3306:3306"
|
||||
- "2112:2112" # Prometheus openmetrics
|
||||
environment:
|
||||
RABBITMQ_URI: ${RABBITMQ_URI}
|
||||
volumes:
|
||||
|
35
go.mod
35
go.mod
@ -1,13 +1,38 @@
|
||||
module beelzebub
|
||||
|
||||
go 1.16
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/gliderlabs/ssh v0.3.5
|
||||
github.com/go-resty/resty/v2 v2.7.0
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/rabbitmq/amqp091-go v1.4.0
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
github.com/stretchr/testify v1.8.0
|
||||
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d
|
||||
github.com/jarcoal/httpmock v1.3.0
|
||||
github.com/melbahja/goph v1.3.1
|
||||
github.com/prometheus/client_golang v1.15.1
|
||||
github.com/rabbitmq/amqp091-go v1.8.1
|
||||
github.com/sirupsen/logrus v1.9.2
|
||||
github.com/stretchr/testify v1.8.4
|
||||
golang.org/x/crypto v0.9.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/kr/fs v0.1.0 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pkg/sftp v1.13.5 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/prometheus/client_model v0.3.0 // indirect
|
||||
github.com/prometheus/common v0.42.0 // indirect
|
||||
github.com/prometheus/procfs v0.9.0 // indirect
|
||||
github.com/rogpeppe/go-internal v1.10.0 // indirect
|
||||
golang.org/x/net v0.10.0 // indirect
|
||||
golang.org/x/sys v0.8.0 // indirect
|
||||
golang.org/x/term v0.8.0 // indirect
|
||||
google.golang.org/protobuf v1.30.0 // indirect
|
||||
)
|
||||
|
104
go.sum
104
go.sum
@ -1,75 +1,125 @@
|
||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
|
||||
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
|
||||
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
|
||||
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/jarcoal/httpmock v1.3.0 h1:2RJ8GP0IIaWwcC9Fp2BmVi8Kog3v2Hn7VXM3fTd+nuc=
|
||||
github.com/jarcoal/httpmock v1.3.0/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg=
|
||||
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
|
||||
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
|
||||
github.com/maxatome/go-testdeep v1.12.0 h1:Ql7Go8Tg0C1D/uMMX59LAoYK7LffeJQ6X2T04nTH68g=
|
||||
github.com/melbahja/goph v1.3.1 h1:FxFevAwCCpLkM4WBmnVVxcJBcBz6lKQpsN5biV2hA6w=
|
||||
github.com/melbahja/goph v1.3.1/go.mod h1:uG+VfK2Dlhk+O32zFrRlc3kYKTlV6+BtvPWd/kK7U68=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/sftp v1.13.5 h1:a3RLUqkyjYRtBTZJZ1VRrKbN3zhuPLlUc3sphVz81go=
|
||||
github.com/pkg/sftp v1.13.5/go.mod h1:wHDZ0IZX6JcBYRK1TH9bcVq8G7TLpVHYIGJRFnmPfxg=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rabbitmq/amqp091-go v1.4.0 h1:T2G+J9W9OY4p64Di23J6yH7tOkMocgnESvYeBjuG9cY=
|
||||
github.com/rabbitmq/amqp091-go v1.4.0/go.mod h1:JsV0ofX5f1nwOGafb8L5rBItt9GyhfQfcJj+oyz0dGg=
|
||||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/prometheus/client_golang v1.15.1 h1:8tXpTmJbyH5lydzFPoxSIJ0J46jdh3tylbvM1xCv0LI=
|
||||
github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
|
||||
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
|
||||
github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
|
||||
github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM=
|
||||
github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc=
|
||||
github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI=
|
||||
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
|
||||
github.com/rabbitmq/amqp091-go v1.8.1 h1:RejT1SBUim5doqcL6s7iN6SBmsQqyTgXb1xMlH0h1hA=
|
||||
github.com/rabbitmq/amqp091-go v1.8.1/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
|
||||
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
||||
github.com/sirupsen/logrus v1.9.2 h1:oxx1eChJGI6Uks2ZC4W1zpLlVgqB8ner4EuQwV4Ik1Y=
|
||||
github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
|
||||
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
|
||||
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d h1:3qF+Z8Hkrw9sOhrFHti9TlB1Hkac1x+DNRkv0XQiFjo=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
||||
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
|
||||
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
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.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
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-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 h1:UiNENfZ8gDvpiWw7IpOMQ27spWmThO1RwwdQVbJahJM=
|
||||
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc=
|
||||
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols=
|
||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
|
||||
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
12
integration_test/configurations/beelzebub.yaml
Normal file
12
integration_test/configurations/beelzebub.yaml
Normal file
@ -0,0 +1,12 @@
|
||||
core:
|
||||
logging:
|
||||
debug: false
|
||||
debugReportCaller: false
|
||||
logDisableTimestamp: true
|
||||
logsPath: ./logs
|
||||
tracing:
|
||||
rabbitMQEnabled: true
|
||||
rabbitMQURI: "amqp://integration:integration@localhost:5672/"
|
||||
prometheus:
|
||||
path: "/metrics"
|
||||
port: ":2112"
|
19
integration_test/configurations/services/http-8080.yaml
Normal file
19
integration_test/configurations/services/http-8080.yaml
Normal file
@ -0,0 +1,19 @@
|
||||
apiVersion: "v1"
|
||||
protocol: "http"
|
||||
address: ":8080"
|
||||
description: "Wordpress 6.0"
|
||||
commands:
|
||||
- regex: "index.php"
|
||||
handler: "mocked response"
|
||||
headers:
|
||||
- "Content-Type: text/html"
|
||||
- "Server: Apache/2.4.53 (Debian)"
|
||||
- "X-Powered-By: PHP/7.4.29"
|
||||
statusCode: 200
|
||||
- regex: "^(/wp-login.php|/wp-admin)$"
|
||||
handler: "mocked response"
|
||||
headers:
|
||||
- "Content-Type: text/html"
|
||||
- "Server: Apache/2.4.53 (Debian)"
|
||||
- "X-Powered-By: PHP/7.4.29"
|
||||
statusCode: 400
|
25
integration_test/configurations/services/ssh-2222.yaml
Normal file
25
integration_test/configurations/services/ssh-2222.yaml
Normal file
@ -0,0 +1,25 @@
|
||||
apiVersion: "v1"
|
||||
protocol: "ssh"
|
||||
address: ":2222"
|
||||
description: "SSH interactive"
|
||||
commands:
|
||||
- regex: "^ls$"
|
||||
handler: "Documents Images Desktop Downloads .m2 .kube .ssh .docker"
|
||||
- regex: "^pwd$"
|
||||
handler: "/home/"
|
||||
- regex: "^uname -m$"
|
||||
handler: "x86_64"
|
||||
- regex: "^docker ps$"
|
||||
handler: "CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES"
|
||||
- regex: "^docker .*$"
|
||||
handler: "Error response from daemon: dial unix docker.raw.sock: connect: connection refused"
|
||||
- regex: "^uname$"
|
||||
handler: "Linux"
|
||||
- regex: "^ps$"
|
||||
handler: " PID TTY TIME CMD\n21642 ttys000 0:00.07 /bin/dockerd"
|
||||
- regex: "^(.+)$"
|
||||
handler: "command not found"
|
||||
serverVersion: "OpenSSH"
|
||||
serverName: "ubuntu"
|
||||
passwordRegex: "^(root|qwerty|Smoker666|123456|jenkins|minecraft|sinus|alex|postgres|Ly123456)$"
|
||||
deadlineTimeoutSeconds: 60
|
6
integration_test/configurations/services/tcp-3306.yaml
Normal file
6
integration_test/configurations/services/tcp-3306.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
apiVersion: "v1"
|
||||
protocol: "tcp"
|
||||
address: ":3306"
|
||||
description: "Mysql 8.0.29"
|
||||
banner: "8.0.29"
|
||||
deadlineTimeoutSeconds: 10
|
10
integration_test/docker-compose.yml
Normal file
10
integration_test/docker-compose.yml
Normal file
@ -0,0 +1,10 @@
|
||||
version: "3.9"
|
||||
services:
|
||||
rabbitmq:
|
||||
image: rabbitmq:3-alpine
|
||||
container_name: 'rabbitmq'
|
||||
ports:
|
||||
- 5672:5672
|
||||
environment:
|
||||
- RABBITMQ_DEFAULT_USER=integration
|
||||
- RABBITMQ_DEFAULT_PASS=integration
|
163
integration_test/integration_test.go
Normal file
163
integration_test/integration_test.go
Normal file
@ -0,0 +1,163 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"beelzebub/builder"
|
||||
"beelzebub/parser"
|
||||
"beelzebub/tracer"
|
||||
"encoding/json"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/melbahja/goph"
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
type IntegrationTestSuite struct {
|
||||
suite.Suite
|
||||
beelzebubBuilder *builder.Builder
|
||||
prometheusHost string
|
||||
httpHoneypotHost string
|
||||
tcpHoneypotHost string
|
||||
sshHoneypotHost string
|
||||
rabbitMQURI string
|
||||
}
|
||||
|
||||
func TestIntegrationTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(IntegrationTestSuite))
|
||||
}
|
||||
|
||||
func (suite *IntegrationTestSuite) SetupSuite() {
|
||||
suite.T().Helper()
|
||||
if os.Getenv("INTEGRATION") == "" {
|
||||
suite.T().Skip("skipping integration tests, set environment variable INTEGRATION")
|
||||
}
|
||||
suite.httpHoneypotHost = "http://localhost:8080"
|
||||
suite.tcpHoneypotHost = "localhost:3306"
|
||||
suite.sshHoneypotHost = "localhost"
|
||||
suite.prometheusHost = "http://localhost:2112/metrics"
|
||||
|
||||
beelzebubConfigPath := "./configurations/beelzebub.yaml"
|
||||
servicesConfigDirectory := "./configurations/services/"
|
||||
|
||||
parser := parser.Init(beelzebubConfigPath, servicesConfigDirectory)
|
||||
|
||||
coreConfigurations, err := parser.ReadConfigurationsCore()
|
||||
suite.Require().NoError(err)
|
||||
suite.rabbitMQURI = coreConfigurations.Core.Tracing.RabbitMQURI
|
||||
|
||||
beelzebubServicesConfiguration, err := parser.ReadConfigurationsServices()
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.beelzebubBuilder = builder.NewBuilder()
|
||||
|
||||
director := builder.NewDirector(suite.beelzebubBuilder)
|
||||
|
||||
suite.beelzebubBuilder, err = director.BuildBeelzebub(coreConfigurations, beelzebubServicesConfiguration)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Require().NoError(suite.beelzebubBuilder.Run())
|
||||
}
|
||||
|
||||
func (suite *IntegrationTestSuite) TestInvokeHTTPHoneypot() {
|
||||
response, err := resty.New().R().
|
||||
Get(suite.httpHoneypotHost + "/index.php")
|
||||
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal(http.StatusOK, response.StatusCode())
|
||||
suite.Equal("mocked response", string(response.Body()))
|
||||
|
||||
response, err = resty.New().R().
|
||||
Get(suite.httpHoneypotHost + "/wp-admin")
|
||||
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal(http.StatusBadRequest, response.StatusCode())
|
||||
suite.Equal("mocked response", string(response.Body()))
|
||||
}
|
||||
|
||||
func (suite *IntegrationTestSuite) TestInvokeTCPHoneypot() {
|
||||
tcpAddr, err := net.ResolveTCPAddr("tcp", suite.tcpHoneypotHost)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
conn, err := net.DialTCP("tcp", nil, tcpAddr)
|
||||
suite.Require().NoError(err)
|
||||
defer conn.Close()
|
||||
|
||||
_, err = conn.Write([]byte("hello!"))
|
||||
suite.Require().NoError(err)
|
||||
|
||||
reply := make([]byte, 1024)
|
||||
|
||||
n, err := conn.Read(reply)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("8.0.29\n", string(reply[:n]))
|
||||
}
|
||||
|
||||
func (suite *IntegrationTestSuite) TestInvokeSSHHoneypot() {
|
||||
client, err := goph.NewConn(
|
||||
&goph.Config{
|
||||
User: "root",
|
||||
Addr: suite.sshHoneypotHost,
|
||||
Port: 2222,
|
||||
Auth: goph.Password("root"),
|
||||
Callback: ssh.InsecureIgnoreHostKey(),
|
||||
})
|
||||
suite.Require().NoError(err)
|
||||
defer client.Close()
|
||||
|
||||
out, err := client.Run("")
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("root@ubuntu:~$ ", string(out))
|
||||
}
|
||||
|
||||
func (suite *IntegrationTestSuite) TestRabbitMQ() {
|
||||
conn, err := amqp.Dial(suite.rabbitMQURI)
|
||||
suite.Require().NoError(err)
|
||||
defer conn.Close()
|
||||
|
||||
ch, err := conn.Channel()
|
||||
suite.Require().NoError(err)
|
||||
defer ch.Close()
|
||||
|
||||
msgs, err := ch.Consume("event", "", true, false, false, false, nil)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
//Invoke HTTP Honeypot
|
||||
response, err := resty.New().R().Get(suite.httpHoneypotHost + "/index.php")
|
||||
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal(http.StatusOK, response.StatusCode())
|
||||
|
||||
for msg := range msgs {
|
||||
var event tracer.Event
|
||||
err := json.Unmarshal(msg.Body, &event)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.Equal("GET", event.HTTPMethod)
|
||||
suite.Equal("/index.php", event.RequestURI)
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
func (suite *IntegrationTestSuite) TestPrometheus() {
|
||||
//Invoke HTTP Honeypot
|
||||
response, err := resty.New().R().Get(suite.httpHoneypotHost + "/index.php")
|
||||
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal(http.StatusOK, response.StatusCode())
|
||||
|
||||
response, err = resty.New().R().Get(suite.prometheusHost)
|
||||
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal(http.StatusOK, response.StatusCode())
|
||||
}
|
||||
|
||||
func (suite *IntegrationTestSuite) TestShutdownBeelzebub() {
|
||||
suite.Require().NoError(suite.beelzebubBuilder.Close())
|
||||
}
|
120
main.go
120
main.go
@ -1,74 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"beelzebub/builder"
|
||||
"beelzebub/parser"
|
||||
"beelzebub/protocols"
|
||||
"beelzebub/tracer"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
var quit = make(chan struct{})
|
||||
|
||||
var channel *amqp.Channel
|
||||
|
||||
func main() {
|
||||
parser := parser.Init("./configurations/beelzebub.yaml", "./configurations/services/")
|
||||
var configurationsCorePath string
|
||||
var configurationsServicesDirectory string
|
||||
|
||||
flag.StringVar(&configurationsCorePath, "confCore", "./configurations/beelzebub.yaml", "Provide the path of configurations core")
|
||||
flag.StringVar(&configurationsServicesDirectory, "confServices", "./configurations/services/", "Directory config services")
|
||||
flag.Parse()
|
||||
|
||||
parser := parser.Init(configurationsCorePath, configurationsServicesDirectory)
|
||||
|
||||
coreConfigurations, err := parser.ReadConfigurationsCore()
|
||||
failOnError(err, fmt.Sprintf("Error during ReadConfigurationsCore: "))
|
||||
|
||||
fileLogs := configureLoggingByConfigurations(coreConfigurations.Core.Logging)
|
||||
defer fileLogs.Close()
|
||||
|
||||
beelzebubServicesConfiguration, err := parser.ReadConfigurationsServices()
|
||||
failOnError(err, fmt.Sprintf("Error during ReadConfigurationsServices: "))
|
||||
|
||||
if coreConfigurations.Core.Tracing.RabbitMQEnabled {
|
||||
rabbitMQURI, configured := os.LookupEnv("RABBITMQ_URI")
|
||||
if !configured {
|
||||
rabbitMQURI = coreConfigurations.Core.Tracing.RabbitMQURI
|
||||
}
|
||||
conn, err := amqp.Dial(rabbitMQURI)
|
||||
failOnError(err, "Failed to connect to RabbitMQ")
|
||||
defer conn.Close()
|
||||
beelzebubBuilder := builder.NewBuilder()
|
||||
|
||||
channel, err = conn.Channel()
|
||||
failOnError(err, "Failed to open a channel")
|
||||
defer channel.Close()
|
||||
}
|
||||
director := builder.NewDirector(beelzebubBuilder)
|
||||
|
||||
// Init Protocol strategies
|
||||
secureShellStrategy := &protocols.SecureShellStrategy{}
|
||||
hypertextTransferProtocolStrategy := &protocols.HypertextTransferProtocolStrategy{}
|
||||
transmissionControlProtocolStrategy := &protocols.TransmissionControlProtocolStrategy{}
|
||||
beelzebubBuilder, err = director.BuildBeelzebub(coreConfigurations, beelzebubServicesConfiguration)
|
||||
failOnError(err, fmt.Sprintf("Error during BuildBeelzebub: "))
|
||||
|
||||
// Init protocol manager, with simple log on stout trace strategy and default protocol HTTP
|
||||
protocolManager := protocols.InitProtocolManager(traceStrategyStdoutAndRabbitMQ, hypertextTransferProtocolStrategy)
|
||||
err = beelzebubBuilder.Run()
|
||||
failOnError(err, fmt.Sprintf("Error during run beelzebub core: "))
|
||||
|
||||
for _, beelzebubServiceConfiguration := range beelzebubServicesConfiguration {
|
||||
switch beelzebubServiceConfiguration.Protocol {
|
||||
case "http":
|
||||
protocolManager.SetProtocolStrategy(hypertextTransferProtocolStrategy)
|
||||
break
|
||||
case "ssh":
|
||||
protocolManager.SetProtocolStrategy(secureShellStrategy)
|
||||
break
|
||||
case "tcp":
|
||||
protocolManager.SetProtocolStrategy(transmissionControlProtocolStrategy)
|
||||
break
|
||||
default:
|
||||
log.Fatalf("Protocol %s not managed", beelzebubServiceConfiguration.Protocol)
|
||||
continue
|
||||
}
|
||||
defer beelzebubBuilder.Close()
|
||||
|
||||
err := protocolManager.InitService(beelzebubServiceConfiguration)
|
||||
failOnError(err, fmt.Sprintf("Error during init protocol: %s, ", beelzebubServiceConfiguration.Protocol))
|
||||
}
|
||||
<-quit
|
||||
}
|
||||
|
||||
@ -77,57 +47,3 @@ func failOnError(err error, msg string) {
|
||||
log.Fatalf("%s: %s", msg, err)
|
||||
}
|
||||
}
|
||||
|
||||
func traceStrategyStdoutAndRabbitMQ(event tracer.Event) {
|
||||
log.WithFields(log.Fields{
|
||||
"status": event.Status,
|
||||
"event": event,
|
||||
}).Info("New Event")
|
||||
|
||||
if channel != nil {
|
||||
log.Debug("Push Event on queue")
|
||||
eventJSON, err := json.Marshal(event)
|
||||
failOnError(err, "Failed to Marshal Event")
|
||||
|
||||
queue, err := channel.QueueDeclare(
|
||||
"event",
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
nil,
|
||||
)
|
||||
failOnError(err, "Failed to declare a queue")
|
||||
|
||||
err = channel.Publish(
|
||||
"",
|
||||
queue.Name,
|
||||
false,
|
||||
false,
|
||||
amqp.Publishing{
|
||||
ContentType: "application/json",
|
||||
Body: eventJSON,
|
||||
})
|
||||
failOnError(err, "Failed to publish a message")
|
||||
}
|
||||
}
|
||||
|
||||
func configureLoggingByConfigurations(configurations parser.Logging) *os.File {
|
||||
file, err := os.OpenFile(configurations.LogsPath, os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
|
||||
if err != nil {
|
||||
log.Fatalf("error opening file: %v", err)
|
||||
}
|
||||
|
||||
log.SetOutput(io.MultiWriter(os.Stdout, file))
|
||||
|
||||
log.SetFormatter(&log.JSONFormatter{
|
||||
DisableTimestamp: configurations.LogDisableTimestamp,
|
||||
})
|
||||
log.SetReportCaller(configurations.DebugReportCaller)
|
||||
if configurations.Debug {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
} else {
|
||||
log.SetLevel(log.InfoLevel)
|
||||
}
|
||||
return file
|
||||
}
|
||||
|
@ -2,17 +2,19 @@ package parser
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v3"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type BeelzebubCoreConfigurations struct {
|
||||
Core struct {
|
||||
Logging Logging `yaml:"logging"`
|
||||
Tracing Tracing `yaml:"tracing"`
|
||||
Prometheus Prometheus `yaml:"prometheus"`
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,6 +30,15 @@ type Tracing struct {
|
||||
RabbitMQURI string `yaml:"rabbitMQURI"`
|
||||
}
|
||||
|
||||
type Prometheus struct {
|
||||
Path string `yaml:"path"`
|
||||
Port string `yaml:"port"`
|
||||
}
|
||||
|
||||
type Plugin struct {
|
||||
OpenAPIChatGPTSecretKey string `yaml:"openAPIChatGPTSecretKey"`
|
||||
}
|
||||
|
||||
type BeelzebubServiceConfiguration struct {
|
||||
ApiVersion string `yaml:"apiVersion"`
|
||||
Protocol string `yaml:"protocol"`
|
||||
@ -39,6 +50,7 @@ type BeelzebubServiceConfiguration struct {
|
||||
PasswordRegex string `yaml:"passwordRegex"`
|
||||
Description string `yaml:"description"`
|
||||
Banner string `yaml:"banner"`
|
||||
Plugin Plugin `yaml:"plugin"`
|
||||
}
|
||||
|
||||
type Command struct {
|
||||
@ -46,6 +58,7 @@ type Command struct {
|
||||
Handler string `yaml:"handler"`
|
||||
Headers []string `yaml:"headers"`
|
||||
StatusCode int `yaml:"statusCode"`
|
||||
Plugin string `yaml:"plugin"`
|
||||
}
|
||||
|
||||
type configurationsParser struct {
|
116
plugins/openai-gpt.go
Normal file
116
plugins/openai-gpt.go
Normal file
@ -0,0 +1,116 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
const ChatGPTPluginName = "OpenAIGPTLinuxTerminal"
|
||||
const openAIGPTEndpoint = "https://api.openai.com/v1/completions"
|
||||
|
||||
type History struct {
|
||||
Input, Output string
|
||||
}
|
||||
|
||||
type OpenAIGPTVirtualTerminal struct {
|
||||
Histories []History
|
||||
OpenAPIChatGPTSecretKey string
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func (openAIGPTVirtualTerminal *OpenAIGPTVirtualTerminal) InjectDependency() {
|
||||
if openAIGPTVirtualTerminal.client == nil {
|
||||
openAIGPTVirtualTerminal.client = resty.New()
|
||||
}
|
||||
}
|
||||
|
||||
type Choice struct {
|
||||
Text string `json:"text"`
|
||||
Index int `json:"index"`
|
||||
Logprobs interface{} `json:"logprobs"`
|
||||
FinishReason string `json:"finish_reason"`
|
||||
}
|
||||
|
||||
type gptResponse struct {
|
||||
ID string `json:"id"`
|
||||
Object string `json:"object"`
|
||||
Created int `json:"created"`
|
||||
Model string `json:"model"`
|
||||
Choices []Choice `json:"choices"`
|
||||
Usage struct {
|
||||
PromptTokens int `json:"prompt_tokens"`
|
||||
CompletionTokens int `json:"completion_tokens"`
|
||||
TotalTokens int `json:"total_tokens"`
|
||||
} `json:"usage"`
|
||||
}
|
||||
|
||||
type gptRequest struct {
|
||||
Model string `json:"model"`
|
||||
Prompt string `json:"prompt"`
|
||||
Temperature int `json:"temperature"`
|
||||
MaxTokens int `json:"max_tokens"`
|
||||
TopP int `json:"top_p"`
|
||||
FrequencyPenalty int `json:"frequency_penalty"`
|
||||
PresencePenalty int `json:"presence_penalty"`
|
||||
Stop []string `json:"stop"`
|
||||
}
|
||||
|
||||
// Reference: https://www.engraved.blog/building-a-virtual-machine-inside/
|
||||
const promptVirtualizeLinuxTerminal = "I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do no write explanations. Do not type commands unless I instruct you to do so.\n\nA:pwd\n\nQ:/home/user\n\n"
|
||||
|
||||
func buildPrompt(histories []History, command string) string {
|
||||
var sb strings.Builder
|
||||
|
||||
sb.WriteString(promptVirtualizeLinuxTerminal)
|
||||
|
||||
for _, history := range histories {
|
||||
sb.WriteString(fmt.Sprintf("A:%s\n\nQ:%s\n\n", history.Input, history.Output))
|
||||
}
|
||||
// Append command to evaluate
|
||||
sb.WriteString(fmt.Sprintf("A:%s\n\nQ:", command))
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func (openAIGPTVirtualTerminal *OpenAIGPTVirtualTerminal) GetCompletions(command string) (string, error) {
|
||||
requestJson, err := json.Marshal(gptRequest{
|
||||
Model: "text-davinci-003",
|
||||
Prompt: buildPrompt(openAIGPTVirtualTerminal.Histories, command),
|
||||
Temperature: 0,
|
||||
MaxTokens: 100,
|
||||
TopP: 1,
|
||||
FrequencyPenalty: 0,
|
||||
PresencePenalty: 0,
|
||||
Stop: []string{"\n"},
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if openAIGPTVirtualTerminal.OpenAPIChatGPTSecretKey == "" {
|
||||
return "", errors.New("OpenAPIChatGPTSecretKey is empty")
|
||||
}
|
||||
|
||||
response, err := openAIGPTVirtualTerminal.client.R().
|
||||
SetHeader("Content-Type", "application/json").
|
||||
SetBody(requestJson).
|
||||
SetAuthToken(openAIGPTVirtualTerminal.OpenAPIChatGPTSecretKey).
|
||||
SetResult(&gptResponse{}).
|
||||
Post(openAIGPTEndpoint)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
log.Debug(response)
|
||||
if len(response.Result().(*gptResponse).Choices) == 0 {
|
||||
return "", errors.New("no choices")
|
||||
}
|
||||
|
||||
return response.Result().(*gptResponse).Choices[0].Text, nil
|
||||
}
|
82
plugins/openai-gpt_test.go
Normal file
82
plugins/openai-gpt_test.go
Normal file
@ -0,0 +1,82 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/jarcoal/httpmock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBuildPromptEmptyHistory(t *testing.T) {
|
||||
//Given
|
||||
var histories []History
|
||||
command := "pwd"
|
||||
|
||||
//When
|
||||
prompt := buildPrompt(histories, command)
|
||||
|
||||
//Then
|
||||
assert.Equal(t,
|
||||
"I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do no write explanations. Do not type commands unless I instruct you to do so.\n\nA:pwd\n\nQ:/home/user\n\nA:pwd\n\nQ:",
|
||||
prompt)
|
||||
}
|
||||
|
||||
func TestBuildPromptWithHistory(t *testing.T) {
|
||||
//Given
|
||||
var histories = []History{
|
||||
{
|
||||
Input: "cat hello.txt",
|
||||
Output: "world",
|
||||
},
|
||||
{
|
||||
Input: "echo 1234",
|
||||
Output: "1234",
|
||||
},
|
||||
}
|
||||
|
||||
command := "pwd"
|
||||
|
||||
//When
|
||||
prompt := buildPrompt(histories, command)
|
||||
|
||||
//Then
|
||||
assert.Equal(t,
|
||||
"I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do no write explanations. Do not type commands unless I instruct you to do so.\n\nA:pwd\n\nQ:/home/user\n\nA:cat hello.txt\n\nQ:world\n\nA:echo 1234\n\nQ:1234\n\nA:pwd\n\nQ:",
|
||||
prompt)
|
||||
}
|
||||
|
||||
func TestBuildGetCompletions(t *testing.T) {
|
||||
client := resty.New()
|
||||
httpmock.ActivateNonDefault(client.GetClient())
|
||||
defer httpmock.DeactivateAndReset()
|
||||
|
||||
// Given
|
||||
httpmock.RegisterResponder("POST", openAIGPTEndpoint,
|
||||
func(req *http.Request) (*http.Response, error) {
|
||||
resp, err := httpmock.NewJsonResponse(200, &gptResponse{
|
||||
Choices: []Choice{
|
||||
{
|
||||
Text: "prova.txt",
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return httpmock.NewStringResponse(500, ""), nil
|
||||
}
|
||||
return resp, nil
|
||||
},
|
||||
)
|
||||
|
||||
openAIGPTVirtualTerminal := OpenAIGPTVirtualTerminal{
|
||||
OpenAPIChatGPTSecretKey: "sdjdnklfjndslkjanfk",
|
||||
client: client,
|
||||
}
|
||||
|
||||
//When
|
||||
str, err := openAIGPTVirtualTerminal.GetCompletions("ls")
|
||||
|
||||
//Then
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "prova.txt", str)
|
||||
}
|
@ -1,22 +1,23 @@
|
||||
package protocols
|
||||
package strategies
|
||||
|
||||
import (
|
||||
"beelzebub/parser"
|
||||
"beelzebub/tracer"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type HypertextTransferProtocolStrategy struct {
|
||||
type HTTPStrategy struct {
|
||||
beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration
|
||||
}
|
||||
|
||||
func (httpStrategy HypertextTransferProtocolStrategy) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error {
|
||||
func (httpStrategy HTTPStrategy) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error {
|
||||
httpStrategy.beelzebubServiceConfiguration = beelzebubServiceConfiguration
|
||||
serverMux := http.NewServeMux()
|
||||
|
||||
@ -47,7 +48,7 @@ func (httpStrategy HypertextTransferProtocolStrategy) Init(beelzebubServiceConfi
|
||||
log.WithFields(log.Fields{
|
||||
"port": beelzebubServiceConfiguration.Address,
|
||||
"commands": len(beelzebubServiceConfiguration.Commands),
|
||||
}).Infof("Init service %s", beelzebubServiceConfiguration.Protocol)
|
||||
}).Infof("Init service: %s", beelzebubServiceConfiguration.Description)
|
||||
return nil
|
||||
}
|
||||
|
@ -1,22 +1,24 @@
|
||||
package protocols
|
||||
package strategies
|
||||
|
||||
import (
|
||||
"beelzebub/parser"
|
||||
"beelzebub/plugins"
|
||||
"beelzebub/tracer"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gliderlabs/ssh"
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SecureShellStrategy struct {
|
||||
type SSHStrategy struct {
|
||||
}
|
||||
|
||||
func (SSHStrategy *SecureShellStrategy) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error {
|
||||
func (sshStrategy *SSHStrategy) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error {
|
||||
go func() {
|
||||
server := &ssh.Server{
|
||||
Addr: beelzebubServiceConfiguration.Address,
|
||||
@ -39,20 +41,13 @@ func (SSHStrategy *SecureShellStrategy) Init(beelzebubServiceConfiguration parse
|
||||
})
|
||||
|
||||
term := terminal.NewTerminal(sess, buildPrompt(sess.User(), beelzebubServiceConfiguration.ServerName))
|
||||
var histories []plugins.History
|
||||
for {
|
||||
commandInput, err := term.ReadLine()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
tr.TraceEvent(tracer.Event{
|
||||
Msg: "New SSH Terminal Session",
|
||||
RemoteAddr: sess.RemoteAddr().String(),
|
||||
Status: tracer.Interaction.String(),
|
||||
Command: commandInput,
|
||||
ID: uuidSession.String(),
|
||||
Protocol: tracer.SSH.String(),
|
||||
Description: beelzebubServiceConfiguration.Description,
|
||||
})
|
||||
|
||||
if commandInput == "exit" {
|
||||
break
|
||||
}
|
||||
@ -64,7 +59,32 @@ func (SSHStrategy *SecureShellStrategy) Init(beelzebubServiceConfiguration parse
|
||||
}
|
||||
|
||||
if matched {
|
||||
term.Write(append([]byte(command.Handler), '\n'))
|
||||
commandOutput := command.Handler
|
||||
|
||||
if command.Plugin == plugins.ChatGPTPluginName {
|
||||
openAIGPTVirtualTerminal := plugins.OpenAIGPTVirtualTerminal{Histories: histories, OpenAPIChatGPTSecretKey: beelzebubServiceConfiguration.Plugin.OpenAPIChatGPTSecretKey}
|
||||
openAIGPTVirtualTerminal.InjectDependency()
|
||||
|
||||
if commandOutput, err = openAIGPTVirtualTerminal.GetCompletions(commandInput); err != nil {
|
||||
log.Errorf("Error GetCompletions: %s, %s", commandInput, err.Error())
|
||||
commandOutput = "command not found"
|
||||
}
|
||||
}
|
||||
|
||||
histories = append(histories, plugins.History{Input: commandInput, Output: commandOutput})
|
||||
|
||||
term.Write(append([]byte(commandOutput), '\n'))
|
||||
|
||||
tr.TraceEvent(tracer.Event{
|
||||
Msg: "New SSH Terminal Session",
|
||||
RemoteAddr: sess.RemoteAddr().String(),
|
||||
Status: tracer.Interaction.String(),
|
||||
Command: commandInput,
|
||||
CommandOutput: commandOutput,
|
||||
ID: uuidSession.String(),
|
||||
Protocol: tracer.SSH.String(),
|
||||
Description: beelzebubServiceConfiguration.Description,
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
@ -1,19 +1,20 @@
|
||||
package protocols
|
||||
package strategies
|
||||
|
||||
import (
|
||||
"beelzebub/parser"
|
||||
"beelzebub/tracer"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type TransmissionControlProtocolStrategy struct {
|
||||
type TCPStrategy struct {
|
||||
}
|
||||
|
||||
func (TCPStrategy *TransmissionControlProtocolStrategy) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error {
|
||||
func (tcpStrategy *TCPStrategy) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error {
|
||||
listen, err := net.Listen("tcp", beelzebubServiceConfiguration.Address)
|
||||
if err != nil {
|
||||
log.Errorf("Error during init TCP Protocol: %s", err.Error())
|
17
pull_request_template.md
Normal file
17
pull_request_template.md
Normal file
@ -0,0 +1,17 @@
|
||||
All Submissions:
|
||||
|
||||
* [ ] Have you followed the guidelines in our Contributing document?
|
||||
* [ ] Have you checked to ensure there aren't other open [Pull Requests](../../pulls) for the same update/change?
|
||||
|
||||
<!-- You can erase any parts of this template not applicable to your Pull Request. -->
|
||||
|
||||
### New Feature Submissions:
|
||||
|
||||
1. [ ] Does your submission pass tests?
|
||||
2. [ ] Have you lint your code locally before submission?
|
||||
|
||||
### Changes to Core Features:
|
||||
|
||||
* [ ] Have you added an explanation of what your changes do and why you'd like us to include them?
|
||||
* [ ] Have you written new tests for your core changes, as applicable?
|
||||
* [ ] Have you successfully run tests with your changes locally?
|
@ -2,34 +2,17 @@ package tracer
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
type Strategy func(event Event)
|
||||
|
||||
type Tracer interface {
|
||||
TraceEvent(event Event)
|
||||
}
|
||||
|
||||
type tracer struct {
|
||||
strategy Strategy
|
||||
}
|
||||
|
||||
func Init(strategy Strategy) *tracer {
|
||||
return &tracer{
|
||||
strategy: strategy,
|
||||
}
|
||||
}
|
||||
|
||||
func (tracer *tracer) TraceEvent(event Event) {
|
||||
event.DateTime = time.Now().UTC().Format(time.RFC3339)
|
||||
tracer.strategy(event)
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
DateTime string
|
||||
RemoteAddr string
|
||||
Protocol string
|
||||
Command string
|
||||
CommandOutput string
|
||||
Status string
|
||||
Msg string
|
||||
ID string
|
||||
@ -71,3 +54,63 @@ const (
|
||||
func (status Status) String() string {
|
||||
return [...]string{"Start", "End", "Stateless", "Interaction"}[status]
|
||||
}
|
||||
|
||||
type Strategy func(event Event)
|
||||
|
||||
type Tracer interface {
|
||||
TraceEvent(event Event)
|
||||
}
|
||||
|
||||
type tracer struct {
|
||||
strategy Strategy
|
||||
}
|
||||
|
||||
var (
|
||||
eventsTotal = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: "beelzebub",
|
||||
Name: "events_total",
|
||||
Help: "The total number of events",
|
||||
})
|
||||
eventsSSHTotal = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: "beelzebub",
|
||||
Name: "ssh_events_total",
|
||||
Help: "The total number of SSH events",
|
||||
})
|
||||
eventsTCPTotal = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: "beelzebub",
|
||||
Name: "tcp_events_total",
|
||||
Help: "The total number of TCP events",
|
||||
})
|
||||
eventsHTTPTotal = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: "beelzebub",
|
||||
Name: "http_events_total",
|
||||
Help: "The total number of HTTP events",
|
||||
})
|
||||
)
|
||||
|
||||
func Init(strategy Strategy) *tracer {
|
||||
return &tracer{
|
||||
strategy: strategy,
|
||||
}
|
||||
}
|
||||
|
||||
func (tracer *tracer) TraceEvent(event Event) {
|
||||
event.DateTime = time.Now().UTC().Format(time.RFC3339)
|
||||
|
||||
tracer.strategy(event)
|
||||
|
||||
//Openmetrics
|
||||
eventsTotal.Inc()
|
||||
|
||||
switch event.Protocol {
|
||||
case HTTP.String():
|
||||
eventsHTTPTotal.Inc()
|
||||
break
|
||||
case SSH.String():
|
||||
eventsSSHTotal.Inc()
|
||||
break
|
||||
case TCP.String():
|
||||
eventsTCPTotal.Inc()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user