HTTPプロキシサーバ経由のssh接続

提供: セキュリティ
2015年6月9日 (火) 00:44時点におけるDaemon (トーク | 投稿記録)による版

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索
スポンサーリンク

SSH over HTTP (HTTP Tunnelling) のやり方について説明します。HTTPプロキシサーバを経由して、Secure Shellでサーバにログインできます。ここで扱うのは、HTTPトンネリングです。

読み方

SSH over HTTP
すえすえいち おーばー えいてぃてぃぴー

概要

HTTPしか出ていけない環境で、ssh接続したいときに、どのように実現すれば良いのでしょうか?1つの方法は、sshHTTPトンネリングすることです。

ssh -> httpプロキシ -> サーバ

ここでの例では、OpenSSHを利用していますが、TeraTerm, PuTTYなどのsshクライアントもプロキシサーバの設定が可能です。

ここの例では、22番に接続していますが、sshdを443でアクセス可能にすることによって、自分が制御できないプロキシ経由でもアクセスが可能になります。

ここでは、HTTPトンネリングの例ですが、ICMPを利用したICMPトンネリングトンネリングすることもできます。sshを利用して、sshポートフォワーディングによるsshトンネリングもよく利用されます。コネクションの中継のためにncatなんかも利用されます。

何のために使うのか

トンネリング自体は、正常な状態であれば、必要はありません。

通信経路が限定されているため、しかたがなく、socatなどでソケットトンネリングをするようなケースがありますが、おそらく、ネットワーク構成に問題がありそうです。

そのほかのケースで、トンネリングが必要なのは、たいていの場合、攻撃者が攻撃を検知されにくくするため、だったり、通信の制限のある環境で通信を確立するために用いられます。

用意するもの

  • プロキシ
  • connect-proxy
  • ssh クライアント

インストール

Ubuntu

apt install squid3
apt install connect-proxy
apt install openssh-client

設定

squidの設定

squidの設定に以下の設定が必要です。 Ubuntuの場合は、/etc/squid3/squid.conf の設定ファイルを編集します。

acl SSL_ports port 22
acl Safe_ports port 22          # ssh

設定編集後に、squidを再起動して、設定を反映してください。

sshの設定

sshssh_configにも設定が必要です。~/.ssh/config を編集します。

Host example.com
        Hostname example.com
        ProxyCommand connect-proxy -H localhost:3128 %h %p

使い方

設定さえできれば、あとは、sshコマンドを実行するだけで、自動的にプロキシ経由で、sshの接続が確立できます。

ssh example.com

connect-proxy

コマンドラインオプション

connect-proxyコマンドのコマンドラインオプションは、以下の通りです。

usage: connect-proxy [-dnhst45] [-p local-port][-R resolve] [-w timeout] 
          [-H proxy-server[:port]] [-S [user@]socks-server[:port]] 
          [-T proxy-server[:port]]
          [-c telnet-proxy-command]
          host port

エラー

ssh が以下のようなエラーを起こす場合は、プロキシの設定に問題があります。

root@5ecf56dbad43:/root# ssh -v example.com
OpenSSH_6.6, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /root/.ssh/config
debug1: /root/.ssh/config line 1: Applying options for example.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Executing proxy command: exec connect-proxy -H localhost:3128 example.com 22
debug1: permanently_set_uid: 0/0
debug1: permanently_drop_suid: 0
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6p1 Ubuntu-2ubuntu1
FATAL: failed to begin relaying via HTTP.
ssh_exchange_identification: Connection closed by remote host

ssh が以下のようなエラーを起こす場合は、プロキシの設定に問題があります。

root@5ecf56dbad43:/root# connect -d -H localhost:3128 example.com 22
DEBUG: No direct address are specified.
DEBUG: relay_method = HTTP (3)
DEBUG: relay_host=localhost
DEBUG: relay_port=3128
DEBUG: relay_user=root
DEBUG: local_type=stdio
DEBUG: dest_host=example.com
DEBUG: dest_port=22
DEBUG: checking example.com is for direct?
DEBUG: example.com is for not direct.
DEBUG: resolving host by name: localhost
DEBUG: resolved: localhost (127.0.0.1)
DEBUG: connecting to 127.0.0.1:3128
DEBUG: begin_http_relay()
DEBUG: >>> "CONNECT example.com:22 HTTP/1.0\r\n"
DEBUG: >>> "\r\n"
DEBUG: <<< "HTTP/1.1 403 Forbidden\r\n"
DEBUG: http proxy is not allowed.
FATAL: failed to begin relaying via HTTP.

なお、squidのaccess.logには、 TCP_DENIED と、接続を拒否したことを表すエラーが出ています。

1433677529.178      0 127.0.0.1 TCP_DENIED/403 3407 CONNECT example.com:22 -
HIER_NONE/- text/html

SSLの接続先ポートとして 22 番が許されていない、安全なポートとして22 が設定されていない場合に、上記のエラーがでます。squidの設定でいえば、 SSL_ports と Safe_ports の設定です。 「squidの設定」(前述)の設定で示した設定が必要です。

acl SSL_ports port 22
acl Safe_ports port 22          # ssh

設定編集後に、squidを再起動して、設定を反映してください。

どうやって防ぐか

プロキシを提供している場合に、CONNECT 接続のセッションで、特に長いセッションが疑わしいのではないでしょうか。

関連項目




スポンサーリンク