Reorganize packages

This commit is contained in:
Torjus Håkestad 2021-10-21 12:36:01 +02:00
parent a71ff52ab4
commit 94e7faae78
15 changed files with 24 additions and 24 deletions

View File

@ -8,12 +8,12 @@ import (
"os/signal" "os/signal"
"time" "time"
"github.com/gliderlabs/ssh" sshlib "github.com/gliderlabs/ssh"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"github.uio.no/torjus/apiary" "github.uio.no/torjus/apiary"
"github.uio.no/torjus/apiary/config" "github.uio.no/torjus/apiary/config"
"github.uio.no/torjus/apiary/honeypot" "github.uio.no/torjus/apiary/honeypot/ssh"
"github.uio.no/torjus/apiary/honeypot/store" "github.uio.no/torjus/apiary/honeypot/ssh/store"
"github.uio.no/torjus/apiary/web" "github.uio.no/torjus/apiary/web"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
@ -82,7 +82,7 @@ func ActionServe(c *cli.Context) error {
} }
// Setup honeypot // Setup honeypot
hs, err := honeypot.NewHoneypotServer(cfg.Honeypot, s) hs, err := ssh.NewHoneypotServer(cfg.Honeypot, s)
if err != nil { if err != nil {
return err return err
} }
@ -123,7 +123,7 @@ func ActionServe(c *cli.Context) error {
// Start ssh server // Start ssh server
go func() { go func() {
loggers.rootLogger.Info("Starting SSH server") loggers.rootLogger.Info("Starting SSH server")
if err := hs.ListenAndServe(); err != nil && err != ssh.ErrServerClosed { if err := hs.ListenAndServe(); err != nil && err != sshlib.ErrServerClosed {
loggers.rootLogger.Warnw("SSH server returned error", "error", err) loggers.rootLogger.Warnw("SSH server returned error", "error", err)
} }
}() }()

Binary file not shown.

View File

@ -1,4 +1,4 @@
package honeypot package ssh
type ActionType int type ActionType int

View File

@ -1,4 +1,4 @@
package honeypot package ssh
import ( import (
"net" "net"

View File

@ -1,4 +1,4 @@
package honeypot package ssh
import ( import (
_ "embed" _ "embed"

View File

@ -1,4 +1,4 @@
package honeypot package ssh
import ( import (
"context" "context"
@ -12,9 +12,9 @@ import (
"github.uio.no/torjus/apiary/config" "github.uio.no/torjus/apiary/config"
"github.com/gliderlabs/ssh" sshlib "github.com/gliderlabs/ssh"
"github.com/google/uuid" "github.com/google/uuid"
"github.uio.no/torjus/apiary/honeypot/store" "github.uio.no/torjus/apiary/honeypot/ssh/store"
"github.uio.no/torjus/apiary/models" "github.uio.no/torjus/apiary/models"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -22,7 +22,7 @@ import (
type HoneypotServer struct { type HoneypotServer struct {
Logger *zap.SugaredLogger Logger *zap.SugaredLogger
sshServer *ssh.Server sshServer *sshlib.Server
attemptStore store.LoginAttemptStore attemptStore store.LoginAttemptStore
attemptsCallbacks []func(l models.LoginAttempt) attemptsCallbacks []func(l models.LoginAttempt)
@ -35,7 +35,7 @@ func NewHoneypotServer(cfg config.HoneypotConfig, store store.LoginAttemptStore)
hs.attemptStore = store hs.attemptStore = store
hs.Logger = zap.NewNop().Sugar() hs.Logger = zap.NewNop().Sugar()
hs.sshServer = &ssh.Server{ hs.sshServer = &sshlib.Server{
Addr: cfg.ListenAddr, Addr: cfg.ListenAddr,
PasswordHandler: hs.passwordHandler, PasswordHandler: hs.passwordHandler,
ConnCallback: hs.connCallback, ConnCallback: hs.connCallback,
@ -75,7 +75,7 @@ func (hs *HoneypotServer) AddLoginCallback(c func(l models.LoginAttempt)) {
hs.attemptsCallbacks = append(hs.attemptsCallbacks, c) hs.attemptsCallbacks = append(hs.attemptsCallbacks, c)
} }
func (hs *HoneypotServer) passwordHandler(ctx ssh.Context, password string) bool { func (hs *HoneypotServer) passwordHandler(ctx sshlib.Context, password string) bool {
sessUUID, ok := ctx.Value("uuid").(uuid.UUID) sessUUID, ok := ctx.Value("uuid").(uuid.UUID)
if !ok { if !ok {
hs.Logger.Warn("Unable to get session UUID") hs.Logger.Warn("Unable to get session UUID")
@ -114,7 +114,7 @@ func (hs *HoneypotServer) passwordHandler(ctx ssh.Context, password string) bool
return false return false
} }
func (s *HoneypotServer) connCallback(ctx ssh.Context, conn net.Conn) net.Conn { func (s *HoneypotServer) connCallback(ctx sshlib.Context, conn net.Conn) net.Conn {
throttledConn := newThrottledConn(conn) throttledConn := newThrottledConn(conn)
throttledConn.SetSpeed(s.throttleSpeed) throttledConn.SetSpeed(s.throttleSpeed)
ctx.SetValue("uuid", throttledConn.ID) ctx.SetValue("uuid", throttledConn.ID)
@ -122,7 +122,7 @@ func (s *HoneypotServer) connCallback(ctx ssh.Context, conn net.Conn) net.Conn {
return throttledConn return throttledConn
} }
func handler(session ssh.Session) { func handler(session sshlib.Session) {
_, _ = io.WriteString(session, "[root@hostname ~]#") _, _ = io.WriteString(session, "[root@hostname ~]#")
session.Exit(1) session.Exit(1)
} }

View File

@ -3,7 +3,7 @@ package store_test
import ( import (
"testing" "testing"
"github.uio.no/torjus/apiary/honeypot/store" "github.uio.no/torjus/apiary/honeypot/ssh/store"
) )
func TestCacheStore(t *testing.T) { func TestCacheStore(t *testing.T) {

View File

@ -3,7 +3,7 @@ package store_test
import ( import (
"testing" "testing"
"github.uio.no/torjus/apiary/honeypot/store" "github.uio.no/torjus/apiary/honeypot/ssh/store"
) )
func TestMemoryStore(t *testing.T) { func TestMemoryStore(t *testing.T) {

View File

@ -5,7 +5,7 @@ import (
"os" "os"
"testing" "testing"
"github.uio.no/torjus/apiary/honeypot/store" "github.uio.no/torjus/apiary/honeypot/ssh/store"
) )
func TestPostgresStore(t *testing.T) { func TestPostgresStore(t *testing.T) {

View File

@ -7,7 +7,7 @@ import (
"time" "time"
"github.com/google/uuid" "github.com/google/uuid"
"github.uio.no/torjus/apiary/honeypot/store" "github.uio.no/torjus/apiary/honeypot/ssh/store"
"github.uio.no/torjus/apiary/models" "github.uio.no/torjus/apiary/models"
) )

View File

@ -16,8 +16,8 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
"github.uio.no/torjus/apiary" "github.uio.no/torjus/apiary"
"github.uio.no/torjus/apiary/config" "github.uio.no/torjus/apiary/config"
"github.uio.no/torjus/apiary/honeypot" "github.uio.no/torjus/apiary/honeypot/ssh"
"github.uio.no/torjus/apiary/honeypot/store" "github.uio.no/torjus/apiary/honeypot/ssh/store"
"github.uio.no/torjus/apiary/models" "github.uio.no/torjus/apiary/models"
"go.uber.org/zap" "go.uber.org/zap"
"golang.org/x/crypto/acme/autocert" "golang.org/x/crypto/acme/autocert"
@ -31,7 +31,7 @@ type Server struct {
cfg config.FrontendConfig cfg config.FrontendConfig
honeypotServer *honeypot.HoneypotServer honeypotServer *ssh.HoneypotServer
store store.LoginAttemptStore store store.LoginAttemptStore
ServerLogger *zap.SugaredLogger ServerLogger *zap.SugaredLogger
@ -42,7 +42,7 @@ type Server struct {
streamContext context.Context streamContext context.Context
} }
func NewServer(cfg config.FrontendConfig, hs *honeypot.HoneypotServer, store store.LoginAttemptStore) *Server { func NewServer(cfg config.FrontendConfig, hs *ssh.HoneypotServer, store store.LoginAttemptStore) *Server {
s := &Server{ s := &Server{
ServerLogger: zap.NewNop().Sugar(), ServerLogger: zap.NewNop().Sugar(),
AccessLogger: zap.NewNop().Sugar(), AccessLogger: zap.NewNop().Sugar(),