3

我正在尝试通过 HTTP 代理建立 ssh 隧道。

在使用 squid localhost 代理测试设置时,我从(我猜)Apache 远程代理收到“不允许的方法”:

$ proxytunnel -v -p localhost:3128 -r torno.example.com:80 -d ssh.example.com:22 -H "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\nHost: ssh.example.com\nContent-Length: 0\nPragma: no-cache"
Local proxy localhost resolves to 127.0.0.1
Connected to localhost:3128 (local proxy)

Tunneling to torno.example.com:80 (remote proxy)
Communication with local proxy:
 -> CONNECT torno.example.com:80 HTTP/1.0
 -> Proxy-Connection: Keep-Alive
 -> User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\nHost: ssh.example.com\nContent-Length: 0\nPragma: no-cache
 <- HTTP/1.0 200 Connection established

Tunneling to ssh.example.com:22 (destination)
Communication with remote proxy:
 -> CONNECT ssh.example.com:22 HTTP/1.0
 -> Proxy-Connection: Keep-Alive
 -> User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\nHost: ssh.example.com\nContent-Length: 0\nPragma: no-cache
 <- HTTP/1.1 405 Method Not Allowed
HTTP return code: 405 Method Not Allowed
 <- Date: Thu, 25 Aug 2011 17:17:07 GMT
 <- Server: Apache/2.2.15 (CentOS)
 <- Allow: GET,HEAD,POST,OPTIONS,TRACE
 <- Content-Length: 352
 <- Connection: close
 <- Content-Type: text/html; charset=iso-8859-1

这是我的 Apache 虚拟主机配置:

<VirtualHost *:80>

     ServerAdmin admin@example.com
     ServerName torno.example.com
     ServerSignature Off

     HostnameLookups Off
     LogLevel Warn
     ErrorLog logs/torno.example.com-error_log
     CustomLog logs/torno.example.com-access_log combined

     ProxyRequests On
     AllowConnect 22

     <Proxy *>
         Order deny,allow
         Deny from all
     </Proxy>
     <Proxy ssh.example.com>
         Order deny,allow
         Allow from all
     </Proxy>

     ProxyPass / http://www.ibm.com/
     ProxyPassReverse / http://www.ibm.com/
     <Proxy http://www.ibm.com/>
         Order deny,allow
         Allow from all
     </Proxy>

</VirtualHost>

有任何想法吗?如何读取 405 响应的正文以确保它来自远程 Apache 代理而不是本地 squid 代理?

编辑:

请求位于默认服务器日志中:

189.99.135.105 - - [25/Aug/2011:17:17:07 +0000] "CONNECT ssh.example.com:22 HTTP/1.0" 405 352 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\\nHost: ssh.example.com\\nContent-Length: 0\\nPragma: no-cache"

新编辑:

使代理虚拟服务器成为默认服务器使其工作!!!:

$ proxytunnel -v -p localhost:3128 -r torno.example.com:80 -d ssh.example.com:22 -H "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\nHost: ssh.example.com\nContent-Length: 0\nPragma: no-cache"
Local proxy localhost resolves to 127.0.0.1
Connected to localhost:3128 (local proxy)

Tunneling to torno.example.com:80 (remote proxy)
Communication with local proxy:
 -> CONNECT torno.example.com:80 HTTP/1.0
 -> Proxy-Connection: Keep-Alive
 -> User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\nHost: ssh.example.com\nContent-Length: 0\nPragma: no-cache
 <- HTTP/1.0 200 Connection established

Tunneling to ssh.example.com:22 (destination)
Communication with remote proxy:
 -> CONNECT ssh.example.com:22 HTTP/1.0
 -> Proxy-Connection: Keep-Alive
 -> User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)\nHost: ssh.example.com\nContent-Length: 0\nPragma: no-cache
 <- HTTP/1.0 200 Connection Established
 <- Proxy-agent: Apache/2.2.15 (CentOS)

Tunnel established.
SSH-2.0-OpenSSH_5.3

这里发生了什么?一些代理隧道错误?

编辑:

这不是代理隧道的错。远程登录连接时也会发生同样的情况:

$ telnet torno.example.com 80
Trying 1.2.3.4...
Connected to torno.example.com.
Escape character is '^]'.
CONNECT ssh.example.com:22 HTTP/1.1
Host: ssh.example.com

HTTP/1.1 405 Method Not Allowed
Date: Fri, 26 Aug 2011 12:34:24 GMT
Server: Apache/2.2.15 (CentOS)
Allow: GET,HEAD,POST,OPTIONS,TRACE
Content-Length: 352
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method CONNECT is not allowed for the URL /.</p>
<hr>
<address>Apache/2.2.15 (CentOS) Server at <a href="mailto:admin@cz.example.com">ssh.example.com</a> Port 22</address>
</body></html>
Connection closed by foreign host.

现在将配置文件移动到 aaa.torno.example.com.conf 以使其成为默认值并且它可以工作:

$ telnet torno.example.com 80
Trying 1.2.3.4...
Connected to torno.example.com.
Escape character is '^]'.
CONNECT ssh.example.com:22 HTTP/1.1
Host: ssh.example.com

HTTP/1.0 200 Connection Established
Proxy-agent: Apache/2.2.15 (CentOS)

SSH-2.0-OpenSSH_5.3
4

2 回答 2

1

您在 405 响应中看到“Server: Apache/2.2.15 (CentOS)”标头,因此如果您使用 Squid,则响应必须来自服务器。

附带说明一下,我会将这个问题提交给 ServerFault 而不是这里。

于 2011-08-25T18:10:24.453 回答
0

方法不允许,因为 proxytunnel 在二进制版本中不支持 HTTP/1.1。

您可以将部分移出 VirtualHost。

于 2017-01-08T07:05:42.770 回答