fcbreak

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2022 License: GPL-3.0 Imports: 25 Imported by: 0

README

Fullcone Breaker

This is an NAT traversal tool for fullcone NAT only, allowing TCP traversal.

Prerequision

Fullcone NAT is required. If your ISP uses CGN, it's very likely that you have fullcone NAT.

Additionally, any NAT box between your computer and internet need to be fullcone, or you can set DMZ to your computer.

Usage

Server:

./server
    -l [<listen ip>]:<port>   API exposing host, the API will listen as http
    -s [<listen ip>]:<port>   API exposing host, will listen as https
    [--cert <cert file>]      HTTPS certificate file, must be defined when -s is presented
    [--key <key file>]        HTTPS certificate file, must be defined when -s is presented
    [--proxy-protocol]        Listen using Proxy Protocol
    [-u <username>]           Set username to secure the API, optional
    [-p <password>]           Set password to secure the API, optional

Client:

./client -c <path to config file>

Client Config File:

[common]
server = http://<user>:<pass>@<server host>:<server port> # Server API address
heartbeat_interval = 15 # [Optional] Heartbeat frequency
skip_verify = false    # [Optional] Skip TLS certification verification, default false.

[http_service]         # Name of exposing service
type = http            # Type of service, support tcp/http/https
local_ip = 127.0.0.1   # LAN IP of the service
local_port = 5000      # LAN Port of the service
remote_ip = 0.0.0.0    # [Optional] Listening IP on your server, optional, default to all IP
remote_port = 5000     # [Optional] Listening Port, no remote port is assigned if not defined
http_hostname = srv.example.com, srv.foobar.com
                       # [Optional] Add a hostname to server, service will be accessible on 
                                    http://<server host>:<server http port> with designated hostnames.
http_ddns_domain = ddns.example.com
                       # [Optional] Set DDNS domain. If set, redirection will go to the domain name instead of IP.
                          DDNS need to be updated using other programs.
http_nip_domain = ip.example.com
                       # [Optional] Set AltSvc domain. If set, redirection will use pattern like
                          1-1-1-1.ip.example.com instead of IP. ddns domain will not be used if this is set.
http_cache_time = 0    # [Optional] Cache time of HTTP, will also control the HTTP Redirect cache.
http_altsvc = true     # [Optional] Use AltSvc instead of redirection

[https_service]
type = https
local_ip = 127.0.0.1   # LAN IP of the service
local_port = 5001      # LAN Port of the service
remote_ip = 0.0.0.0    # [Optional] Listening IP on your server, optional, default to all IP
remote_port = 5001     # [Optional] Listening Port, no remote port is assigned if not defined
http_hostname = srv.example.com, srv.foobar.com
                       # [Optional] Add a hostname to server, service will be accessible on
                                    https://<server host>:<server https port> with designated hostnames.
http_backend=https     # [Optional] HTTP Backend (http/https/proxy), default to http
https_crt = /certs/example.com.crt # TLS Certificate
https_key = /certs/example.com.key # TLS Private Key

[http_proxy]
type = http
bind_ip = 0.0.0.0      # [Optional] Binding IP on your computer, optional, default to all IP
bind_port = 5012       # [Optional] Binding port on your computer, optional, default ramdom port
remote_port = 5002     # [Optional] Listening Port, no remote port is assigned if not defined
http_username=proxy    # [Optional] HTTP Basic Auth Username
http_password=password # [Optional] HTTP Basic Auth Password
http_backend=proxy
http_proxy_chain=http://localhost:3128 # [Optional] Chain Proxy, http or socks.

