@@ -31,6 +31,68 @@ func (sshStrategy *SSHStrategy) Init(beelzebubServiceConfiguration parser.Beelze
31
31
32
32
host , port , _ := net .SplitHostPort (sess .RemoteAddr ().String ())
33
33
34
+ if sess .RawCommand () != "" {
35
+ for _ , command := range beelzebubServiceConfiguration .Commands {
36
+ matched , err := regexp .MatchString (command .Regex , sess .RawCommand ())
37
+ if err != nil {
38
+ log .Errorf ("Error regex: %s, %s" , command .Regex , err .Error ())
39
+ continue
40
+ }
41
+
42
+ if matched {
43
+ commandOutput := command .Handler
44
+
45
+ if command .Plugin == plugins .LLMPluginName {
46
+
47
+ llmModel , err := plugins .FromStringToLLMModel (beelzebubServiceConfiguration .Plugin .LLMModel )
48
+
49
+ if err != nil {
50
+ log .Errorf ("Error fromString: %s" , err .Error ())
51
+ commandOutput = "command not found"
52
+ }
53
+
54
+ llmHoneypot := plugins.LLMHoneypot {
55
+ Histories : make ([]plugins.Message , 0 ),
56
+ OpenAIKey : beelzebubServiceConfiguration .Plugin .OpenAISecretKey ,
57
+ Protocol : tracer .SSH ,
58
+ Host : beelzebubServiceConfiguration .Plugin .Host ,
59
+ Model : llmModel ,
60
+ }
61
+
62
+ llmHoneypotInstance := plugins .InitLLMHoneypot (llmHoneypot )
63
+
64
+ if commandOutput , err = llmHoneypotInstance .ExecuteModel (sess .RawCommand ()); err != nil {
65
+ log .Errorf ("Error ExecuteModel: %s, %s" , sess .RawCommand (), err .Error ())
66
+ commandOutput = "command not found"
67
+ }
68
+ }
69
+
70
+ sess .Write (append ([]byte (commandOutput ), '\n' ))
71
+
72
+ tr .TraceEvent (tracer.Event {
73
+ Msg : "New SSH Session" ,
74
+ Protocol : tracer .SSH .String (),
75
+ RemoteAddr : sess .RemoteAddr ().String (),
76
+ SourceIp : host ,
77
+ SourcePort : port ,
78
+ Status : tracer .Start .String (),
79
+ ID : uuidSession .String (),
80
+ Environ : strings .Join (sess .Environ (), "," ),
81
+ User : sess .User (),
82
+ Description : beelzebubServiceConfiguration .Description ,
83
+ Command : sess .RawCommand (),
84
+ CommandOutput : commandOutput ,
85
+ })
86
+ tr .TraceEvent (tracer.Event {
87
+ Msg : "End SSH Session" ,
88
+ Status : tracer .End .String (),
89
+ ID : uuidSession .String (),
90
+ })
91
+ return
92
+ }
93
+ }
94
+ }
95
+
34
96
tr .TraceEvent (tracer.Event {
35
97
Msg : "New SSH Session" ,
36
98
Protocol : tracer .SSH .String (),
@@ -42,7 +104,6 @@ func (sshStrategy *SSHStrategy) Init(beelzebubServiceConfiguration parser.Beelze
42
104
Environ : strings .Join (sess .Environ (), "," ),
43
105
User : sess .User (),
44
106
Description : beelzebubServiceConfiguration .Description ,
45
- Command : sess .RawCommand (),
46
107
})
47
108
48
109
term := terminal .NewTerminal (sess , buildPrompt (sess .User (), beelzebubServiceConfiguration .ServerName ))
0 commit comments