Tunnel TCP Through WebSockets (CLI Tool)
github.com
github.com
That said...You could just use corkscrew.
https://wiki.archlinux.org/index.php/HTTP_tunneling
Corkscrew + SSH has been helping individuals escape restrictive corporate networks for years.
Pretty sure SSH for remote server on port 443 plus corkscrew offers more than this solution. (Socks proxy, etc. Very flexible. No need for DNS muckery you would need with this solutions example etc.)
And it's all about the web browser, so...
I was told by the developer that he uses it also to maintain hundreds of machines which don't have a public IP.
You can pass PPP or SLIP via WebSockets and connect to the Internet that way. That's already used for connecting DOSBox running in a web browser to the Internet: http://blog.vrcade.io/2017/03/setting-up-a-visp-using-pppow/
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.
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 !");
});For this use case: That they are an extension of HTTP, and thus can pass modern HTTP proxies.
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.
node core can only tell if a file is a socket, but not read from it, at least that's what the docs say.
for people interested in this: https://github.com/santigimeno/node-unix-stream
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.
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".
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.
https://github.com/derhuerst/tcp-over-websockets/blob/master...
It's encrypted so firewalls shouldn't be able to tell the difference.
I would indeed find it surprising if any commercial firewalls distinguish websockets over TLS versus raw bytes over TLS. Not that it's impossible, but I wouldn't think it would be done commercially.
Also, having the DoD as a client will buy you some serious R&D time.
And is machine learning fast enough for live network filters?
You're right that TLS is not 100% random, there is some information to work with: the size of the encrypted blobs (they're rounded because of padding) and the timing of them. Are there any commercial firewalls that do analysis of this kind for the purpose of blocking the traffic? It wouldn't be able the block all the traffic, because it would have to wait a while to get more timing data that it can apply its heuristics, then end the connection.
And it wouldn't be able to unpack protocol layers.
The two oldest and most successful methods that I know of are matching on payload length and models trained on the initialization of network application protocols, neither of which requires constantly re-sampling and re-classifying to get a hit. And blocking traffic is often more about terminating an existing connection once you detect something bad going over it (deep content inspection).
Yes, commercial firewalls do look for tunneled applications. Palo Alto Networks has a patent on it (App-ID), Websense/Forcepoint does it (Content Gateway Analysis), Cisco sort of implements it (Network Based Application Recognition/Application Visibility and Control).
A bunch of open source software implements it, too. Some commercial proprietary software is also out there, with PACE leading the pack. Wikileaks has one of their product data sheets: https://wikileaks.org/spyfiles/docs/IPOQUE-PACEProtAppl-en.p...
Honestly, a lot of customers simply force proxies on their users and inspect all their traffic and drop anything that it can't inspect, so there probably isn't a lot of commercial need for this. But it is out there.
I don't see why? Just have N multiple outstanding requests to the server (with N being large enough to achieve whatever communication rate you can accept). When the server wants to send you something, it picks one and replies to it. While you're busy processing it the server can still reply to anther one and send more data. When you're done you send more outstanding requests to the server to reach N again.
And if you ever run out of outstanding requests, then that's equivalent to your socket not being able to accept a new connection because there are too many pending already, which can always happen.
The downside is you end up with a complex stateful protocol, with multiple sockets, and need the ability to handle out-of-order data. If you're targeting a platform that can't do HTTP streaming, then sure, but otherwise this is a pretty gnarly road to go down.
My personal preference for long-polling is to use it for stateless / RESTful APIs that have infrequent updates. Super clean, easy to use from the client's perspective, and efficient enough. I would not use it for stateful communication (IMO SockJS and Engine.IO are gross but I understand why they exist).
But if this is not needed, then long-polling is perfectly sufficient for push delivery.
Note that these things can also be solved with HTTP by using streaming, so WebSocket isn't strictly required as a solution. About the only difference between two single-directional HTTP streams and a WebSocket is that the WebSocket ensures data in both directions travels the same network path, which may make scaling or stateful sessions easier to build.
Sigh. Of course I develop network virtualization software so I'm just as guilty of it.
(I also run a semi-related project, without the decentralized magic of ZeroTier)
How's your buffer bloat? — Fine, how's yours? — Great, thanks for asking!
HTTPS VPNs require TLS, and some proxies don't let you use TLS, because you might tunnel with it. It's pretty easy to block most HTTP tunneling because they typically use the CONNECT method. Ones that simply do an HTTP handshake and then pass the socket to a tunneling program can be detected or simply terminated after the session has gone on for a while or transferred a certain number of bytes. BOSH connections are a little more reliable, and I don't know off the top of my head if any tunneling apps support chunked encoding/multipart/etc, but it's possible to implement a tunnel using only valid HTTP methods, but it would be inefficient. Basically, most tunnels can be defeated without negative impact to regular users because HTTP isn't supposed to be used that way.
In comes WebSockets. Since it's a part of the modern web, and disabling them would negatively affect user experiences on the web, you can abuse them to tunnel random crap and proxies can't really do anything about it. The protocol even allows for obfuscation to make it difficult to see what's going over the socket (though it was intended to prevent cache poisoning attacks).
So in theory, if you can reach a target HTTP server, WebSockets may be the most reliable method to tunnel a connection over HTTP. The fact that it also supports multiple streams may make it faster than alternatives. And the fact that you don't need to use TLS may make it even faster, assuming the app you're tunneling does its own encryption.
built on WebSockets
built on HTTP
built on TCP
This is like where newborn babies and the elderly have a lot in common.
In other words, WebSockets is a TCP protocol that mimicks HTTP during the handshake in order to be left alone by proxies and whatnot.
Ahem: https://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_tunne...
In this mechanism, the client asks an HTTP Proxy server to forward the TCP
connection to the desired destination. The server then proceeds to make
the connection on behalf of the client. Once the connection has been established
by the server, the Proxy server continues to proxy the TCP stream to and from the
client. Note that only the initial connection request is HTTP - after that,
the server simply proxies the established TCP connection.
Both HTTP CONNECT and WS are designed to work over http proxies, both are designed to tunnel arbitrary application data, both use http to initiate a connection, both use http application ports for these connections, and neither of them return to http request-responses once they're set up.But somehow, WS is a separate protocol and stops being http, while HTTP CONNECT is just an HTTP extension and becomes some other application proxied over http.
I guess WS is just special.