fiddyschmitt / File-Tunnel

Tunnel TCP connections through a file
MIT License
849 stars 71 forks source link

[Feature Request] SOCKS Proxy #16

Closed YourSandwich closed 3 weeks ago

YourSandwich commented 1 month ago

Hi Fidel,

Thank you very much for this program. I have been looking for a long time for a way to SSH over an RDP server that does not have an SSH server. This finally enables me to do that.

The only con with it is that I can only SSH into one server at a time. It would be awesome if something like this were possible:

ssh -o ProxyCommand='nc -x 127.0.0.1:5000 %h %p' user@ip

This would allow me to create an SSH config file and SSH into multiple SSH servers that are behind the RDP jumphost.

Thank you for your efforts!!!

fiddyschmitt commented 1 month ago

Thanks @YourSandwich!

That's an awesome idea - I'd love to implement it. I'll have a think about how best to do it.

Cheers, Fidel

fiddyschmitt commented 1 month ago

I'm thinking of using a syntax similar to ssh, specifically the -L arg. For example:

Client side

ft.exe -L localIP1:localPort1:destinationHost1:remotePort1 -L localIP2:localPort2:destinationHost2:remotePort2 --write 1.dat --read 2.dat

Server side

ft.exe --read 1.dat --auto-forward --write 2.dat

How does that sound?

fiddyschmitt commented 1 month ago

The server side could also have a way of specifying which remote machines can be connected to (single or ranges):

ft.exe --read 1.dat --auto-forward --write 2.dat --allow 10.0.0.1:22 --allow 192.168.1.1-255:22 --allow 172.16.1.1:8000-8010

fiddyschmitt commented 1 month ago

Alternatively, you could run a SOCKS server such as shinysocks on the remote computer, and use File Tunnel to get data to and from it.

YourSandwich commented 1 month ago

Hi Fiddy,

I tried to use ShinySocks, but it seemed to not work properly. It could be an issue on my side, but it worked standalone if I disabled the Windows firewall.

If you plan to implement the full RFC 1928, I think --socks would be sufficient. The --auto-forward method is cool as well, but it would be limiting in that I still need to specify specific hosts I want to reach, even though this is much better than the current situation.

YourSandwich commented 1 month ago

This is similar to what you can do with SSH:

ssh -N -D 5000 hop-server
ssh -o ProxyCommand='nc -x 127.0.0.1:5000 %h %p' user@behind-hop-ip

This sets up a SOCKS server on port 5000, which also allows the use of HTTPS proxies or proxychains, similar to what was done in #13.

fiddyschmitt commented 3 weeks ago

v2.2.0 now supports tunneling multiple ports, by using the -L arg multiple times.

On your computer, run: ft.exe -L 5000:127.0.0.1:3389 -L 5001:127.0.0.1:8080 --write "\\server\share\1.dat" --read "\\server\share\2.dat"

And on the remote computer, run: ft.exe --read "\\server\share\1.dat" --write "\\server\share\2.dat"

Both 5000 and 5001 will be forwarded through the tunnel.

I'll keep thinking about implementing SOCKS :)

YourSandwich commented 3 weeks ago

This is awesome, It's still not as simple as a SOCKS but, now I could write a script that reads the hostnames out of my ssh config file and automatically creates the tunnel :)

Hey, can I buy you a coffee? I really appreciate your work. Do you have a Monero Wallet or some Donation platform?

Your work really helps me out!

YourSandwich commented 3 weeks ago

I have managed to run the shinysocks server, so theoretically there is a workaround for this.

I am doing following on the Server:

Start-Process \\tsclient\_home_sandwich_Stuff_FS\shinysocks\shinysocks.exe; Start-Process \\tsclient\_home_sandwich_Stuff_FS\ft-win-x64.exe -ArgumentList '--read "\\tsclient\_home_sandwich_Stuff_FS\1.dat" --tcp-connect 127.0.0.1:1080 --write "\\tsclient\_home_sandwich_Stuff_FS\2.dat"'

Then I can connect to the tunnel on my Linux client: ./Stuff/FS/ft-linux-x64 --tcp-listen 127.0.0.1:5000 --write "Stuff/FS/1.dat" --read "Stuff/FS/2.dat"

This allows me to connect to any Host:Port behind from the Server's side: ssh -o ProxyCommand='nc -x 127.0.0.1:5000 %h %p' sandwich@192.168.122.51

This also works as an HTTPs Proxy: image

So if you want to keep this binary as simple as possible, this can be a solution for people like me.

fiddyschmitt commented 3 weeks ago

So cool! Thanks!!

fiddyschmitt commented 3 weeks ago

I also found a way to run a SOCKS server on Linux (to share its internet connection), without using any third-party tools.

On the Linux machine:

On the Windows machine:

image

YourSandwich commented 3 weeks ago

Unfortunately this does not work on most Windows Servers because they don't have ssh-server preinstalled :<

fiddyschmitt commented 3 weeks ago

True :`(

fiddyschmitt commented 3 weeks ago

As described above, a SOCKS Proxy Server can be run on Windows using shinysocks, and on Linux without any third-party tools, described here.

For that reason I won't be implementing SOCKS within File Tunnel for now.

Thanks @YourSandwich for the adventure!