mirror of
https://github.com/jpillora/chisel
synced 2026-06-08 15:07:02 +00:00
remote: introduce notation for reverse port forwarding
An upcoming enhancement will add reverse port forwarding support (client sharing its ports to the server) to complement the existing port forwarding (server sharing its ports to the client). As a first step, introduce notation for specifying a remote for reverse port forwarding; i.e. "R:<local-interface>:<local-port>:<remote-host>:<remote-port>". At this stage, reverse port forwarding remotes are recognized but never actually created. A subsequent change will flesh out the functionality.
This commit is contained in:
@@ -133,6 +133,9 @@ func (c *Client) Start(ctx context.Context) error {
|
||||
}
|
||||
//prepare proxies
|
||||
for i, r := range c.config.shared.Remotes {
|
||||
if r.Reverse {
|
||||
continue
|
||||
}
|
||||
proxy := chshare.NewTCPProxy(c.Logger, func() ssh.Conn { return c.sshConn }, i, r)
|
||||
if err := proxy.Start(ctx); err != nil {
|
||||
return err
|
||||
|
||||
@@ -98,6 +98,9 @@ func (s *Server) handleWebsocket(w http.ResponseWriter, req *http.Request) {
|
||||
//access to the desired remotes
|
||||
if user != nil {
|
||||
for _, r := range c.Remotes {
|
||||
if r.Reverse {
|
||||
continue
|
||||
}
|
||||
addr := r.RemoteHost + ":" + r.RemotePort
|
||||
if !user.HasAccess(addr) {
|
||||
failed(s.Errorf("access to '%s' denied", addr))
|
||||
|
||||
+18
-3
@@ -20,20 +20,31 @@ import (
|
||||
|
||||
type Remote struct {
|
||||
LocalHost, LocalPort, RemoteHost, RemotePort string
|
||||
Socks bool
|
||||
Socks, Reverse bool
|
||||
}
|
||||
|
||||
func DecodeRemote(s string) (*Remote, error) {
|
||||
const revPrefix = "R:"
|
||||
reverse := false
|
||||
if strings.HasPrefix(s, revPrefix) {
|
||||
s = s[len(revPrefix):]
|
||||
reverse = true
|
||||
}
|
||||
parts := strings.Split(s, ":")
|
||||
if len(parts) <= 0 || len(parts) >= 5 {
|
||||
return nil, errors.New("Invalid remote")
|
||||
}
|
||||
r := &Remote{}
|
||||
r := &Remote{Reverse: reverse}
|
||||
//TODO fix up hacky decode
|
||||
for i := len(parts) - 1; i >= 0; i-- {
|
||||
p := parts[i]
|
||||
//last part "socks"?
|
||||
if i == len(parts)-1 && p == "socks" {
|
||||
if reverse {
|
||||
// TODO allow reverse+socks by having client
|
||||
// automatically start local SOCKS5 server
|
||||
return nil, errors.New("'socks' incompatible with reverse port forwarding")
|
||||
}
|
||||
r.Socks = true
|
||||
continue
|
||||
}
|
||||
@@ -95,7 +106,11 @@ func isHost(s string) bool {
|
||||
|
||||
//implement Stringer
|
||||
func (r *Remote) String() string {
|
||||
return r.LocalHost + ":" + r.LocalPort + "=>" + r.Remote()
|
||||
var tag string
|
||||
if r.Reverse {
|
||||
tag = " [reverse]"
|
||||
}
|
||||
return r.LocalHost + ":" + r.LocalPort + "=>" + r.Remote() + tag
|
||||
}
|
||||
|
||||
func (r *Remote) Remote() string {
|
||||
|
||||
Reference in New Issue
Block a user