mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
* implement new feature, custom prompt * Add doc for custom prompt
This commit is contained in:
19
README.md
19
README.md
@ -250,6 +250,25 @@ plugin:
|
|||||||
llmModel: "llama3"
|
llmModel: "llama3"
|
||||||
host: "http://example.com/api/chat" #default http://localhost:11434/api/chat
|
host: "http://example.com/api/chat" #default http://localhost:11434/api/chat
|
||||||
```
|
```
|
||||||
|
Example with custom prompt:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: "v1"
|
||||||
|
protocol: "ssh"
|
||||||
|
address: ":2222"
|
||||||
|
description: "SSH interactive OpenAI GPT-4"
|
||||||
|
commands:
|
||||||
|
- regex: "^(.+)$"
|
||||||
|
plugin: "LLMHoneypot"
|
||||||
|
serverVersion: "OpenSSH"
|
||||||
|
serverName: "ubuntu"
|
||||||
|
passwordRegex: "^(root|qwerty|Smoker666|123456|jenkins|minecraft|sinus|alex|postgres|Ly123456)$"
|
||||||
|
deadlineTimeoutSeconds: 60
|
||||||
|
plugin:
|
||||||
|
llmModel: "gpt4-o"
|
||||||
|
openAISecretKey: "sk-proj-123456"
|
||||||
|
prompt: "You will act as an Ubuntu Linux terminal. The user will type commands, and you are to reply with what the terminal should show. Your responses must be contained within a single code block."
|
||||||
|
```
|
||||||
|
|
||||||
###### SSH Honeypot on Port 22
|
###### SSH Honeypot on Port 22
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ type Plugin struct {
|
|||||||
OpenAISecretKey string `yaml:"openAISecretKey"`
|
OpenAISecretKey string `yaml:"openAISecretKey"`
|
||||||
Host string `yaml:"host"`
|
Host string `yaml:"host"`
|
||||||
LLMModel string `yaml:"llmModel"`
|
LLMModel string `yaml:"llmModel"`
|
||||||
|
Prompt string `yaml:"prompt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BeelzebubServiceConfiguration is the struct that contains the configurations of the honeypot service
|
// BeelzebubServiceConfiguration is the struct that contains the configurations of the honeypot service
|
||||||
|
@ -58,6 +58,7 @@ plugin:
|
|||||||
openAISecretKey: "qwerty"
|
openAISecretKey: "qwerty"
|
||||||
llmModel: "llama3"
|
llmModel: "llama3"
|
||||||
host: "localhost:1563"
|
host: "localhost:1563"
|
||||||
|
prompt: "hello world"
|
||||||
`)
|
`)
|
||||||
return beelzebubServiceConfiguration, nil
|
return beelzebubServiceConfiguration, nil
|
||||||
}
|
}
|
||||||
@ -133,6 +134,7 @@ func TestReadConfigurationsServicesValid(t *testing.T) {
|
|||||||
assert.Equal(t, firstBeelzebubServiceConfiguration.Plugin.OpenAISecretKey, "qwerty")
|
assert.Equal(t, firstBeelzebubServiceConfiguration.Plugin.OpenAISecretKey, "qwerty")
|
||||||
assert.Equal(t, firstBeelzebubServiceConfiguration.Plugin.LLMModel, "llama3")
|
assert.Equal(t, firstBeelzebubServiceConfiguration.Plugin.LLMModel, "llama3")
|
||||||
assert.Equal(t, firstBeelzebubServiceConfiguration.Plugin.Host, "localhost:1563")
|
assert.Equal(t, firstBeelzebubServiceConfiguration.Plugin.Host, "localhost:1563")
|
||||||
|
assert.Equal(t, firstBeelzebubServiceConfiguration.Plugin.Prompt, "hello world")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGelAllFilesNameByDirName(t *testing.T) {
|
func TestGelAllFilesNameByDirName(t *testing.T) {
|
||||||
|
@ -25,6 +25,7 @@ type LLMHoneypot struct {
|
|||||||
Protocol tracer.Protocol
|
Protocol tracer.Protocol
|
||||||
Model LLMModel
|
Model LLMModel
|
||||||
Host string
|
Host string
|
||||||
|
CustomPrompt string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Choice struct {
|
type Choice struct {
|
||||||
@ -211,8 +212,20 @@ func (llmHoneypot *LLMHoneypot) ollamaCaller(messages []Message) (string, error)
|
|||||||
|
|
||||||
func (llmHoneypot *LLMHoneypot) ExecuteModel(command string) (string, error) {
|
func (llmHoneypot *LLMHoneypot) ExecuteModel(command string) (string, error) {
|
||||||
var err error
|
var err error
|
||||||
|
var prompt []Message
|
||||||
|
|
||||||
prompt, err := buildPrompt(llmHoneypot.Histories, llmHoneypot.Protocol, command)
|
if llmHoneypot.CustomPrompt != "" {
|
||||||
|
prompt = append(prompt, Message{
|
||||||
|
Role: SYSTEM.String(),
|
||||||
|
Content: llmHoneypot.CustomPrompt,
|
||||||
|
})
|
||||||
|
prompt = append(prompt, Message{
|
||||||
|
Role: USER.String(),
|
||||||
|
Content: command,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
prompt, err = buildPrompt(llmHoneypot.Histories, llmHoneypot.Protocol, command)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -59,6 +59,51 @@ func TestBuildExecuteModelFailValidation(t *testing.T) {
|
|||||||
assert.Equal(t, "openAIKey is empty", err.Error())
|
assert.Equal(t, "openAIKey is empty", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildExecuteModelWithCustomPrompt(t *testing.T) {
|
||||||
|
client := resty.New()
|
||||||
|
httpmock.ActivateNonDefault(client.GetClient())
|
||||||
|
defer httpmock.DeactivateAndReset()
|
||||||
|
|
||||||
|
// Given
|
||||||
|
httpmock.RegisterMatcherResponder("POST", openAIGPTEndpoint,
|
||||||
|
httpmock.BodyContainsString("hello world"),
|
||||||
|
func(req *http.Request) (*http.Response, error) {
|
||||||
|
resp, err := httpmock.NewJsonResponse(200, &Response{
|
||||||
|
Choices: []Choice{
|
||||||
|
{
|
||||||
|
Message: Message{
|
||||||
|
Role: SYSTEM.String(),
|
||||||
|
Content: "[default]\nregion = us-west-2\noutput = json",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return httpmock.NewStringResponse(500, ""), nil
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
llmHoneypot := LLMHoneypot{
|
||||||
|
Histories: make([]Message, 0),
|
||||||
|
OpenAIKey: "sdjdnklfjndslkjanfk",
|
||||||
|
Protocol: tracer.HTTP,
|
||||||
|
Model: GPT4O,
|
||||||
|
CustomPrompt: "hello world",
|
||||||
|
}
|
||||||
|
|
||||||
|
openAIGPTVirtualTerminal := InitLLMHoneypot(llmHoneypot)
|
||||||
|
openAIGPTVirtualTerminal.client = client
|
||||||
|
|
||||||
|
//When
|
||||||
|
str, err := openAIGPTVirtualTerminal.ExecuteModel("GET /.aws/credentials")
|
||||||
|
|
||||||
|
//Then
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, "[default]\nregion = us-west-2\noutput = json", str)
|
||||||
|
}
|
||||||
|
|
||||||
func TestBuildExecuteModelFailValidationStrategyType(t *testing.T) {
|
func TestBuildExecuteModelFailValidationStrategyType(t *testing.T) {
|
||||||
|
|
||||||
llmHoneypot := LLMHoneypot{
|
llmHoneypot := LLMHoneypot{
|
||||||
|
@ -50,6 +50,7 @@ func (httpStrategy HTTPStrategy) Init(beelzebubServiceConfiguration parser.Beelz
|
|||||||
Protocol: tracer.HTTP,
|
Protocol: tracer.HTTP,
|
||||||
Host: beelzebubServiceConfiguration.Plugin.Host,
|
Host: beelzebubServiceConfiguration.Plugin.Host,
|
||||||
Model: llmModel,
|
Model: llmModel,
|
||||||
|
CustomPrompt: beelzebubServiceConfiguration.Plugin.Prompt,
|
||||||
}
|
}
|
||||||
|
|
||||||
llmHoneypotInstance := plugins.InitLLMHoneypot(llmHoneypot)
|
llmHoneypotInstance := plugins.InitLLMHoneypot(llmHoneypot)
|
||||||
|
@ -57,6 +57,7 @@ func (sshStrategy *SSHStrategy) Init(beelzebubServiceConfiguration parser.Beelze
|
|||||||
Protocol: tracer.SSH,
|
Protocol: tracer.SSH,
|
||||||
Host: beelzebubServiceConfiguration.Plugin.Host,
|
Host: beelzebubServiceConfiguration.Plugin.Host,
|
||||||
Model: llmModel,
|
Model: llmModel,
|
||||||
|
CustomPrompt: beelzebubServiceConfiguration.Plugin.Prompt,
|
||||||
}
|
}
|
||||||
|
|
||||||
llmHoneypotInstance := plugins.InitLLMHoneypot(llmHoneypot)
|
llmHoneypotInstance := plugins.InitLLMHoneypot(llmHoneypot)
|
||||||
@ -142,6 +143,7 @@ func (sshStrategy *SSHStrategy) Init(beelzebubServiceConfiguration parser.Beelze
|
|||||||
Protocol: tracer.SSH,
|
Protocol: tracer.SSH,
|
||||||
Host: beelzebubServiceConfiguration.Plugin.Host,
|
Host: beelzebubServiceConfiguration.Plugin.Host,
|
||||||
Model: llmModel,
|
Model: llmModel,
|
||||||
|
CustomPrompt: beelzebubServiceConfiguration.Plugin.Prompt,
|
||||||
}
|
}
|
||||||
|
|
||||||
llmHoneypotInstance := plugins.InitLLMHoneypot(llmHoneypot)
|
llmHoneypotInstance := plugins.InitLLMHoneypot(llmHoneypot)
|
||||||
|
Reference in New Issue
Block a user