nathole

package
v0.51.4 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EasyNAT = "EasyNAT"
	HardNAT = "HardNAT"

	BehaviorNoChange    = "BehaviorNoChange"
	BehaviorIPChanged   = "BehaviorIPChanged"
	BehaviorPortChanged = "BehaviorPortChanged"
	BehaviorBothChanged = "BehaviorBothChanged"
)

Variables

View Source
var (
	// mode 0: simple detect mode, usually for both EasyNAT or HardNAT & EasyNAT(Public Network)
	// a. receiver sends detect message with low TTL
	// b. sender sends normal detect message to receiver
	// c. receiver receives detect message and sends back a message to sender
	//
	// mode 1: For HardNAT & EasyNAT, send detect messages to multiple guessed ports.
	// Usually applicable to scenarios where port changes are regular.
	// Most of the steps are the same as mode 0, but EasyNAT is fixed as the receiver and will send detect messages
	// with low TTL to multiple guessed ports of the sender.
	//
	// mode 2: For HardNAT & EasyNAT, ports changes are not regular.
	// a. HardNAT machine will listen on multiple ports and send detect messages with low TTL to EasyNAT machine
	// b. EasyNAT machine will send detect messages to random ports of HardNAT machine.
	//
	// mode 3: For HardNAT & HardNAT, both changes in the ports are regular.
	// Most of the steps are the same as mode 1, but the sender also needs to send detect messages to multiple guessed
	// ports of the receiver.
	//
	// mode 4: For HardNAT & HardNAT, one of the changes in the ports is regular.
	// Regular port changes are usually on the sender side.
	// a. Receiver listens on multiple ports and sends detect messages with low TTL to the sender's guessed range ports.
	// b. Sender sends detect messages to random ports of the receiver.
	SupportedModes = []int{DetectMode0, DetectMode1, DetectMode2, DetectMode3, DetectMode4}
	SupportedRoles = []string{DetectRoleSender, DetectRoleReceiver}

	DetectMode0        = 0
	DetectMode1        = 1
	DetectMode2        = 2
	DetectMode3        = 3
	DetectMode4        = 4
	DetectRoleSender   = "sender"
	DetectRoleReceiver = "receiver"
)
View Source
var NatHoleTimeout int64 = 10

NatHoleTimeout seconds.

Functions

func ClassifyFeatureCount added in v0.51.1

func ClassifyFeatureCount(features []*NatFeature) (int, int, int)

func DecodeMessageInto added in v0.51.1

func DecodeMessageInto(data, key []byte, m msg.Message) error

func Discover added in v0.51.1

func Discover(stunServers []string, localAddr string) ([]string, net.Addr, error)

If the localAddr is empty, it will listen on a random port.

func EncodeMessage added in v0.51.1

func EncodeMessage(m msg.Message, key []byte) ([]byte, error)

func ExchangeInfo added in v0.51.1

func ExchangeInfo(
	ctx context.Context, transporter transport.MessageTransporter,
	laneKey string, m msg.Message, timeout time.Duration,
) (*msg.NatHoleResp, error)

ExchangeInfo is used to exchange information between client and visitor. 1. Send input message to server by msgTransporter. 2. Server will gather information from client and visitor and analyze it. Then send back a NatHoleResp message to them to tell them how to do next. 3. Receive NatHoleResp message from server.

func ListAllLocalIPs added in v0.51.1

func ListAllLocalIPs() ([]net.IP, error)

func ListLocalIPsForNatHole added in v0.51.1

func ListLocalIPsForNatHole(max int) ([]string, error)

func MakeHole added in v0.51.1

func MakeHole(ctx context.Context, listenConn *net.UDPConn, m *msg.NatHoleResp, key []byte) (*net.UDPConn, *net.UDPAddr, error)

MakeHole is used to make a NAT hole between client and visitor.

func NewTransactionID added in v0.51.1

func NewTransactionID() string

func PreCheck added in v0.51.1

func PreCheck(
	ctx context.Context, transporter transport.MessageTransporter,
	proxyName string, timeout time.Duration,
) error

