Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v9] ssh: Ignore PuTTY-specific channel requests #12662

Merged
merged 4 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/srv/regular/sshserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,13 @@ func (s *Server) dispatch(ch ssh.Channel, req *ssh.Request, ctx *srv.ServerConte
log.Warn(err)
}
return nil
case sshutils.PuTTYSimpleRequest:
// PuTTY automatically requests a named '[email protected]' channel any time it connects to a server
// as a proxy to indicate that it's in "simple" node and won't be requesting any other channels.
webvictim marked this conversation as resolved.
Show resolved Hide resolved
// As we don't support this request, we ignore it.
// https://the.earth.li/~sgtatham/putty/0.76/htmldoc/AppendixG.html#sshnames-channel
log.Debugf("%v: deliberately ignoring request for '%v' channel", s.Component(), sshutils.PuTTYSimpleRequest)
return nil
default:
return trace.BadParameter(
"(%v) proxy doesn't support request type '%v'", s.Component(), req.Type)
Expand Down
135 changes: 135 additions & 0 deletions lib/srv/regular/sshserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,141 @@ func TestX11ProxySupport(t *testing.T) {
require.Equal(t, string(msg), string(rsp))
}

// TestIgnorePuTTYSimpleChannel verifies that any request from the PuTTY SSH client for
// its "simple" mode is ignored and connections remain open.
func TestIgnorePuTTYSimpleChannel(t *testing.T) {
t.Parallel()

f := newFixture(t)
ctx := context.Background()

listener, _ := mustListen(t)
logger := logrus.WithField("test", "TestIgnorePuTTYSimpleChannel")
proxyClient, _ := newProxyClient(t, f.testSrv)
lockWatcher := newLockWatcher(ctx, t, proxyClient)
nodeWatcher := newNodeWatcher(ctx, t, proxyClient)

reverseTunnelServer, err := reversetunnel.NewServer(reversetunnel.Config{
ClientTLS: proxyClient.TLSConfig(),
ID: hostID,
ClusterName: f.testSrv.ClusterName(),
Listener: listener,
HostSigners: []ssh.Signer{f.signer},
LocalAuthClient: proxyClient,
LocalAccessPoint: proxyClient,
NewCachingAccessPoint: noCache,
NewCachingAccessPointOldProxy: noCache,
DirectClusters: []reversetunnel.DirectCluster{{Name: f.testSrv.ClusterName(), Client: proxyClient}},
DataDir: t.TempDir(),
Emitter: proxyClient,
Log: logger,
LockWatcher: lockWatcher,
NodeWatcher: nodeWatcher,
})
require.NoError(t, err)

require.NoError(t, reverseTunnelServer.Start())
defer reverseTunnelServer.Close()

nodeClient, _ := newNodeClient(t, f.testSrv)

proxy, err := New(
utils.NetAddr{AddrNetwork: "tcp", Addr: "localhost:0"},
f.testSrv.ClusterName(),
[]ssh.Signer{f.signer},
proxyClient,
t.TempDir(),
"",
utils.NetAddr{},
proxyClient,
SetProxyMode(reverseTunnelServer, proxyClient),
SetSessionServer(proxyClient),
SetEmitter(nodeClient),
SetNamespace(apidefaults.Namespace),
SetPAMConfig(&pam.Config{Enabled: false}),
SetBPF(&bpf.NOP{}),
SetRestrictedSessionManager(&restricted.NOP{}),
SetClock(f.clock),
SetLockWatcher(lockWatcher),
SetNodeWatcher(nodeWatcher),
)
require.NoError(t, err)
require.NoError(t, proxy.Start())
defer proxy.Close()

// set up SSH client using the user private key for signing
up, err := newUpack(f.testSrv, f.user, []string{f.user}, wildcardAllow)
require.NoError(t, err)

sshConfig := &ssh.ClientConfig{
User: f.user,
Auth: []ssh.AuthMethod{ssh.PublicKeys(up.certSigner)},
HostKeyCallback: ssh.FixedHostKey(f.signer.PublicKey()),
}

_, err = newUpack(f.testSrv, "user1", []string{f.user}, wildcardAllow)
require.NoError(t, err)

// Connect SSH client to proxy
client, err := ssh.Dial("tcp", proxy.Addr(), sshConfig)

require.NoError(t, err)
defer client.Close()

se, err := client.NewSession()
require.NoError(t, err)
defer se.Close()

writer, err := se.StdinPipe()
require.NoError(t, err)

reader, err := se.StdoutPipe()
require.NoError(t, err)

// Request the PuTTY-specific "[email protected]" channel type
// This request should be ignored, and the connection should remain open.
_, err = se.SendRequest(sshutils.PuTTYSimpleRequest, false, []byte{})
require.NoError(t, err)

// Request proxy subsystem routing TCP connection to the remote host
require.NoError(t, se.RequestSubsystem(fmt.Sprintf("proxy:%v", f.ssh.srvAddress)))

local, err := utils.ParseAddr("tcp://" + proxy.Addr())
require.NoError(t, err)
remote, err := utils.ParseAddr("tcp://" + f.ssh.srv.Addr())
require.NoError(t, err)

pipeNetConn := utils.NewPipeNetConn(
reader,
writer,
se,
local,
remote,
)

defer pipeNetConn.Close()

// Open SSH connection via proxy subsystem's TCP tunnel
conn, chans, reqs, err := ssh.NewClientConn(pipeNetConn,
f.ssh.srv.Addr(), sshConfig)
require.NoError(t, err)
defer conn.Close()

// Run commands over this connection like regular SSH
client2 := ssh.NewClient(conn, chans, reqs)
require.NoError(t, err)
defer client2.Close()

se2, err := client2.NewSession()
require.NoError(t, err)
defer se2.Close()

out, err := se2.Output("echo hello again")
require.NoError(t, err)

require.Equal(t, "hello again\n", string(out))
}

// upack holds all ssh signing artefacts needed for signing and checking user keys
type upack struct {
// key is a raw private user key
Expand Down
4 changes: 4 additions & 0 deletions lib/sshutils/req.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ const (

// X11ChannelRequest is the type of an X11 forwarding channel.
X11ChannelRequest = "x11"

// PuTTYSimpleRequest is a PuTTY-specific channel name which it automatically requests when it proxies
// connections. Teleport does not support this channel type, so deliberately ignores requests for it.
PuTTYSimpleRequest = "[email protected]"
)

const (
Expand Down