sshbox

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: MIT Imports: 32 Imported by: 0

README

SSHBox

This is a library for ease of native ssh with https://pkg.go.dev/golang.org/x/crypto/ssh . This help you to:

  • Create tunnels on ssh server
  • Create reverse tunnels on ssh server
  • Create socks5 server on ssh server, you can also have dns resolution from nameserver on ssh server which let you set socks5h server
  • Gateway(s) creation for accessing ssh server in chainable way
  • Have an interactive shell on ssh server

Note: Use https://pkg.go.dev/golang.org/x/crypto/ssh make the library totally standalone from ssh command line from a linux server. This liberate you from having putty on windows for example.

Usage

package main

import (
	"github.com/ArthurHlt/sshbox"
)

func main() {
	sb, err := sshbox.NewSSHBox(sshbox.SSHConf{
		SSHUri:     "url.com",
		User:       "root",
		Password:   "a password",
		NoSSHAgent: true,
	})
	if err != nil {
		panic(err)
	}

	// create tunnels
	// this will let you call access to something running on port 8080 in your ssh server on port 8080 on localhost
	// if reverse is true, this is inverted, ssh server will access to something running locally on port 8080
	go sb.StartTunnels([]*sshbox.TunnelTarget{
		{
			Network:    "tcp",
			RemoteHost: "127.0.0.1",
			RemotePort: 8080,
			LocalPort:  8080,
			Reverse:    false,
		},
	})
	// Create a socks5 server on udp and tcp
	// you can now use with env var https_proxy=socks5h://localhost:9090 and http_proxy=socks5h://localhost:9090
	go sb.StartSocksServer(9090, "tcp")
	go sb.StartSocksServer(9090, "udp")
	// This will open a shell on ssh server
	interact := sshbox.NewInteractiveSSH(sb)
	panic(interact.Interactive())
	// panic(sb.StartSocksServer(9090, "tcp"))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSshClientFactory

func DefaultSshClientFactory(conf SSHConf) (*ssh.Client, error)

func NewNameResolverSimple

func NewNameResolverSimple(servers []string) *nameResolverSimple

func OptNameResolverFactory

func OptNameResolverFactory(nameResolverFactory NameResolverFactory) func(box *SSHBox) error

func OptSSHClientFactory

func OptSSHClientFactory(factory SshClientFactory) func(box *SSHBox) error

func OptSocksConf

func OptSocksConf(conf *socks5.Config) func(box *SSHBox) error

Types

type DnsConfig

type DnsConfig struct {
	Servers    []string // servers to use
	Search     []string // suffixes to append to local name
	Ndots      int      // number of dots in name to trigger absolute lookup
	Timeout    int      // seconds before giving up on packet
	Attempts   int      // lost packets before giving up on server
	Rotate     bool     // round robin among servers
	UnknownOpt bool     // anything unknown was encountered
	Lookup     []string // OpenBSD top-level database "lookup" order
	Err        error    // any error that occurs during open of resolv.conf
}

func DnsConfFromSSH

func DnsConfFromSSH(sshBox *SSHBox) (*DnsConfig, error)

type Emitter

type Emitter struct {
	// contains filtered or unexported fields
}

func NewEmitter

func NewEmitter() *Emitter

func (*Emitter) EmitStopSocks

func (em *Emitter) EmitStopSocks()

func (*Emitter) EmitStopSsh

func (em *Emitter) EmitStopSsh()

func (*Emitter) EmitStopTunnels

func (em *Emitter) EmitStopTunnels()

func (*Emitter) ListenersStartTunnels

func (em *Emitter) ListenersStartTunnels() []<-chan emitter.Event

func (*Emitter) ListenersStopSocks

func (em *Emitter) ListenersStopSocks() []<-chan emitter.Event

func (*Emitter) ListenersStopSsh

func (em *Emitter) ListenersStopSsh() []<-chan emitter.Event

func (*Emitter) ListenersStopTunnels

func (em *Emitter) ListenersStopTunnels() []<-chan emitter.Event

func (*Emitter) OffStartTunnels

func (em *Emitter) OffStartTunnels(events ...<-chan emitter.Event)

func (*Emitter) OffStopSocks

func (em *Emitter) OffStopSocks(events ...<-chan emitter.Event)

func (*Emitter) OffStopSsh

func (em *Emitter) OffStopSsh(events ...<-chan emitter.Event)

func (*Emitter) OffStopTunnels

func (em *Emitter) OffStopTunnels(events ...<-chan emitter.Event)

func (*Emitter) OnStartTunnels

func (em *Emitter) OnStartTunnels() <-chan emitter.Event

func (*Emitter) OnStopSocks

func (em *Emitter) OnStopSocks() <-chan emitter.Event

func (*Emitter) OnStopSsh

func (em *Emitter) OnStopSsh() <-chan emitter.Event

func (*Emitter) OnStopTunnels

func (em *Emitter) OnStopTunnels() <-chan emitter.Event

func (*Emitter) ToError

func (em *Emitter) ToError(evt emitter.Event) error

type ErrLoad

type ErrLoad struct {
	// contains filtered or unexported fields
}

func (ErrLoad) Error

func (e ErrLoad) Error() string

type GatewayInfo

type GatewayInfo struct {
	SrcSSHUri  string
	LocalPort  int
	RemoteHost string
	RemotePort int
}

type Gateways

type Gateways struct {
	// contains filtered or unexported fields
}

func NewGateways

func NewGateways(gateways []*SSHConf) *Gateways

func (Gateways) RunGateways

func (g Gateways) RunGateways(sshUri string) (string, error)

type InteractiveSSH

type InteractiveSSH struct {
	// contains filtered or unexported fields
}

func NewInteractiveSSH

func NewInteractiveSSH(sshBox *SSHBox) *InteractiveSSH

func (*InteractiveSSH) Interactive

func (c *InteractiveSSH) Interactive() error

func (*InteractiveSSH) InteractiveSession

func (c *InteractiveSSH) InteractiveSession(commands []string, terminalRequest TTYRequest) error

func (*InteractiveSSH) RunCmd

func (c *InteractiveSSH) RunCmd(cmd []string) error

func (*InteractiveSSH) Stop

func (c *InteractiveSSH) Stop() error

type NameResolver

type NameResolver interface {
	Resolve(ctx netctx.Context, name string) (context.Context, net.IP, error)
}

func NameResolverFactorySSH

func NameResolverFactorySSH(sshBox *SSHBox) (NameResolver, error)

type NameResolverFactory

type NameResolverFactory func(sshBox *SSHBox) (NameResolver, error)

type PublicKeys

type PublicKeys struct {
	User   string
	Signer ssh.Signer
}

PublicKeys implements AuthMethod by using the given key pairs.

func NewPublicKeys

func NewPublicKeys(pemBytes []byte, password string) (*PublicKeys, error)

func NewPublicKeysFromFile

func NewPublicKeysFromFile(pemFile, password string) (*PublicKeys, error)

type SSHBox

type SSHBox struct {
	// contains filtered or unexported fields
}

func NewSSHBox

func NewSSHBox(config SSHConf, opts ...SSHBoxOptions) (*SSHBox, error)

func (SSHBox) Emitter

func (t SSHBox) Emitter() *Emitter

func (*SSHBox) HandleRTunnelClient added in v0.1.2

func (t *SSHBox) HandleRTunnelClient(client net.Conn, target *TunnelTarget)

func (*SSHBox) HandleTunnelClient added in v0.1.2

func (t *SSHBox) HandleTunnelClient(client net.Conn, target *TunnelTarget)

func (*SSHBox) SSHClient

func (t *SSHBox) SSHClient() *ssh.Client

func (*SSHBox) StartSocksServer

func (t *SSHBox) StartSocksServer(port int, network string) error

func (*SSHBox) StartTunnels

func (t *SSHBox) StartTunnels(tunnelTargets []*TunnelTarget) error

func (*SSHBox) StopSSH

func (t *SSHBox) StopSSH()

func (*SSHBox) StopSocksServer

func (t *SSHBox) StopSocksServer()

func (*SSHBox) StopTunnelsServer

func (t *SSHBox) StopTunnelsServer()

type SSHBoxOptions

type SSHBoxOptions func(sshBox *SSHBox) error

type SSHConf

type SSHConf struct {
	SSHUri             string
	User               string
	Password           string
	PrivateKey         string
	Passphrase         string
	HostKeyFingerprint string
	SSHAuthSock        *string
	NoSSHAgent         bool
}

func (*SSHConf) CheckAndFill

func (c *SSHConf) CheckAndFill() error

type SshClientFactory

type SshClientFactory func(conf SSHConf) (*ssh.Client, error)

type TTYRequest

type TTYRequest int
const (
	RequestTTYAuto TTYRequest = iota
	RequestTTYNo
	RequestTTYYes
	RequestTTYForce
)

type TunnelTarget

type TunnelTarget struct {
	Network    string
	RemoteHost string
	RemotePort int
	LocalPort  int
	Reverse    bool
}

func DNSServerToTunnel

func DNSServerToTunnel(dnsservers []string) ([]*TunnelTarget, error)

func (*TunnelTarget) CheckAndFill

func (c *TunnelTarget) CheckAndFill() error

type TunnelTargets

type TunnelTargets []*TunnelTarget

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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