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"
"time"
"github.com/gliderlabs/ssh"
sshlib "github.com/gliderlabs/ssh"
"github.com/urfave/cli/v2"
"github.uio.no/torjus/apiary"
"github.uio.no/torjus/apiary/config"
"github.uio.no/torjus/apiary/honeypot"
"github.uio.no/torjus/apiary/honeypot/store"
"github.uio.no/torjus/apiary/honeypot/ssh"
"github.uio.no/torjus/apiary/honeypot/ssh/store"
"github.uio.no/torjus/apiary/web"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
@ -82,7 +82,7 @@ func ActionServe(c *cli.Context) error {
}
// Setup honeypot
hs, err := honeypot.NewHoneypotServer(cfg.Honeypot, s)
hs, err := ssh.NewHoneypotServer(cfg.Honeypot, s)
if err != nil {
return err
}
@ -123,7 +123,7 @@ func ActionServe(c *cli.Context) error {
// Start ssh server
go func() {
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)
}
}()

Binary file not shown.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,7 +7,7 @@ import (
"time"
"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"
)

View File

@ -16,8 +16,8 @@ import (
"github.com/google/uuid"
"github.uio.no/torjus/apiary"
"github.uio.no/torjus/apiary/config"
"github.uio.no/torjus/apiary/honeypot"
"github.uio.no/torjus/apiary/honeypot/store"
"github.uio.no/torjus/apiary/honeypot/ssh"
"github.uio.no/torjus/apiary/honeypot/ssh/store"
"github.uio.no/torjus/apiary/models"
"go.uber.org/zap"
"golang.org/x/crypto/acme/autocert"
@ -31,7 +31,7 @@ type Server struct {
cfg config.FrontendConfig
honeypotServer *honeypot.HoneypotServer
honeypotServer *ssh.HoneypotServer
store store.LoginAttemptStore
ServerLogger *zap.SugaredLogger
@ -42,7 +42,7 @@ type Server struct {
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{
ServerLogger: zap.NewNop().Sugar(),
AccessLogger: zap.NewNop().Sugar(),