PreCheck is used to check if the proxy is ready for penetration. Call this function before calling Prepare to avoid unnecessary preparation work.

Types

type Analyzer added in v0.51.1

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

func NewAnalyzer added in v0.51.1

func NewAnalyzer(dataReserveDuration time.Duration) *Analyzer

func (*Analyzer) Clean added in v0.51.1

func (a *Analyzer) Clean() (int, int)

func (*Analyzer) GetRecommandBehaviors added in v0.51.1

func (a *Analyzer) GetRecommandBehaviors(key string, c, v *NatFeature) (mode, index int, _ RecommandBehavior, _ RecommandBehavior)

func (*Analyzer) ReportSuccess added in v0.51.1

func (a *Analyzer) ReportSuccess(key string, mode, index int)

type BehaviorScore added in v0.51.1

type BehaviorScore struct {
	Mode  int
	Index int
	// between -10 and 10
	Score int
}

type ChangedAddress added in v0.51.1

type ChangedAddress struct {
	IP   net.IP
	Port int
}

func (*ChangedAddress) GetFrom added in v0.51.1

func (s *ChangedAddress) GetFrom(m *stun.Message) error

func (*ChangedAddress) String added in v0.51.1

func (s *ChangedAddress) String() string

type ClientCfg

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

type Controller

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

func NewController

func NewController(analysisDataReserveDuration time.Duration) (*Controller, error)

func (*Controller) CleanWorker added in v0.51.1

func (c *Controller) CleanWorker(ctx context.Context)

func (*Controller) CloseClient

func (c *Controller) CloseClient(name string)

func (*Controller) GenNatHoleResponse

func (c *Controller) GenNatHoleResponse(transactionID string, session *Session, errInfo string) *msg.NatHoleResp

func (*Controller) GenSid

func (c *Controller) GenSid() string

func (*Controller) HandleClient

func (c *Controller) HandleClient(m *msg.NatHoleClient, transporter transport.MessageTransporter)

func (*Controller) HandleReport added in v0.51.1

func (c *Controller) HandleReport(m *msg.NatHoleReport)

func (*Controller) HandleVisitor

func (c *Controller) HandleVisitor(m *msg.NatHoleVisitor, transporter transport.MessageTransporter, visitorUser string)

func (*Controller) ListenClient

func (c *Controller) ListenClient(name string, sk string, allowUsers []string) (chan string, error)

type MakeHoleRecords added in v0.51.1

type MakeHoleRecords struct {
	LastUpdateTime time.Time
	// contains filtered or unexported fields
}

func NewMakeHoleRecords added in v0.51.1

func NewMakeHoleRecords(c, v *NatFeature) *MakeHoleRecords

func (*MakeHoleRecords) Recommand added in v0.51.1

func (mhr *MakeHoleRecords) Recommand() (mode, index int)

func (*MakeHoleRecords) ReportSuccess added in v0.51.1

func (mhr *MakeHoleRecords) ReportSuccess(mode int, index int)

type Message added in v0.51.1

type Message struct {
	Body []byte
	Addr string
}

type NatFeature added in v0.51.1

type NatFeature struct {
	NatType            string
	Behavior           string
	PortsDifference    int
	RegularPortsChange bool
	PublicNetwork      bool
}

func ClassifyNATFeature added in v0.51.1

func ClassifyNATFeature(addresses []string, localIPs []string) (*NatFeature, error)

type PrepareResult added in v0.51.1

type PrepareResult struct {
	Addrs         []string
	AssistedAddrs []string
	ListenConn    *net.UDPConn
	NatType       string
	Behavior      string
}

func Prepare added in v0.51.1

func Prepare(stunServers []string) (*PrepareResult, error)

Prepare is used to do some preparation work before penetration.

type RecommandBehavior added in v0.51.1

type RecommandBehavior struct {
	Role              string
	TTL               int
	SendDelayMs       int
	PortsRangeNumber  int
	PortsRandomNumber int
	ListenRandomPorts int
}

type Session

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

Jump to

Keyboard shortcuts

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