by chrisallick · 9y ago · 0 comments
WebSockets is a small layer on top of HTTP. And HTTP is a protocol on top of TCP. Right or wrong?
So then why would do this? To get TCP running over port 80 to get through a firewall? Why not just do TCP over port 80?
Like this project https://github.com/jpillora/chisel
Edit: above project is also using websockets. okay, i think i understand why you would do this.
Your question is still valid, I'm just dispelling the myth that WS is like TCP-over-DNS or something similarly inefficient.
The biggest difference there is that while TCP-over-DNS just has TCP->DNS->UDP as overhead, the WS method has TCP->WS->TCP. Because the connection is stateful and the WS encapsulation is minimal, it's more efficient (and HTTP tunneling is almost always more functional than DNS or ICMP, anyway)
It's still inefficient. And it's not a raw socket, it's an application layer socket, essentially.
Anyway, looking at the code of this tool, it doesn't seem like there's any actual TCP being tunneled; from what I can tell, the raw TCP terminates in the application, and the data is piped directly into the WS connection. That's why you have to choose a static target, whereas with a TCP tunneling system like iodine, you can use it as an open gateway.
Fair enough on the raw socket, I meant a TCP socket.
Comparing it to stateful UDP over DNS is a totally fair thing because in practice that is how you use it. You steal the ports of a completely different application to send data for your own different application, and do the hokey-pokey of one protocol before you then encode a payload in a completely different protocol before sending and after receiving it, and the application protocols it abuses to tunnel its data aren't even of the same state or connection mode.
Saying WS is "just framed data over regular TCP" is like saying stateful UDP over DNS is "just framed data over regular UDP". The only difference is that DNS has message reply limits. If you could keep sending one long DNS response payload, WS would be virtually identical to stateful UDP over DNS (when using tcp for the DNS).
And yeah you're right, this app is not encapsulating TCP packets, but it tunnels applications which use TCP. A lot of tunnels do this, although I don't think they advertise themselves as "tunneling TCP through X".
If, say, I wanted to connect to a (probably read-only) public database from my browser, I could not.
This isn't a surprise to anyone, of course. By most definitions, Web == HTML over HTTP.
More specifically, web pages. Browsers usually support more protocols (FTP, for instance) but don't expose the protocols to scripts running on web pages.
in this case, accessing google over HTTPS locally would not work properly, as the `Origin` header as well as the SSL cert wouldn't match.
Sure browsers don't have a js raw socket API, but no browsers are involved in this thing.
Pretty straightforward to use, at that :
const net = require('net');
const client = new net.Socket();
client.connect(port, host, function() {
client.write("hello !");
});https://en.m.wikipedia.org/wiki/Raw_socket
It does not even offer real access to a TCP socket, for example you can't set any options or flags in the TCP header of a packet. All that it provides is a way to open a socket and send / receive data. Very useful, but not a raw socket.