[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 2200

Connector:

sudo ./connector
    -s http[s]://[<user>:<pass>@]<server host>:<server port> # Server API
    [-i <interval>]               # Update Interval, default 300s

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConnContextKey = &contextKey{"http-conn"}
View Source
var (
	ErrorServiceNotFound = errors.New("Service is not found")
)

Functions

func GetConn

func GetConn(r *http.Request) net.Conn

func GetConnUnwarpTLS

func GetConnUnwarpTLS(r *http.Request) net.Conn

func SaveConnInContext

func SaveConnInContext(ctx context.Context, c net.Conn) context.Context

func SupportAltSvc

func SupportAltSvc(useragent string) bool

Types

type ClientCommonConf

type ClientCommonConf struct {
	// ServerAddr specifies the address of the server to connect to. By
	// default, this value is "http://0.0.0.0:7001".
	Server string `ini:"server" json:"server"`
	// SkipTLSVerify willl skip the check of TLS certificates.
	SkipTLSVerify bool `ini:"skip_verify" json:"skip_verify"`
	// HeartBeatInterval specifies at what interval heartbeats are sent to the
	// server, in seconds. It is not recommended to change this value. By
	// default, this value is 30.
	HeartbeatInterval int64 `ini:"heartbeat_interval" json:"heartbeat_interval"`
	// HeartBeatTimeout specifies the maximum allowed heartbeat response delay
	// before the connection is terminated, in seconds. It is not recommended
	// to change this value. By default, this value is 90.
	HeartbeatTimeout int64 `ini:"heartbeat_timeout" json:"heartbeat_timeout"`
}

func GetDefaultClientConf

func GetDefaultClientConf() ClientCommonConf

type CloseReader

type CloseReader interface {
	CloseRead() error
}

type CloseWriter

type CloseWriter interface {
	CloseWrite() error
}

type HTTPProxy

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

func NewHTTPProxy added in v0.2.0

func NewHTTPProxy(s *Service) *HTTPProxy

func (*HTTPProxy) Auth

func (hp *HTTPProxy) Auth(req *http.Request, header string) bool

func (*HTTPProxy) ConnectHandler

func (hp *HTTPProxy) ConnectHandler(rw http.ResponseWriter, req *http.Request)

deprecated Hijack needs to SetReadDeadline on the Conn of the request, but if we use stream compression here, we may always get i/o timeout error.

func (*HTTPProxy) HTTPHandler

func (hp *HTTPProxy) HTTPHandler(rw http.ResponseWriter, req *http.Request)

func (*HTTPProxy) InfoHandler

func (hp *HTTPProxy) InfoHandler(rw http.ResponseWriter, req *http.Request)

func (*HTTPProxy) ServeHTTP

func (hp *HTTPProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type HTTPService

type HTTPService struct {
	*Service
	// contains filtered or unexported fields
}

func (*HTTPService) ModifyResponse

func (s *HTTPService) ModifyResponse(r *http.Response) error

func (*HTTPService) Serve

func (s *HTTPService) Serve(l net.Listener) (err error)

func (*HTTPService) ServeHTTP

func (s *HTTPService) ServeHTTP(w http.ResponseWriter, r *http.Request)

HTTP Reverse Proxy Handler

func (*HTTPService) Shutdown

func (s *HTTPService) Shutdown() error

type HTTPServiceConf

type HTTPServiceConf struct {
	Hostname      string `ini:"http_hostname"`
	Username      string `ini:"http_username"`
	Password      string `ini:"http_password"`
	CacheTime     int    `ini:"http_cache_time"`
	AltSvc        bool   `ini:"http_altsvc"`
	DDNSDomain    string `ini:"http_ddns_domain"`
	NIPDomain     string `ini:"http_nip_domain"`
	Backend       string `ini:"http_backend"`
	ChainProxy    string `ini:"http_proxy_chain"`
	TLSCert       string `ini:"https_crt"`
	TLSKey        string `ini:"https_key"`
	ProxyInsecure bool   `ini:"https_proxy_skip_cert_verification"`
}

type Server

type Server struct {
	User string
	Pass string
	// contains filtered or unexported fields
}

func NewServer

func NewServer() *Server

func (*Server) AddService

func (s *Server) AddService(svc *ServiceInfo) (*ServiceInfo, error)

func (*Server) DelService

func (s *Server) DelService(name string) error

func (*Server) DeleteService

func (s *Server) DeleteService(c *gin.Context)

func (*Server) GetServiceByName

func (s *Server) GetServiceByName(c *gin.Context)

func (*Server) GetServices

func (s *Server) GetServices(c *gin.Context)

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string, tls *tls.Config, useProxyProto bool) error

func (*Server) PostService

func (s *Server) PostService(c *gin.Context)

func (*Server) PutService

func (s *Server) PutService(c *gin.Context)

func (*Server) PutServiceExposedAddr

func (s *Server) PutServiceExposedAddr(c *gin.Context)

func (*Server) PutServiceProxyAddr

func (s *Server) PutServiceProxyAddr(c *gin.Context)

func (*Server) Shutdown added in v0.2.0

func (s *Server) Shutdown()

func (*Server) UpdateService

func (s *Server) UpdateService(name string, svc *ServiceInfo) (*ServiceInfo, error)

type Service

type Service struct {
	ServiceInfo
	Cfg ServiceConf
	// contains filtered or unexported fields
}

func NewService

func NewService(name string, cfg ServiceConf) *Service

func (*Service) Handle

func (s *Service) Handle(conn net.Conn) error

Handle raw connection

func (*Service) Listen

func (s *Service) Listen() (net.Listener, error)

func (*Service) ListenAndServe

func (s *Service) ListenAndServe() error

func (*Service) Serve

func (s *Service) Serve(l net.Listener) (err error)

func (*Service) Shutdown

func (s *Service) Shutdown() error

type ServiceClient

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

func NewServiceClient

func NewServiceClient(svc *Service, clientCfg *ClientCommonConf) *ServiceClient

func (*ServiceClient) DialBindAddr

func (c *ServiceClient) DialBindAddr(_ context.Context, network string, addr string) (net.Conn, error)

Use the binded address to dial

func (*ServiceClient) DialProxyAddr

func (c *ServiceClient) DialProxyAddr(_ context.Context, network string, addr string) (net.Conn, error)

Use the binded address to dial

func (*ServiceClient) Start

func (c *ServiceClient) Start(force bool) error

func (*ServiceClient) Stop

func (c *ServiceClient) Stop() error

type ServiceConf

type ServiceConf struct {
	Name            string `ini:"-" json:"name"`
	Scheme          string `ini:"type" json:"type"`
	LocalAddr       string `ini:"local_ip" json:"local_ip"`
	LocalPort       uint16 `ini:"local_port" json:"local_port"`
	BindAddr        string `ini:"bind_addr" json:"bind_addr"`
	BindPort        uint16 `ini:"bind_port" json:"bind_port"`
	RemoteAddr      string `ini:"remote_addr" json:"remote_addr"`
	RemotePort      uint16 `ini:"remote_port" json:"remote_port"`
	HTTPServiceConf `ini:",extends"`
}

func GetDefaultServiceConf

func GetDefaultServiceConf() ServiceConf

type ServiceInfo

type ServiceInfo struct {
	Name        string   `json:"name" binding:"required"`
	RemoteAddr  string   `json:"remote_addr,omitempty"`
	ExposedAddr string   `json:"exposed_addr,omitempty"` // address for direct connection
	ProxyAddr   string   `json:"proxy_addr,omitempty"`   // address for proxy_protocol
	Scheme      string   `json:"scheme" binding:"required"`
	Hostnames   []string `json:"hostnames,omitempty"` // binding hostname if scheme is supported
}

type ServiceReflector

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

ServiceReflector is the implementation on Server-side.

func NewServiceReflector

func NewServiceReflector(info *ServiceInfo) *ServiceReflector

func (*ServiceReflector) GetServiceInfo

func (r *ServiceReflector) GetServiceInfo() ServiceInfo

func (*ServiceReflector) Handle

func (r *ServiceReflector) Handle(conn net.Conn) error

Handle an client request

func (*ServiceReflector) Listen

func (r *ServiceReflector) Listen() error

func (*ServiceReflector) Rename

func (r *ServiceReflector) Rename(name string) ServiceInfo

func (*ServiceReflector) Running

func (r *ServiceReflector) Running() bool

func (*ServiceReflector) Serve

func (r *ServiceReflector) Serve()

func (*ServiceReflector) Stop

func (r *ServiceReflector) Stop() error

func (*ServiceReflector) UpdateAddr

func (r *ServiceReflector) UpdateAddr(exposedAddr *string, proxyAddr *string)

type SvcInitConn

type SvcInitConn struct {
	net.Conn
	IsReflected bool // Indicates if the connection is via server
}

type SvcInitMuxListenChanPair

type SvcInitMuxListenChanPair struct {
	Conn *SvcInitConn
	Err  error
}

type TimedService

type TimedService struct {
	*ServiceReflector
	// contains filtered or unexported fields
}

ServiceInfo is a service wrapper

func (TimedService) GetServiceInfoForOutput added in v0.2.0

func (svc TimedService) GetServiceInfoForOutput() ServiceInfo

GetServiceInfoForOutput filters fields for output

func (TimedService) Stop added in v0.2.0

func (svc TimedService) Stop() error

func (TimedService) Timeout

func (svc TimedService) Timeout(s *Server)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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