diff --git a/README.md b/README.md index ea787f7..b9db1c5 100644 --- a/README.md +++ b/README.md @@ -5,12 +5,15 @@ xtunnel is a simple tunneling tool that allows you to create a tunnel in different ways. +Note: This tool is still in development and is not ready for production use. All connection is done over insecure channels. + ## Installation You can download binary files for each platform from [the latest releases](https://github.com/eminmuhammadi/xtunnel/releases). ## Usage +### Port Forwarding ```bash -xtunnel start --master :9090 --target example.com:80 --protocol tcp4 +xtunnel forward --local : --remote : --protocol tcp ``` diff --git a/cmd/start.go b/cmd/forward.go similarity index 59% rename from cmd/start.go rename to cmd/forward.go index 542f09d..9b71562 100644 --- a/cmd/start.go +++ b/cmd/forward.go @@ -25,24 +25,24 @@ import ( cli "github.com/urfave/cli/v2" ) -func Start() *cli.Command { +func Forward() *cli.Command { return &cli.Command{ - Name: "start", - Aliases: []string{"s"}, + Name: "forward", + Aliases: []string{"f"}, Usage: "Forwards remote connections to local port", Flags: []cli.Flag{ - // -m, --master flag + // -r, --remote flag &cli.StringFlag{ - Name: "master", - Aliases: []string{"m"}, - Usage: "Master node", + Name: "remote", + Aliases: []string{"r"}, + Usage: "Remote node", Required: true, }, - // -t, --target flag + // -l, --local flag &cli.StringFlag{ - Name: "target", - Aliases: []string{"t"}, - Usage: "Target node", + Name: "local", + Aliases: []string{"l"}, + Usage: "Local node", Required: true, }, // -p, --protocol flag @@ -56,36 +56,36 @@ func Start() *cli.Command { Action: func(ctx *cli.Context) error { log.Println("Starting tunnel...") - master := ctx.String("master") - log.Printf("Using %s as master node\n", master) + local := ctx.String("local") + log.Printf("Using %s as local node\n", local) - target := ctx.String("target") - log.Printf("Dialling %s, and using it as target node\n", target) + remote := ctx.String("remote") + log.Printf("Dialling %s, and using it as remote node\n", remote) protocol := ctx.String("protocol") log.Printf("Using %s as protocol\n", protocol) - masterHost, masterPort := strings.Split(master, ":")[0], strings.Split(master, ":")[1] - log.Printf("Master info: %s, port: %s\n", masterHost, masterPort) + localHost, localPort := strings.Split(local, ":")[0], strings.Split(local, ":")[1] + log.Printf("Local info: %s, port: %s\n", localHost, localPort) - targetHost, targetPort := strings.Split(target, ":")[0], strings.Split(target, ":")[1] - log.Printf("Target info: %s, port: %s\n", targetHost, targetPort) + remoteHost, remotePort := strings.Split(remote, ":")[0], strings.Split(remote, ":")[1] + log.Printf("Remote info: %s, port: %s\n", remoteHost, remotePort) - masterPortN, err := strconv.Atoi(masterPort) + localPortN, err := strconv.Atoi(localPort) if err != nil { return err } - targetPortN, err := strconv.Atoi(targetPort) + remotePortN, err := strconv.Atoi(remotePort) if err != nil { return err } - masterNode := pkg.NewNode(masterHost, masterPortN) - targetNode := pkg.NewNode(targetHost, targetPortN) + localNode := pkg.NewNode(localHost, localPortN) + remoteNode := pkg.NewNode(remoteHost, remotePortN) log.Println("Connection established") - if err := pkg.CreateTunnel(protocol, masterNode, targetNode); err != nil { + if err := pkg.CreateTunnel(protocol, localNode, remoteNode); err != nil { return err } diff --git a/main.go b/main.go index 97260d7..38ee226 100644 --- a/main.go +++ b/main.go @@ -34,7 +34,7 @@ var ( ) var commands = []*cli.Command{ - cmd.Start(), + cmd.Forward(), } // Metadata for current release diff --git a/pkg/main.go b/pkg/main.go index 9ed043c..36e46b7 100644 --- a/pkg/main.go +++ b/pkg/main.go @@ -33,7 +33,6 @@ type Node struct { type Tunnel struct { Protocol string Listener net.Listener - Target *Node } // Creates a new node @@ -45,7 +44,7 @@ func NewNode(host string, port int) *Node { } // Listen announces on the local network address. -func (node *Node) Listen(protocol string, target *Node) (Tunnel, error) { +func (node *Node) Listen(protocol string) (Tunnel, error) { listener, err := net.Listen(protocol, fmt.Sprintf("%s:%d", node.Host, node.Port)) if err != nil { @@ -55,7 +54,6 @@ func (node *Node) Listen(protocol string, target *Node) (Tunnel, error) { return Tunnel{ Protocol: protocol, Listener: listener, - Target: target, }, nil } @@ -100,9 +98,9 @@ func Handshake(local net.Conn, remote net.Conn) { } // Creates a new reverse tunnel -func CreateTunnel(protocol string, master *Node, target *Node) error { - // Listen on master - tunnel, err := master.Listen(protocol, target) +func CreateTunnel(protocol string, local *Node, remote *Node) error { + // Listen on local + tunnel, err := local.Listen(protocol) if err != nil { return err @@ -111,14 +109,14 @@ func CreateTunnel(protocol string, master *Node, target *Node) error { defer tunnel.Listener.Close() for { - // Accept connections from master + // Accept connections from local local, err := tunnel.Listener.Accept() if err != nil { return err } - // Dial to target - remote, err := target.Dial(protocol) + // Dial to remote + remote, err := remote.Dial(protocol) if err != nil { return err }