mscdex / ssh2

SSH2 client and server modules written in pure JavaScript for node.js
MIT License
5.52k stars 664 forks source link

Socks client works fine with normal SSH server but doesnt work with this #1214

Closed AirplanegoBrr closed 2 years ago

AirplanegoBrr commented 2 years ago

The SSH client to an openSSH server (running on windows) works fine however when trying to do the same using the node server it doesn't do anything...

I did check the docs and the server has an event called tcpip and it only gives me the following: accpet, reject, info (info is a object and has destIP, destPort, srcIP, srcPort) this would work but what about headers, query, etc? And what about websockets and online games like Robox, Minecraft, etc?

Im not 100% sure if javascript is able to handle all the data I will be pushing (Around 4ish clients at once constantly pushing data) But I would just like to try and see if its gonna work

Im trying to replace my current proxy that I'm using and it is as follows: (this has nothing to do with the issue its just more info of what my end goal is) ``` BitviseSSH connects to my home computer, after that it makes a socks v5 proxy available at 127.0.0.1:1080 and then I use a program called `Proxifier` I want to replace both my SSH client and my SSH server with this nodejs module (proxifier will stay in place) The reason is that I want better control of the ssh server (kicking users, seeing what they are on, etc) and better/easier time for my clients that also use this ```

Info: OS: Windows 10 (Could use Ubuntu but I would prefer to use windows if possible) NodeJS version: v16.0.0 Module version: ssh2@1.11.0, socksv5@0.0.6

If more info is needed feel free to ask! For my socks proxy I'm using the example found in the readme and I'm also using one of the examples for the ssh server

mscdex commented 2 years ago

Forwarded connections in SSH are just plain byte streams. SSH knows nothing about specific higher-level protocols, that is up to you to handle.

If you accept() the request, you get back a node stream that represents the TCP connection. You can either read from it/write to it directly, pipe it to some other stream, or do something else. If you're implementing a "dumb proxy", then you could just immediately attempt to make a connection to the requested destination IP:port first and then only accept() if you were able to successfully connect (reject()ing otherwise), followed by piping the two streams together.

The important thing is that ssh2 does not handle any of this for you (for flexibility reasons), much like it does not automatically proxy connections on the client side (e.g. using SOCKS).

AirplanegoBrr commented 2 years ago

Im new to using nodejs to handle SSH and handling streams How would I stream the accept() to and from node to the requested server? Could you point me in the right direction?

mscdex commented 2 years ago

Typically you should have a stream representing the destination connection. Just pipe it together with the stream from accept().