Full SSH proxy over a reverse SSH connection - ssh

There are tools like sshuttle that allow proxying of all traffic through an outbound SSH connection. In our case, we can only SSH into the server, and would like to then proxy all outbound traffic over the inbound SSH connection. Is this possible?

It's possible using ssh port forwarding.In this scenario let's say you can ssh login into b, the command
ssh -L2001:HostD:143 user#HostB will use the ssh tunnel to forward all the outbound traffic from your port 2001 to the port 143 of the HostD , And as you can see ,you can replace HostD by by localhost ,that would made it instead forward the traffic to the port 143 of HostB
Image credit goes to https://www.youtube.com/watch?v=JKrO5WABdoY&t=251s

Related

How does SSH dynamic forward (-D) function under the hood?

How does SSH dynamic forward (-D) function under the hood?
I understand that SSH dynamic forward opens a SOCSK4 proxy on the local host, and that each connection to the SOCK4 proxy is forwarded over the SSH tunnel to the remote destination.
Does SSH intercept the connections to the SOCKS4 proxy? I mean, it cannot be a "normal" SOCKS4 proxy, because then it would directly proxy the connections to the remote hosts.
Furthermore, how does SSH handle responses from the remote hosts, i.e., how does it transfer them back over the SSH tunnel to the recipients on the local host?
When the -D flag is given, the SSH client will start a built-in SOCKS4/5 proxy. (note: "SOCKS", not "SOCK").
-D [bind_address:]port
Specifies a local “dynamic” application-level port forwarding. This works by allocating a socket to listen to port on the local side, optionally bound to the specified bind_address. Whenever a connection is made to this port, the connection is forwarded over the secure channel, and the application protocol is then used to determine where to connect to from the remote machine. Currently the SOCKS4 and SOCKS5 protocols are supported, and ssh will act as a SOCKS server.
When another application wishes to connect to a proxied service, they will establish a connection via this SOCKS server. The SOCKS protocol is a little bit of negotiation that occurs at the beginning of a connection, something like this: (inspired by the wiki page)
ssh -D 1234 user#remote is execute, the SSH client starts a SOCKS proxy server listening on port 1234.
A local application wishes to communicate with a service via the SOCKS proxy, so connects to port 1234.
The SOCKS client asks for a connection to a particular IP address and port - e.g: 66.102.7.99, port 4321.
The SOCKS server, in this case the SSH client, will negotiate to establish this onward connection with it's server (remote, from above). This may fail.
The SOCKS serve will respond to the client with success / failure information.
If successful, all data passed through this socket will now be forwarded appropriately:
From the local application, to the SSH server (remote), and then onto 66.102.7.99.
From 66.102.7.99 to the SSH server (remote), and then onto the local SSH client, and ultimately the local application.
Does SSH intercept the connections to the SOCK4 proxy?
No, the SSH Client is the SOCKS proxy.
I mean, it cannot be a "normal" SOCK4 proxy, because then it would directly proxy the connections to the remote hosts.
I suppose it's not really - the SSH Client and Server act together to achieve the function of a "normal" SOCKS proxy. The high-level result is that the proxy listens on one host, but forwards data from another host, with a magical link in between.
Furthermore, how does SSH handle responses from the remote hosts, i.e., how does it transfer them back over the SSH tunnel to the recipients on the local host?
TCP is a connection-oriented method of communication. That is to say that once a connection is established, data can flow in both directions, and is reliably identified as "related to that connection". With this information it is trivial to associate the data with arbitrary rules such as "forward to the SSH server, who will forward to 66.102.7.99".

Forward server HTTP traffic to handle in another device via SSH Tunnel

I'm developing some webhook required direct access public domain to internal machine, thinking use SSH tunnel to forward data, or got alternative solution?
Hosting server & development machine are in same network
192.168.1.2/24 (Hosting server)
2nd machine is virtual mapping using forticlient firewall without static or dynamic IP in visible in hosting server, so is 1 way initial communication right now.
In this case possible to setup SSH tunnel forward all traffic from 192.168.1.2:80 to handle in development machine port 8080?
How to ssh syntax look like?
Thanks.
This could be done by setting up an SSH tunnel to the remote machine:
ssh -L localhost:80:localhost:8080 development-system
Every request to port 80 on the hosting-server is now forwarded to port 8080 on the development-system.
Please note, that the port 80 on the hosting-server could only be used, when you start the SSH command as root. Also note that the port 80 is only accessible from the hosting-server. To access the port 80 on the hosting-server from everywhere use the following:
ssh -L 80:localhost:8080 development-system
Be sure that you want that.
A good introduction to the topic could be found at
https://www.ssh.com/ssh/tunneling/example
https://unix.stackexchange.com/questions/115897/whats-ssh-port-forwarding-and-whats-the-difference-between-ssh-local-and-remot

SSH tunnel behind Squid proxy server

How can I configure squid server on my local machine to redirect traffic to SSH tunnel created with Putty?
That's my goal:
webBrowser--->Squid--->SSHTunnel--->remoteServer--->anything

Able to connect to ssh server on any port using an ssh tunnel

I'm having a little problem with the ssh server running on an ubuntu server. I'm using key-pair authentication, and i'm able to connect just fine, but the problem is that i can connect on any port (using a tunnel), even though "Port 22" is defined in sshd_config. Why am i able to connect on any port? How can i stop ssh from listening to ports other than port 22?
In your screenshot Local Address column tells that you are listening on all interfaces at port 22 (e.g. 0.0.0.0:22). The Foreign Address column tells that anyone can connect from any ip from any port (e.g 0.0.0.0:*). And below the same for IPV6.
The connections are normally started from some random free high number port so it's ok to have wildcard in Foreign address. The only thing you care about is that there is a listener at local port 22. Just as you wanted.
You are connecting the port 22 first (as you don't specify anything else with -p switch) and then ssh directs data from port 54321 of one machine to 80 of the other. So, the path of the data is something like:
Machine A, port 54321 -> Machine A, port random -> Machine B, port 22, Machine B, port 80.
So the thing is, when not defined, it will connect to the ssh server on the default port 22. you can explicitly define the port using "-p xxxx" where xxxx is the ssh server port you want to connect to. When tunneling, the "local port" is the port on your computer you will connect to, and "remote port" is the port on the remote computer that the connection will end on. so its like this:
(localport->randomport)->->->->(sshport->remoteport)
sshport is defined by -p, and the default when not defined is port 22

firewall has blocked ssh. any wayarounds?

I want to connect to remote amazon aws service(EC2 instance) , and I would like to be able to ssh to it from my laptop while using the campus provided network (which has cyberoam firewall). However, they have pretty much every port blocked and ssh won't work. Is there anything i can do? does ssh run through port 80? I don't really know what to do .
All it says is :
ssh_exchange_identification: read: Software caused connection abort
ssh works elsewhere.
You can set your SSH server to use port 80 (or 443 if 80 is used for a webserver). Just check the configuration file of your ssh server for more details!