SOCKS 経由で SSH 経由で HTTP をトンネリングする方法は?

SOCKS 経由で SSH 経由で HTTP をトンネリングする方法は?

これは簡単に解決できる問題のはずですが、何らかの理由でうまくいきません。

ssh vps問題なく動作します(認証キーを使用します)

次のコマンドでトンネルを設定しました:

ssh -C2TNv -D 8080 vps

次に、Firefox のネットワーク設定を変更します。

  • 手動設定
    • http プロキシ: localhost、ポート: 8080
    • すべてのプロトコルにこのプロキシサーバーを使用する
    • ソックス v5
  • について:config
    • network.proxy.socks_remote_dns: 有効

端末出力:

$ 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 ヘッダーのみを取得し、より詳細な出力を取得するため)。

これらのフラグが選択され、curl が接続されている場合、出力文字列に次のようなものが表示されます。

* 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

関連情報