feat: Trace command output for SSH Strategy (#35)

manage command output SSH strategy
This commit is contained in:
Mario Candela
2023-04-14 22:35:11 +02:00
committed by GitHub
parent fe6d95ecd6
commit 49a4022f56
2 changed files with 17 additions and 12 deletions

View File

@ -5,13 +5,14 @@ import (
"beelzebub/plugins" "beelzebub/plugins"
"beelzebub/tracer" "beelzebub/tracer"
"fmt" "fmt"
"regexp"
"strings"
"time"
"github.com/gliderlabs/ssh" "github.com/gliderlabs/ssh"
"github.com/google/uuid" "github.com/google/uuid"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh/terminal" "golang.org/x/crypto/ssh/terminal"
"regexp"
"strings"
"time"
) )
type SecureShellStrategy struct { type SecureShellStrategy struct {
@ -46,15 +47,7 @@ func (SSHStrategy *SecureShellStrategy) Init(beelzebubServiceConfiguration parse
if err != nil { if err != nil {
break 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" { if commandInput == "exit" {
break break
} }
@ -81,6 +74,17 @@ func (SSHStrategy *SecureShellStrategy) Init(beelzebubServiceConfiguration parse
histories = append(histories, plugins.History{Input: commandInput, Output: commandOutput}) histories = append(histories, plugins.History{Input: commandInput, Output: commandOutput})
term.Write(append([]byte(commandOutput), '\n')) 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 break
} }
} }

View File

@ -12,6 +12,7 @@ type Event struct {
RemoteAddr string RemoteAddr string
Protocol string Protocol string
Command string Command string
CommandOutput string
Status string Status string
Msg string Msg string
ID string ID string