Server2Client (S2C) Port Forwarding
Server install
- Install a Linux virtual machine (Ubuntu 16.04 in my case).
- Install ssh server
apt-get install openssh-server
.
- Edit
/etc/ssh/sshd_config
and add the following line (otherwise ssh will publish the forwarding port only on local host nevermind the client’s rule):
- GatewayPorts clientspecified
- Restart ssh service or the whole server (
shutdown -r now
); watch out that restarting ssh service (like service ssh restart
or service ssh stop
+service ssh start
will not kill existing established ssh sessions because they are run as separate sshd
processes
- Configure the client
- Check that the ssh service listens on 3389 by running
lsof -i :3389
(we target RDP protocol, see Client Install section)
- Check all sshd processes
lsof -i -n | egrep '\<sshd\>'
Client Install
Download and install Bitvise Tunnelier client https://www.bitvise.com/ssh-client-download
Run Bitvise SSH Client:
- Create/save a profile by specifying:
- Login tab
- Host
- Username (SSH user)
- Initial Method
password
- Password
- Store encrypted password in profile
- Options tab:
- Allways reconnect automatically
- Un-check the On-login options
- S2C tab:
- Add as many rules as required by specifying:
- Enabled
- Listen interface: 0.0.0.0 (this means that the SSH server will accept connections on all interfaces)
- Listen port: 3389 (for instance, SSH server will wait connections on this port)
- Destination host (where on the client’s side the connection will be redirected):
- localhost for the local computer
- IP/FQDN for another computer
- Destination port: 3389, to redirect to a local computer RDP requests
- Press Login
Use the Forwarded Port
Suppose that our Linux machine is called sshs2c we can now open a RDP connection on the remote host (the one specified in <Destination host:Destination port>) by connecting to sshs2c:<Listen port>
Windows ssh servers
Remark: I haven’t fully tried the below mentioned OpenSSH approaches but I just would mention them in case you are interested in bypassing the installation of the Linux virtual machine (which actually brings an additional layer of security since you are not exposing your workstation directly over internet on highly sensitive port 22)
PGgxIGlkPSJzZXJ2ZXIyY2xpZW50czJjcG9ydGZvcndhcmRpbmciPlNlcnZlcjJDbGllbnQg
KFMyQykgUG9ydCBGb3J3YXJkaW5nPC9oMT4NCg0KPGgyIGlkPSJzZXJ2ZXJpbnN0YWxsIj5T
ZXJ2ZXIgaW5zdGFsbDwvaDI+DQoNCjx1bD4NCjxsaT5JbnN0YWxsIGEgTGlud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