sshdog

package module
v0.0.0-...-a66c830 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

README

SSHDog

SSHDog is your go-anywhere lightweight SSH server. Written in Go, it aims to be a portable SSH server that you can drop on a system and use for remote access without any additional configuration.

Useful for:

  • Tech support
  • Backup SSHD
  • Authenticated remote bind shells

Supported features:

  • Windows & Linux
  • Configure port, host key, authorized keys
  • Pubkey authentication (no passwords)
  • Port forwarding
  • SCP (but no SFTP support)

Example usage:

% go build ./cmd/sshdog
% ssh-keygen -t rsa -b 2048 -N '' -f config/ssh_host_rsa_key
% echo 2222 > config/port
% cp ~/.ssh/id_rsa.pub config/authorized_keys
% rice append --exec sshdog
% ./sshdog
[DEBUG] Adding hostkey file: ssh_host_rsa_key
[DEBUG] Adding authorized_keys.
[DEBUG] Listening on :2222
[DEBUG] Waiting for shutdown.
[DEBUG] select...

Author: David Tomaschik dwt@google.com

This is not a Google product, merely code that happens to be owned by Google.

Documentation

Overview

TODO: High-level file comment.

TODO: High-level file comment.

TODO: High-level file comment.

Index

Constants

View Source
const (
	SCPCopy = iota
	SCPDir
	SCPEndDir
	SCPTime
)
View Source
const (
	SCPOK = iota
	SCPError
	SCPFatal
)

Variables

View Source
var (
	SCP_END_COMMANDS  = "\x00"
	ErrInvalidAck     = errors.New("Invalid ack code.")
	ErrInvalidPieces  = errors.New("Invalid number of command pieces.")
	ErrNotRegularFile = errors.New("Not a regular file.")
	ErrNotDirectory   = errors.New("Not a directory.")
	ErrNullByte       = errors.New("Expected null byte for EOF.")
)
View Source
var (
	KeyNames = []string{
		"ssh_host_dsa_key",
		"ssh_host_ecdsa_key",
		"ssh_host_rsa_key",
	}
	ErrWrongPassword       = errors.New("Wrong password")
	ErrDisablePasswordAuth = errors.New("Password auth are diabled")
	ErrUnknownPubKey       = errors.New("No valid key found.")
)

Functions

func SCPSendDir

func SCPSendDir(path string, fi os.FileInfo, src *bufio.Reader, dst io.Writer) error

Send a directory

func SCPSendFile

func SCPSendFile(path string, src *bufio.Reader, dst io.Writer) error

Send a file

func SCPSendFile2

func SCPSendFile2(path string, fi os.FileInfo, src *bufio.Reader, dst io.Writer) error

Actually send the file

Types

type EnvRequest

type EnvRequest struct {
	Name  string
	Value string
}

type ExecRequest

type ExecRequest struct {
	Cmd string
}

type PTYRequest

type PTYRequest struct {
	Term     string
	Width    uint32
	Height   uint32
	WidthPx  uint32
	HeightPx uint32
	Modes    string
}

type SCPCommand

type SCPCommand struct {
	CommandType int
	Mode        int16
	Length      int64
	Name        string
}

type Server

type Server struct {
	ServerConfig   ssh.ServerConfig
	Socket         net.Listener
	AuthorizedKeys map[string]bool

	PasswordMap map[string]string
	// contains filtered or unexported fields
}

Manage the SSH Server

func NewServer

func NewServer() *Server

NewServer create new server instance with global authorized keys (load before start with AddAuthorizedKeys)

func NewServerPerUser

func NewServerPerUser(keyDir string) (*Server, error)

NewServer create new server instance with per-user authorized keys (stored in keyDir)

func (*Server) AddAuthorizedKeys

func (s *Server) AddAuthorizedKeys(keyData []byte) *Server

func (*Server) AddHostkey

func (s *Server) AddHostkey(keyData []byte) error

func (*Server) AddHostkeyFrom

func (s *Server) AddHostkeyFrom(keypath string) error

func (*Server) AddUser

func (s *Server) AddUser(user, password string) *Server

func (*Server) Address

func (s *Server) Address() string

func (*Server) GetDoneChan

func (s *Server) GetDoneChan() chan bool

func (*Server) HostAndPort

func (s *Server) HostAndPort() (string, string)

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(port int16) (error, func())

func (*Server) ListenAndServe2

func (s *Server) ListenAndServe2(addr string) (error, func())

func (*Server) ListenAndServeForever

func (s *Server) ListenAndServeForever(port int16) error

func (*Server) ListenAndServeForever2

func (s *Server) ListenAndServeForever2(addr string) error

func (*Server) RandomHostkey

func (s *Server) RandomHostkey() error

func (*Server) Stop

func (s *Server) Stop()

Ask for shutdown

func (*Server) VerifyPassword

func (s *Server) VerifyPassword(conn ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error)

func (*Server) VerifyPublicKey

func (s *Server) VerifyPublicKey(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error)

func (*Server) VerifyUserPublicKey

func (s *Server) VerifyUserPublicKey(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error)

func (*Server) Wait

func (s *Server) Wait()

Wait for server shutdown

type ServerConn

type ServerConn struct {
	*Server
	*ssh.ServerConn
	// contains filtered or unexported fields
}

Handling for a single incoming connection

func NewServerConn

func NewServerConn(conn net.Conn, s *Server) (*ServerConn, error)

func (*ServerConn) Cancel

func (conn *ServerConn) Cancel()

func (*ServerConn) ExecuteForChannel

func (conn *ServerConn) ExecuteForChannel(shellCmd []string, ch ssh.Channel)

Execute a process for the channel.

func (*ServerConn) Exit

func (conn *ServerConn) Exit(ch ssh.Channel)

func (*ServerConn) HandleConn

func (conn *ServerConn) HandleConn()

Handle a single established connection

func (*ServerConn) HandleSessionChannel

func (conn *ServerConn) HandleSessionChannel(wg *sync.WaitGroup, newChan ssh.NewChannel)

func (*ServerConn) HandleTCPIPChannel

func (conn *ServerConn) HandleTCPIPChannel(wg *sync.WaitGroup, newChan ssh.NewChannel)

func (*ServerConn) SCPHandler

func (conn *ServerConn) SCPHandler(shellCmd []string, ch ssh.Channel) error

Manage SCP operations in a built-in fashion

func (*ServerConn) SCPSink

func (conn *ServerConn) SCPSink(path string, dirMode bool, ch ssh.Channel) error

Handle the 'sink' side of an SCP connection

func (*ServerConn) SCPSource

func (conn *ServerConn) SCPSource(path string, dirMode bool, recursive bool, ch ssh.Channel) error

Handle the 'source' side of an SCP connection

func (*ServerConn) ServiceGlobalRequests

func (conn *ServerConn) ServiceGlobalRequests()

Directories

Path Synopsis
cmd
scpdebug
Tool for debug logs of SCP, since it's an undocumented protocol.
Tool for debug logs of SCP, since it's an undocumented protocol.
sshdog
TODO: High-level file comment.
TODO: High-level file comment.
TODO: High-level file comment.
TODO: High-level file comment.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL