简体   繁体   English

HTTPS 隧道

[英]Tunnel over HTTPS

At my workplace, the traffic blocker/firewall has been getting progressively worse.在我的工作场所,流量拦截器/防火墙越来越糟糕。 I can't connect to my home machine on port 22, and lack of ssh access makes me sad.我无法通过 22 端口连接到我的家用机器,而且缺乏 ssh 访问让我感到难过。 I was previously able to use SSH by moving it to port 5050, but I think some recent filters now treat this traffic as IM and redirect it through another proxy, maybe.我以前可以通过将 SSH 移动到端口 5050 来使用 SSH,但我认为最近的一些过滤器现在将此流量视为 IM,并可能通过另一个代理将其重定向。 That's my best guess;这是我最好的猜测; in any case, my ssh connections now terminate before I get to log in.无论如何,我的 ssh 连接现在在我登录之前终止。

These days I've been using Ajaxterm over HTTPS, as port 443 is still unmolested, but this is far from ideal.这些天我一直在通过 HTTPS 使用 Ajaxterm,因为端口 443 仍然不受干扰,但这远非理想。 (Sucky terminal emulation, lack of port forwarding, my browser leaks memory at an amazing rate...) I tried setting up mod_proxy_connect on top of mod_ssl , with the idea that I could send a CONNECT localhost:22 HTTP/1.1 request through HTTPS, and then I'd be all set. (糟糕的终端仿真,缺少端口转发,我的浏览器以惊人的速度泄漏内存......)我尝试在mod_ssl之上设置mod_proxy_connect ,我的想法是我可以通过 HTTPS 发送一个CONNECT localhost:22 HTTP/1.1请求,然后我就准备好了。 Sadly, this seems to not work;可悲的是,这似乎行不通。 the HTTPS connection works, up until I finish sending my request; HTTPS 连接有效,直到我完成发送请求; then SSL craps out.然后 SSL 废话。 It appears as though mod_proxy_connect takes over the whole connection instead of continuing to pipe through mod_ssl , confusing the heck out of the HTTPS client.似乎mod_proxy_connect接管了整个连接,而不是继续通过mod_ssl进行管道传输,这让 HTTPS 客户端感到困惑。

Is there a way to get this to work?有没有办法让它工作? I don't want to do this over plain HTTP, for several reasons:我不想通过纯 HTTP 执行此操作,原因如下:

  • Leaving a big fat open proxy like that just stinks留下一个像这样的大胖子开放代理只会很臭
  • A big fat open proxy is not good over HTTPS either, but with authentication required it feels fine to me一个大的开放式代理也不适合 HTTPS,但是需要身份验证对我来说感觉很好
  • HTTP goes through a proxy -- I'm not too concerned about my traffic being sniffed, as it's ssh that'll be going "plaintext" through the tunnel -- but it's a lot more likely to be mangled than HTTPS, which fundamentally cannot be proxied HTTP通过代理——我不太担心我的流量被嗅探,因为它将通过隧道“纯文本”传输——但它比HTTPS更容易被破坏,而HTTPS基本上不能被代理

Requirements:要求:

  • Must work over port 443, without disturbing other HTTPS traffic (ie I can't just put the ssh server on port 443, because I would no longer be able to serve pages over HTTPS)必须在端口 443 上工作,而不会干扰其他 HTTPS 流量(即我不能将 ssh 服务器放在端口 443 上,因为我将不再能够通过 HTTPS 提供页面)
  • I have or can write a simple port forwarder client that runs under Windows (or Cygwin)我拥有或可以编写一个在 Windows(或 Cygwin)下运行的简单端口转发器客户端

Edit编辑

DAG: Tunnelling SSH over HTTP(S) has been pointed out to me, but it doesn't help: at the end of the article, they mention Bug 29744 - CONNECT does not work over existing SSL connection preventing tunnelling over HTTPS, exactly the problem I was running into. DAG:有人向我指出了通过 HTTP(S) 建立 SSH 隧道,但这并没有帮助:在文章的末尾,他们提到了Bug 29744 - CONNECT 不适用于现有的 SSL 连接,从而阻止了 HTTPS 上的隧道,正是我遇到的问题。 At this point, I am probably looking at some CGI script, but I don't want to list that as a requirement if there's better solutions available.此时,我可能正在查看一些 CGI 脚本,但如果有更好的解决方案可用,我不想将其列为要求。

Find out why the company has such a restrictive policy.找出为什么公司有这样的限制性政策。 It might be for a good reason.这可能是有充分理由的。

If you still find that you want to bypass the policy, you could write a small proxy that will listen on your server on port 443 and then, depending on the request, will forward the traffic either to your web server or to the SSH daemon.如果您仍然想绕过该策略,您可以编写一个小型代理,在您的服务器上侦听端口 443,然后根据请求将流量转发到您的 Web 服务器或 SSH 守护程序。 There are two catches though.不过有两个问题。

  1. To determine whether it's an HTTPS request or an SSH request, you need to try to read some data with a (small) timeout, this is because TLS/SSL handshakes start with the client sending some data, whereas the SSH handshake starts with the server sending some data.要确定是 HTTPS 请求还是 SSH 请求,您需要尝试读取一些具有(小)超时的数据,这是因为 TLS/SSL 握手从客户端发送一些数据开始,而 SSH 握手从服务器开始发送一些数据。 The timeout has to be big enough to delays in delivering the initial data from the client in the TLS/SSL handshake, so it'll make establishing SSH connections slower.超时必须足够大,以延迟在 TLS/SSL 握手中从客户端传递初始数据,因此它会使建立 SSH 连接的速度变慢。

  2. If the HTTP proxy in your company is smart, it'll actually eavesdrop on the expected TLS/SSL "handshake" when you CONNECT to port 443, and, when it detects that it's not an TLS/SSL handshake, it might terminate the SSH connection attempt.如果您公司中的 HTTP 代理很智能,那么当您CONNECT到端口 443 时,它实际上会窃听预期的 TLS/SSL“握手”,并且当它检测到它不是 TLS/SSL 握手时,它可能会终止 SSH连接尝试。 To address that, you could wrap the SSH daemon into an TLS/SSL tunnel (eg, stunnel ), but then you'll need to differentiate requests based on the TLS/SSL version in your client request to determine whether to route the TLS/SSL connection to the web server or to the TLS/SSL-tunneled SSH daemon.为了解决这个问题,您可以将 SSH 守护程序包装到 TLS/SSL 隧道(例如stunnel )中,但是您需要根据客户端请求中的 TLS/SSL 版本来区分请求以确定是否路由 TLS/与 Web 服务器或 TLS/SSL 隧道 SSH 守护程序的 SSL 连接。

You should be able to use iptables to forward ssh traffic from your work machines to ssh while all other machines attaching to your home server on port 443 get the Apache server.您应该能够使用 iptables 将 ssh 流量从您的工作机器转发到 ssh,而在端口 443 上连接到您的家庭服务器的所有其他机器都可以获取 Apache 服务器。

Try a rule like this:试试这样的规则:

iptables -t nat -A PREROUTING -p tcp -s 111.111.111.111 --dport 433 -j REDIRECT --to-port 22

Where 111.111.111.111 is your office computer's ip address.其中 111.111.111.111 是您办公室计算机的 IP 地址。

That all assumes you're running Linux >= 2.4, which you should be by now.这一切都假设您正在运行 Linux >= 2.4,您现在应该是。 It's been out for almost a decade.它已经出现了将近十年。

Documentation for iptables is at http://www.netfilter.org . iptables 的文档位于http://www.netfilter.org

Set up OpenVPN 2.1 server at home, use port 443 (if you set up your home any HTTPS service at port 443, trigger OpenVPN's port-share option to handle both OpenVPN and HTTPS transactions at port 443; this feature is only available to non-Windows OS)在家设置 OpenVPN 2.1 服务器,使用 443 端口(如果你在 443 端口设置了任何 HTTPS 服务,触发 OpenVPN 的端口共享选项,在 443 端口同时处理 OpenVPN 和 HTTPS 事务;此功能仅适用于非视窗操作系统)

Then, set up your OpenVPN client on your laptop in road-warrior mode to access the OpenVPN server at home.然后,在您的笔记本电脑上以公路战士模式设置您的 OpenVPN 客户端,以访问家中的 OpenVPN 服务器。 You will be able to call home or anywhere you like within a secure VPN network you've created with OpenVPN.在您使用 OpenVPN 创建的安全 VPN 网络中,您将能够在家中或任何您喜欢的地方打电话。 It is no longer required to use SSH for this purpose.不再需要为此目的使用 SSH。

I'm really sorry for being the Devil's advocate here, but if they are blocking ports at your work, its likely because they don't want people breaching security.我真的很抱歉在这里成为魔鬼的拥护者,但如果他们在你的工作中封锁了端口,很可能是因为他们不希望人们破坏安全。

Now if you get permission to open a tunnel from your boss, that's fine, but IF something happens, ANYTHING, and they figure out you have a tunnel, I can almost assure you, you'll become the scapegoat.现在,如果你得到老板的许可打开隧道,那很好,但如果发生了什么事,任何事情,他们发现你有隧道,我几乎可以向你保证,你会成为替罪羊。 So if I were you I'd not be opening tunnels at work if they are setting up firewalls against it.因此,如果我是你,如果他们设置防火墙,我就不会在工作中打开隧道。

How about using 2 IP adresses on your machine?在你的机器上使用 2 个 IP 地址怎么样?

Bind apache/https on one IP_1:443 and your sshd on the other IP_2:443?在一个 IP_1:443 上绑定 apache/https,在另一个 IP_2:443 上绑定你的 sshd?

Could you set up a middle man?能不能找个中间人?

Run a small/free/cheap instance in the cloud listening on 443 for SSH, then though that cloud instance tunnel to your home box on your favorite port - 22 or whatever.在云中运行一个小型/免费/便宜的实例,在 443 上侦听 SSH,然后通过该云实例在您最喜欢的端口(22 或其他端口)上通过隧道连接到您的 home box。

It'll add some latency I'm sure, but it solves the problem of leaving the original home setup intact.我敢肯定,它会增加一些延迟,但它解决了保持原始家庭设置完好无损的问题。

I think you'll have to find a port that you're not using currently that you can get out on, and listen on that.我认为你必须找到一个你目前没有使用的端口,你可以离开,然后听它。 443 is the obvious candidate, but you say that's not possible. 443 是明显的候选者,但你说那是不可能的。 What about mail (25, 110, 143), telnet (23), ftp (21), DNS (53), or even whois (43)? mail (25, 110, 143), telnet (23), ftp (21), DNS (53) 甚至 whois (43) 呢?

Proxy tunnel may be your answer代理隧道可能是您的答案

http://proxytunnel.sourceforge.net/ http://proxytunnel.sourceforge.net/

lets say my ssh server is host.domain.tld and my works proxy server is 10.2.4.37假设我的 ssh 服务器是 host.domain.tld 而我的工作代理服务器是 10.2.4.37

I would add this to my local ssh config我会将其添加到我的本地 ssh 配置中

Host host.domain.tld ProxyCommand /usr/local/bin/proxytunnel -q -p 10.2.4.37:3128 -d %h:%p ProtocolKeepAlives 30主机 host.domain.tld ProxyCommand /usr/local/bin/proxytunnel -q -p 10.2.4.37:3128 -d %h:%p ProtocolKeepAlives 30

Since apache has no problem whatsoever with CONNECT when no SSL is involved, I turn off SSL features and I use stunnel to serve an https version of my site.由于 apache 在不涉及 SSL 时对 CONNECT 没有任何问题,因此我关闭了 SSL 功能并使用 stunnel 为我的网站提供 https 版本。 This does not require any recompilation, and allows your site to serve https normally.这不需要任何重新编译,并允许您的站点正常提供 https。 So far, the cleanest workaround I know.到目前为止,我所知道的最干净的解决方法。

See http://chm.duquesne.free.fr/blog/?p=281 for details.有关详细信息,请参阅http://chm.duquesne.free.fr/blog/?p=281

I managed to bypass my company's firewall using the following design via AjaxTerm, it works for me.我通过 AjaxTerm 使用以下设计设法绕过了我公司的防火墙,它对我有用。

PC on company network --> company's proxy via https --> INTERNET --> My home Apache reverse proxy server on SSL + .htpasswd protection --> AjaxTerm Server(From here on ward, I can SSH to any other servers ).公司网络上的 PC --> 公司通过 https 的代理 --> INTERNET --> 我在 SSL + .htpasswd 保护上的家庭 Apache 反向代理服务器 --> AjaxTerm 服务器(从这里开始,我可以通过 SSH 连接到任何其他服务器)。

Still not the perfect world... would be good if I can can tunneling to my home network via HTTPS.仍然不是完美的世界……如果我可以通过 HTTPS 隧道连接到我的家庭网络,那就太好了。

Must work over port 443, without disturbing other HTTPS traffic (ie I can't just put the ssh server on port 443, because I would no longer be able to serve pages over HTTPS)必须在端口 443 上工作,而不会干扰其他 HTTPS 流量(即我不能将 ssh 服务器放在端口 443 上,因为我将不再能够通过 HTTPS 提供页面)

Is it possible to bind your HTTPS server to a different port?是否可以将您的 HTTPS 服务器绑定到不同的端口? Depending on what it's used for, you may even be able to get around the problem of not being able to directly access it from work by just SSHing home and then using lynx from there.根据它的用途,您甚至可以通过 SSH 回家然后从那里使用 lynx 来解决无法从工作中直接访问它的问题。

So, then, give proxifier a try (- it supports HTTP Proxy Server)!那么,试试代理器(它支持 HTTP 代理服务器)!

http://www.proxifier.com/documentation/intro.htm http://www.proxifier.com/documentation/intro.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM