mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
933f02911b | |||
ef07ca1203 | |||
1f59685530 | |||
f658a26b32 | |||
3fb8a667b3 |
4
.github/workflows/codeql.yml
vendored
4
.github/workflows/codeql.yml
vendored
@ -27,7 +27,7 @@ jobs:
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
|
||||
@ -35,6 +35,6 @@ jobs:
|
||||
run: go build ./...
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
uses: github/codeql-action/analyze@v3
|
||||
with:
|
||||
category: "/language:${{matrix.language}}"
|
||||
|
21
.github/workflows/docker-image.yml
vendored
21
.github/workflows/docker-image.yml
vendored
@ -1,31 +1,32 @@
|
||||
---
|
||||
name: Docker Hub Image
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*.*.*'
|
||||
|
||||
jobs:
|
||||
CD:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
-
|
||||
name: Login to Docker Hub
|
||||
- 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
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
-
|
||||
name: Build and push
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
tags: m4r10/beelzebub:${{ github.ref_name }}
|
||||
tags: |
|
||||
m4r10/beelzebub:${{ github.ref_name }}
|
||||
m4r10/beelzebub:latest
|
||||
platforms: linux/amd64,linux/arm64
|
||||
|
@ -22,5 +22,5 @@ commands:
|
||||
plugin: "LLMHoneypot"
|
||||
statusCode: 200
|
||||
plugin:
|
||||
llmModel: "gpt4-o"
|
||||
llmModel: "gpt-4o"
|
||||
openAISecretKey: "sk-proj-123456"
|
@ -15,5 +15,6 @@ services:
|
||||
- "2112:2112" #Prometheus Open Metrics
|
||||
environment:
|
||||
RABBITMQ_URI: ${RABBITMQ_URI}
|
||||
OPEN_AI_SECRET_KEY: ${OPEN_AI_SECRET_KEY}
|
||||
volumes:
|
||||
- "./configurations:/configurations"
|
@ -67,8 +67,11 @@ func (suite *IntegrationTestSuite) TestInvokeHTTPHoneypot() {
|
||||
response, err := resty.New().R().
|
||||
Get(suite.httpHoneypotHost + "/index.php")
|
||||
|
||||
response.Header().Del("Date")
|
||||
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal(http.StatusOK, response.StatusCode())
|
||||
suite.Equal(http.Header{"Content-Length": []string{"15"}, "Content-Type": []string{"text/html"}, "Server": []string{"Apache/2.4.53 (Debian)"}, "X-Powered-By": []string{"PHP/7.4.29"}}, response.Header())
|
||||
suite.Equal("mocked response", string(response.Body()))
|
||||
|
||||
response, err = resty.New().R().
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"github.com/go-resty/resty/v2"
|
||||
"github.com/mariocandela/beelzebub/v3/tracer"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
@ -95,6 +96,10 @@ func InitLLMHoneypot(config LLMHoneypot) *LLMHoneypot {
|
||||
// Inject the dependencies
|
||||
config.client = resty.New()
|
||||
|
||||
if os.Getenv("OPEN_AI_SECRET_KEY") != "" {
|
||||
config.OpenAIKey = os.Getenv("OPEN_AI_SECRET_KEY")
|
||||
}
|
||||
|
||||
return &config
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"github.com/mariocandela/beelzebub/v3/tracer"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -85,7 +86,7 @@ func TestBuildExecuteModelFailValidation(t *testing.T) {
|
||||
Histories: make([]Message, 0),
|
||||
OpenAIKey: "",
|
||||
Protocol: tracer.SSH,
|
||||
Model: "gpt4-o",
|
||||
Model: "gpt-4o",
|
||||
Provider: OpenAI,
|
||||
}
|
||||
|
||||
@ -96,6 +97,24 @@ func TestBuildExecuteModelFailValidation(t *testing.T) {
|
||||
assert.Equal(t, "openAIKey is empty", err.Error())
|
||||
}
|
||||
|
||||
func TestBuildExecuteModelOpenAISecretKeyFromEnv(t *testing.T) {
|
||||
|
||||
llmHoneypot := LLMHoneypot{
|
||||
Histories: make([]Message, 0),
|
||||
OpenAIKey: "",
|
||||
Protocol: tracer.SSH,
|
||||
Model: "gpt-4o",
|
||||
Provider: OpenAI,
|
||||
}
|
||||
|
||||
os.Setenv("OPEN_AI_SECRET_KEY", "sdjdnklfjndslkjanfk")
|
||||
|
||||
openAIGPTVirtualTerminal := InitLLMHoneypot(llmHoneypot)
|
||||
|
||||
assert.Equal(t, "sdjdnklfjndslkjanfk", openAIGPTVirtualTerminal.OpenAIKey)
|
||||
|
||||
}
|
||||
|
||||
func TestBuildExecuteModelWithCustomPrompt(t *testing.T) {
|
||||
client := resty.New()
|
||||
httpmock.ActivateNonDefault(client.GetClient())
|
||||
@ -126,7 +145,7 @@ func TestBuildExecuteModelWithCustomPrompt(t *testing.T) {
|
||||
Histories: make([]Message, 0),
|
||||
OpenAIKey: "sdjdnklfjndslkjanfk",
|
||||
Protocol: tracer.HTTP,
|
||||
Model: "gpt4-o",
|
||||
Model: "gpt-4o",
|
||||
Provider: OpenAI,
|
||||
CustomPrompt: "hello world",
|
||||
}
|
||||
@ -148,7 +167,7 @@ func TestBuildExecuteModelFailValidationStrategyType(t *testing.T) {
|
||||
Histories: make([]Message, 0),
|
||||
OpenAIKey: "",
|
||||
Protocol: tracer.TCP,
|
||||
Model: "gpt4-o",
|
||||
Model: "gpt-4o",
|
||||
Provider: OpenAI,
|
||||
}
|
||||
|
||||
@ -206,7 +225,7 @@ func TestBuildExecuteModelSSHWithResultsOpenAI(t *testing.T) {
|
||||
Histories: make([]Message, 0),
|
||||
OpenAIKey: "sdjdnklfjndslkjanfk",
|
||||
Protocol: tracer.SSH,
|
||||
Model: "gpt4-o",
|
||||
Model: "gpt-4o",
|
||||
Provider: OpenAI,
|
||||
}
|
||||
|
||||
@ -282,7 +301,7 @@ func TestBuildExecuteModelSSHWithoutResults(t *testing.T) {
|
||||
Histories: make([]Message, 0),
|
||||
OpenAIKey: "sdjdnklfjndslkjanfk",
|
||||
Protocol: tracer.SSH,
|
||||
Model: "gpt4-o",
|
||||
Model: "gpt-4o",
|
||||
Provider: OpenAI,
|
||||
}
|
||||
|
||||
@ -325,7 +344,7 @@ func TestBuildExecuteModelHTTPWithResults(t *testing.T) {
|
||||
Histories: make([]Message, 0),
|
||||
OpenAIKey: "sdjdnklfjndslkjanfk",
|
||||
Protocol: tracer.HTTP,
|
||||
Model: "gpt4-o",
|
||||
Model: "gpt-4o",
|
||||
Provider: OpenAI,
|
||||
}
|
||||
|
||||
@ -362,7 +381,7 @@ func TestBuildExecuteModelHTTPWithoutResults(t *testing.T) {
|
||||
Histories: make([]Message, 0),
|
||||
OpenAIKey: "sdjdnklfjndslkjanfk",
|
||||
Protocol: tracer.HTTP,
|
||||
Model: "gpt4-o",
|
||||
Model: "gpt-4o",
|
||||
Provider: OpenAI,
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ func traceRequest(request *http.Request, tr tracer.Tracer, HoneypotDescription s
|
||||
HostHTTPRequest: request.Host,
|
||||
UserAgent: request.UserAgent(),
|
||||
Cookies: mapCookiesToString(request.Cookies()),
|
||||
Headers: mapHeaderToString(request.Header),
|
||||
Headers: request.Header,
|
||||
Status: tracer.Stateless.String(),
|
||||
RemoteAddr: request.RemoteAddr,
|
||||
SourceIp: host,
|
||||
@ -133,18 +133,6 @@ func traceRequest(request *http.Request, tr tracer.Tracer, HoneypotDescription s
|
||||
tr.TraceEvent(event)
|
||||
}
|
||||
|
||||
func mapHeaderToString(headers http.Header) string {
|
||||
headersString := ""
|
||||
|
||||
for key := range headers {
|
||||
for _, values := range headers[key] {
|
||||
headersString += fmt.Sprintf("[Key: %s, values: %s],", key, values)
|
||||
}
|
||||
}
|
||||
|
||||
return headersString
|
||||
}
|
||||
|
||||
func mapCookiesToString(cookies []*http.Cookie) string {
|
||||
cookiesString := ""
|
||||
|
||||
|
@ -13,13 +13,15 @@ import (
|
||||
"github.com/gliderlabs/ssh"
|
||||
"github.com/google/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
type SSHStrategy struct {
|
||||
Sessions map[string][]plugins.Message
|
||||
}
|
||||
|
||||
func (sshStrategy *SSHStrategy) Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tr tracer.Tracer) error {
|
||||
sshStrategy.Sessions = make(map[string][]plugins.Message)
|
||||
go func() {
|
||||
server := &ssh.Server{
|
||||
Addr: beelzebubServiceConfiguration.Address,
|
||||
@ -30,7 +32,9 @@ func (sshStrategy *SSHStrategy) Init(beelzebubServiceConfiguration parser.Beelze
|
||||
uuidSession := uuid.New()
|
||||
|
||||
host, port, _ := net.SplitHostPort(sess.RemoteAddr().String())
|
||||
sessionKey := host + sess.User()
|
||||
|
||||
// Inline SSH command
|
||||
if sess.RawCommand() != "" {
|
||||
for _, command := range beelzebubServiceConfiguration.Commands {
|
||||
matched, err := regexp.MatchString(command.Regex, sess.RawCommand())
|
||||
@ -52,8 +56,14 @@ func (sshStrategy *SSHStrategy) Init(beelzebubServiceConfiguration parser.Beelze
|
||||
llmProvider = plugins.OpenAI
|
||||
}
|
||||
|
||||
histories := make([]plugins.Message, 0)
|
||||
|
||||
if sshStrategy.Sessions[sessionKey] != nil {
|
||||
histories = sshStrategy.Sessions[sessionKey]
|
||||
}
|
||||
|
||||
llmHoneypot := plugins.LLMHoneypot{
|
||||
Histories: make([]plugins.Message, 0),
|
||||
Histories: histories,
|
||||
OpenAIKey: beelzebubServiceConfiguration.Plugin.OpenAISecretKey,
|
||||
Protocol: tracer.SSH,
|
||||
Host: beelzebubServiceConfiguration.Plugin.Host,
|
||||
@ -86,6 +96,10 @@ func (sshStrategy *SSHStrategy) Init(beelzebubServiceConfiguration parser.Beelze
|
||||
Command: sess.RawCommand(),
|
||||
CommandOutput: commandOutput,
|
||||
})
|
||||
var histories []plugins.Message
|
||||
histories = append(histories, plugins.Message{Role: plugins.USER.String(), Content: sess.RawCommand()})
|
||||
histories = append(histories, plugins.Message{Role: plugins.ASSISTANT.String(), Content: commandOutput})
|
||||
sshStrategy.Sessions[sessionKey] = histories
|
||||
tr.TraceEvent(tracer.Event{
|
||||
Msg: "End SSH Session",
|
||||
Status: tracer.End.String(),
|
||||
@ -109,10 +123,14 @@ func (sshStrategy *SSHStrategy) Init(beelzebubServiceConfiguration parser.Beelze
|
||||
Description: beelzebubServiceConfiguration.Description,
|
||||
})
|
||||
|
||||
term := terminal.NewTerminal(sess, buildPrompt(sess.User(), beelzebubServiceConfiguration.ServerName))
|
||||
terminal := term.NewTerminal(sess, buildPrompt(sess.User(), beelzebubServiceConfiguration.ServerName))
|
||||
var histories []plugins.Message
|
||||
if sshStrategy.Sessions[sessionKey] != nil {
|
||||
histories = sshStrategy.Sessions[sessionKey]
|
||||
}
|
||||
|
||||
for {
|
||||
commandInput, err := term.ReadLine()
|
||||
commandInput, err := terminal.ReadLine()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
@ -160,7 +178,7 @@ func (sshStrategy *SSHStrategy) Init(beelzebubServiceConfiguration parser.Beelze
|
||||
histories = append(histories, plugins.Message{Role: plugins.USER.String(), Content: commandInput})
|
||||
histories = append(histories, plugins.Message{Role: plugins.ASSISTANT.String(), Content: commandOutput})
|
||||
|
||||
term.Write(append([]byte(commandOutput), '\n'))
|
||||
terminal.Write(append([]byte(commandOutput), '\n'))
|
||||
|
||||
tr.TraceEvent(tracer.Event{
|
||||
Msg: "New SSH Terminal Session",
|
||||
@ -178,6 +196,7 @@ func (sshStrategy *SSHStrategy) Init(beelzebubServiceConfiguration parser.Beelze
|
||||
}
|
||||
}
|
||||
}
|
||||
sshStrategy.Sessions[sessionKey] = histories
|
||||
tr.TraceEvent(tracer.Event{
|
||||
Msg: "End SSH Session",
|
||||
Status: tracer.End.String(),
|
||||
|
@ -27,7 +27,7 @@ type Event struct {
|
||||
User string
|
||||
Password string
|
||||
Client string
|
||||
Headers string
|
||||
Headers map[string][]string
|
||||
Cookies string
|
||||
UserAgent string
|
||||
HostHTTPRequest string
|
||||
|
Reference in New Issue
Block a user