-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for ssh remote port forwarding
This change adds support for a new type of ssh tunnel, the [remote port forwarding](https://www.ssh.com/ssh/tunneling/example#remote-forwarding). Other significant changes: * Adds a new TunnelType attribute to TunnelFlags so it can be passed to the Tunnel object, preparing it to support different types of port forwarding It also improves the description of `start local` command. * Hides how the `SSHChannel` objects are built under `tunnel.New`, opening room to create either ssh `local` or `remote` forwarding tunnels * Adds support for reading `RemoteForward` configuration from the ssh configuration file * Extends the ssh server implementation using for tests to handle "tcpip-forward" requests Partially implements #22.
- Loading branch information
David Pinheiro
committed
Aug 9, 2020
1 parent
905e590
commit b4239ad
Showing
18 changed files
with
492 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var remoteCmd = &cobra.Command{ | ||
Use: "remote", | ||
Short: "Starts a ssh remote port forwarding tunnel", | ||
Long: `Remote Forwarding allows anyone to expose a service running locally to a remote machine. | ||
This could be particular useful for giving someone on the outside access to an internal web application, for example. | ||
Source endpoints are addresses on the jump server where clients can connect to access services running on the corresponding destination endpoints. | ||
Destination endpoints are addresses of services running on the same machine where mole is getting executed. | ||
`, | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
tunnelFlags.TunnelType = "remote" | ||
return nil | ||
}, | ||
Run: func(cmd *cobra.Command, arg []string) { | ||
start("", tunnelFlags) | ||
}, | ||
} | ||
|
||
func init() { | ||
err := bindFlags(tunnelFlags, remoteCmd) | ||
if err != nil { | ||
log.WithError(err).Error("error parsing command line arguments") | ||
os.Exit(1) | ||
} | ||
|
||
startCmd.AddCommand(remoteCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,13 +86,23 @@ The ssh authentication key files, `test-env/key` and `test-env/key,pub` will | |
```sh | ||
$ make test-env | ||
<lots of output messages here> | ||
$ mole --verbose --insecure --local :21112 --local :21113 --remote 192.168.33.11:80 --remote 192.168.33.11:8080 --server [email protected]:22122 --key test-env/ssh-server/keys/key --keep-alive-interval 2s | ||
INFO[0000] tunnel is ready local="127.0.0.1:21113" remote="192.168.33.11:8080" | ||
INFO[0000] tunnel is ready local="127.0.0.1:21112" remote="192.168.33.11:80" | ||
$ curl 127.0.0.1:21112 | ||
:) | ||
$ curl 127.0.0.1:21113 | ||
:) | ||
mole start local \ | ||
--verbose \ | ||
--insecure \ | ||
--source :21112 \ | ||
--source :21113 \ | ||
--destination 192.168.33.11:80 \ | ||
--destination 192.168.33.11:8080 \ | ||
--server [email protected]:22122 \ | ||
--key test-env/ssh-server/keys/key \ | ||
--keep-alive-interval 2s | ||
DEBU[0000] using ssh config file from: /home/mole/.ssh/config | ||
DEBU[0000] server: [name=127.0.0.1, address=127.0.0.1:22122, user=mole] | ||
DEBU[0000] tunnel: [channels:[[source=127.0.0.1:21112, destination=192.168.33.11:80] [source=127.0.0.1:21113, destination=192.168.33.11:8080]], server:127.0.0.1:22122] | ||
DEBU[0000] connection to the ssh server is established server="[name=127.0.0.1, address=127.0.0.1:22122, user=mole]" | ||
DEBU[0000] start sending keep alive packets | ||
INFO[0000] tunnel channel is waiting for connection destination="192.168.33.11:8080" source="127.0.0.1:21113" | ||
INFO[0000] tunnel channel is waiting for connection destination="192.168.33.11:80" source="127.0.0.1:21112" | ||
``` | ||
|
||
NOTE: If you're wondering about the smile face, that is the response from both | ||
|
@@ -116,9 +126,23 @@ $ make test-env | |
2. Start mole | ||
|
||
```sh | ||
$ mole --verbose --insecure --local :21112 --local :21113 --remote 192.168.33.11:80 --remote 192.168.33.11:8080 --server [email protected]:22122 --key test-env/ssh-server/keys/key --keep-alive-interval 2s | ||
INFO[0000] tunnel is ready local="127.0.0.1:21113" remote="192.168.33.11:8080" | ||
INFO[0000] tunnel is ready local="127.0.0.1:21112" remote="192.168.33.11:80" | ||
mole start local \ | ||
--verbose \ | ||
--insecure \ | ||
--source :21112 \ | ||
--source :21113 \ | ||
--destination 192.168.33.11:80 \ | ||
--destination 192.168.33.11:8080 \ | ||
--server [email protected]:22122 \ | ||
--key test-env/ssh-server/keys/key \ | ||
--keep-alive-interval 2s | ||
DEBU[0000] using ssh config file from: /home/mole/.ssh/config | ||
DEBU[0000] server: [name=127.0.0.1, address=127.0.0.1:22122, user=mole] | ||
DEBU[0000] tunnel: [channels:[[source=127.0.0.1:21112, destination=192.168.33.11:80] [source=127.0.0.1:21113, destination=192.168.33.11:8080]], server:127.0.0.1:22122] | ||
DEBU[0000] connection to the ssh server is established server="[name=127.0.0.1, address=127.0.0.1:22122, user=mole]" | ||
DEBU[0000] start sending keep alive packets | ||
INFO[0000] tunnel channel is waiting for connection destination="192.168.33.11:8080" source="127.0.0.1:21113" | ||
INFO[0000] tunnel channel is waiting for connection destination="192.168.33.11:80" source="127.0.0.1:21112" | ||
``` | ||
|
||
3. Kill all ssh processes running on the container holding the ssh server | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.