如何通过 SOCKS 在 SSH 上传输 HTTP 隧道?

如何通过 SOCKS 在 SSH 上传输 HTTP 隧道?

这应该是一个很容易解决的问题,但由于某种原因,它对我来说不起作用。

ssh vps工作正常(我使用身份验证密钥)

我使用以下命令设置隧道:

ssh -C2TNv -D 8080 vps

然后我修改 Firefox 网络设置:

  • 手动配置
    • http 代理:localhost,端口:8080
    • 对所有协议都使用该代理服务器
    • 袜子v5
  • 关于:配置
    • network.proxy.socks_remote_dns: true

终端输出:

$ ssh -C2TNv -D 8080 vps
OpenSSH_6.0p1, OpenSSL 1.0.1a 19 Apr 2012
debug1: Reading configuration data /home/ting/.ssh/config
debug1: /home/ting/.ssh/config line 47: Applying options for vps
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to vps.server.com [1.1.1.1] port 22.
debug1: Connection established.
debug1: identity file /home/ting/.ssh/id_rsa type 1
debug1: identity file /home/ting/.ssh/id_rsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.5p1 Debian-6+squeeze1
debug1: match: OpenSSH_5.5p1 Debian-6+squeeze1 pat OpenSSH_5*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.0
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 [email protected]
debug1: kex: client->server aes128-ctr hmac-md5 [email protected]
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA <removed>
debug1: Host 'vps.server.com' is known and matches the RSA host key.
debug1: Found key in /home/ting/.ssh/known_hosts:10
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/ting/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Enabling compression at level 6.
debug1: Authentication succeeded (publickey).
Authenticated to vps.server.com ([1.1.1.1]:22).
debug1: Local connections to LOCALHOST:8080 forwarded to remote address socks:0
debug1: Local forwarding listening on ::1 port 8080.
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on 127.0.0.1 port 8080.
debug1: channel 1: new [port listener]
debug1: Requesting [email protected]
debug1: Entering interactive session.

然后我尝试使用 Firefox 访问一个网站,SSH 输出:

debug1: Connection to port 8080 forwarding to socks port 0 requested.
debug1: channel 2: new [dynamic-tcpip]
debug1: channel 2: free: dynamic-tcpip, nchannels 3
debug1: Connection to port 8080 forwarding to socks port 0 requested.
debug1: channel 2: new [dynamic-tcpip]
debug1: channel 2: free: dynamic-tcpip, nchannels 3

尽管代理似乎正在工作,但使用 Firefox 访问任何网站都会返回错误“连接已重置”。

答案1

带有 -D 的 SSH 命令没有问题(因此 SOCKS 将建立隧道,只是通过 HTTP 连接到 SOCKS,您必须理清这一点)

我得到了很好的输出

curl --socks5 127.0.0.1:8080 http://blah

但我得到了和你一样的错误输出

 curl --proxy 127.0.0.1:8080 http://blah

因此,Firefox 就像 HTTP 代理一样进行连接

查看 Firefox 窗口

手动配置 是

你说你勾选了“为所有协议使用该代理服务器”,这完全是错误的举动!你想输入一个 SOCKS 代理,如果你这样做,SOCKS 框就会变为空/灰色,你只能输入 HTTP 代理。

所以不要勾选该项。

然后输入 socks 代理 ip。

并删除显示 127.0.0.1,localhost 没有代理的地方。如果它说没有代理,那是默认的。

答案2

要通过 curl 检查连接,您还可以使用标志-I -v(仅获取 HTTP 标头并获得更具说服力的输出)。

如果选择了这些标志并且卷曲连接 - 您将在输出字符串中看到类似以下内容:

* Rebuilt URL to: http://www.google.ru/
*   Trying ::1...
* 87
* 245
* 198
* 44
* Connected to localhost (::1) port 8080 (#0)

如果无法连接:

* Rebuilt URL to: http://www.google.ru/
*   Trying ::1...
* connect to ::1 port 8080 failed: Connection refused

在另一个具有 ssh 连接的终端选项卡中,你会看到类似这样的内容:

debug1: channel 2: new [dynamic-tcpip]
debug1: channel 2: free: direct-tcpip: listening port 9999 for 87.245.198.44 port 80, connect from ::1 port 55034 to ::1 port 8080, nchannels 3

相关内容