date-1.1.6



  • SOCKS4, SOCKS5 のフリーなサーバ・クライアント実装
  • http://www.inet.no/dante/
    手順

    1. % ./configure --prefix=/usr/local/socks
    2. % make
    3. # make install
    4. # cd /usr/local/bin
    5. # ln -s ../socks/bin/socksify
    6. # cd /usr/local/sbin
    7. # ln -s ../socks/sbin/sockd
      (ライブラリ /usr/local/socks/lib については気にしなくていい)
    8. 実行用のユーザ・グループ socksd と libwrap を作成
      --- /etc/passwd ---
      sockd:x:110:110:socksd privileged user(dante):/:
      sockd_root:x:111:3:socksd privileged root(dante):/:
      libwrap:x:112:112:libwrap user(dante):/:
      --- /etc/shadow ---
      sockd:NP:::::::
      sockd_root:NP:::::::
      libwrap:NP:::::::
      --- /etc/group ---
      sockd::110:
      libwrap::112:
      ---
      
    9. # cp example/sockd.conf /etc/sockd.conf.orig
    10. # cp example/socks.conf /etc/socks.conf.orig
    11. /etc/socksd.conf を /etc/socksd.conf.orig を参考にしながら作成
      ( SOCKS サーバとしての設定ファイル)
      #
      # dante --- SOCKS5 Free Implementation Software ---
      #
      # この設定ファイルは、以下の二部構成になっている。
      #
      # [サーバ設定部]
      #               logoutput        : ログ出力方法
      #               internal         : 内側の IP アドレスとポート
      #               external         : 外側の IP アドレス
      #               method           : 認証方法
      #               users            
      #               compatibility
      #               extension
      #               connecttimeout   : コネクションからリクエストまでの最大間隔
      #               iotimeout        : 
      #		srchost          : DNS 逆引き認証をするか?
      #
      # [ルール設定部]
      #     client block/pass  -- 許可・非許可クライアント --
      #		from to          : 接続元・行き先
      #		libwrap          : indent ラッパー
      #		log              : ログ出力内容
      #
      #     block/pass  -- 許可・非許可パケット --
      #		from to          : 接続元・行き先
      #		method           : 認証方法
      #		command          :
      #		libwrap          : indent ラッパー
      #		log              : ログ出力内容
      #		protocol         : 許可プロトコル (tcp,udp)
      #		proxyprotocol
      
      #
      #
      # ----- サーバ設定部 -----
      #
      #
      
      # [ログ出力先]
      # 		syslog, stderr, stdout, ファイル名から複数選択可
      logoutput: /var/log/socks.log stderr
      
      # [流入時インターフェース(IPアドレス), ポート]
      internal: ???.???.???.??? port = 1080
      
      # [流出時インターフェース(IPアドレス)] [カードが一つだけなら流入と同じにする]
      external: ???.???.???.???
      
      # [受付可能メソッドリスト順]
      #                 ここにないメソッドは選べない。rfc931 は ident のこと。
      #                 この最初に書いたものがデフォルト。
      method: none username rfc931
      
      # -- 重要な項目 --
      
      # [特権動作は誰で行う?] (ユーザ名)
      user.privileged: sockd_root
      
      # [通常動作は誰で行う?] (ユーザ名)
      user.notprivileged: sockd
      
      # [libwrap に対しては誰になる?] (ユーザ名)
      # (libwrap サポートでコンパイルされた場合のみ)
      user.libwrap: libwrap
      
      
      # -- 互換性のためのオプション --
      
      # when a client connection comes in the socksserver will try to use
      # the same port as the client is using, when the socksserver 
      # goes out on the clients behalf (external: ipaddress).
      # If this option is set, Dante will try to do it for reserved ports aswell.
      # This will usually require user.privileged to be set to "root".
      #compatibility: sameport
      
      # If you are using the bind extension and have trouble running servers
      # via the server, you might try setting this.  The consequences of it
      # are unknown.
      #compatibility: reuseaddr
      
      #
      # The Dante server supports some extensions to the socks protocol.
      # These require that the socks client implements the same extension and
      # can be enabled using the "extension" keyword.
      #
      # enable the bind extension.
      #extension: bind
      
      
      # -- その他のオプション --
      
      # コネクションからリクエストまでの間に許容する秒数
      # (none メソッドで LAN の場合は十分にとるべき)
      #connecttimeout: 30   # on a lan, this should be enough if method is "none".
      
      # how many seconds can the client and it's peer idle without sending
      # any data before we dump it?  Unless you disable tcp keep-alive for
      # some reason, it's probably best to set this to 0, which is
      # "forever".
      #iotimeout: 0 # or perhaps 86400, for a day.
      
      # DNS 逆引き不可能アドレスからのコネクションを受け入れない? (nounknown)
      # DNS 情報の不一致アドレスからのコネクションを受け入れない? (nomismatch)
      srchost: nounknown nomismatch
      
      
      
      #
      # ----- ルール設定部 -----
      # (レベルの違いによって、二つの部分に分かれている)
      #
      # client ではじまるルールが、
      # サーバに speak/connect を許すものかどうか最初に検査される。
      # セキュリティ面からホストネームではなく IP アドレスで特定することが重要だ。
      #
      # client 検査が行われた後、実際のリクエストが行われる。
      #
      # client 部での "to:" は接続可能なアドレスを与える.
      # socks サーバが listening するアドレスであり、
      # "0.0.0.0/0" だと、あらゆるアドレスにサーバは listening する。
      #
      # client 部ではない "to:" は、クライアントの到達先アドレスである。
      #
      # from は client 部かどうかに関わらず送信元アドレスである。
      #
      
      
      # -- クライアントルール --
      
      # [許可クライアント] ネットワーク単位で指定 (一台なら /32 )
      client pass {
      	from: ???.???.???.???/?? port 1-65535 to: 0.0.0.0/0
      #	method: rfc931 # ident の値が /etc/passwd にある人のみにする
      }
      client pass {
      	from: ???.???.???.???/32 port 1-65535 to: 0.0.0.0/0
      }
      
      # [非許可クライアント]
      #       許可クライアント以外の全て。ブロック時は connect error として記録。
      client block {
      	from: 0.0.0.0/0 to: 0.0.0.0/0
      	log: connect error
      }
      
      
      
      # -- パケットルール --
      
      # 普通はループバックへの接続は望まないだろう
      block {
      	from: 0.0.0.0/0 to: 127.0.0.0/8
      	log: connect error
      }
      
      # 相手側に悪い人がいる場合、誰にもそこと通信させない。libwrap での反応も記録。
      #block {
      #	from: 0.0.0.0/0 to: 172.16.0.0/12 
      #	libwrap: finger @%a
      #	log: connect error
      #}
      
      # bind リクエストは全てブロック (例えば FTP で行われる接続)
      block {
      	from: 0.0.0.0/0 to: 0.0.0.0/0
      	command: bind
      	log: connect error
      }
      
      # 特定のサイトからの bind は許可 (例えば FTP で特定の人には active 接続を許す)
      #pass {
      #	from: 10.0.0.0/8 to: 0.0.0.0/0
      #	command: bind
      #	log: connect error
      #}
      
      
      # some connections expect some sort of "reply", this might be
      # the reply to a bind request or it may be the reply to a
      # udppacket, since udp is packetbased.
      # Note that nothing is done to verify that it's a "genuine" reply,
      # that is in general not possible anyway.  The below will allow
      # all "replies" in to your clients at the 10.0.0.0/8 net.
      #pass {
      #	from: 0.0.0.0/0 to: 10.0.0.0/8
      #	command: bindreply udpreply
      #	log: connect error
      #}
      
      
      # [ドメインでの許可指定も可能] (後方一致可)
      #pass {
      #	from: 10.0.0.0/8 to: .example.com port = http
      #	log: connect error
      #	method: username
      #}
      
      # [ドメインでの非許可も可能] (後方一致可)
      #block {
      #	from: 0.0.0.0/0 to: .example.com port = http
      #	log: connect error
      #}
      
      # [プロトコル別 許可]
      # ここまでで非許可になってない ** 許可ホストからの ** パケットを許可
      pass {
      	from: ???.???.???.???/?? to: 0.0.0.0/0
      }
      pass {
      	from: ???.???.???.???/?? to: 0.0.0.0/0
      }
      
      # [全てのデフォルトは非許可]  (=ここまで引っ掛からなかったパケットは全て非許可)
      block {
      	from: 0.0.0.0/0 to: 0.0.0.0/0
      	log: connect error
      }
      
    12. /etc/socks.conf は、クライアントとして使う場合のファイルなので設定は特に不要.
      #
      # dante --- SOCKS5 Free Implementation Software ---
      # 
      # クライアント用設定ファイル
      #
      # この設定ファイルは二つの部分に分れている.
      # 最初に雑多な設定があり、次にルーティングに関する設定がある。
      # [] で囲まれたものはオプションである。
      #
      # 推奨順序:
      #	[debug]                 : デバッグ
      #	[logoutput]             : ログ出力
      #	[resolveprotocol]       : 名前解決方法
      #
      # 	routes: ルーティング設定
      #		from to via     : どこからどこへは、どこを通るか
      #		[command]       : コマンド指定
      #		[extension]     : 拡張
      #		[protocol]      : プロトコル指定
      #		[proxyprotocol] : 専用のプロキシープロトコルがある場合
      
      # [デバッグ] (1で行う)
      #debug: 1
      
      # [ログ出力] (ユーザは通常不要)
      #logoutput: stdout
      
      # [名前解決方法] (これを正しく設定するのは重要なことだ)
      #resolveprotocol: udp  # デフォルト
      #resolveprotocol: tcp  # socks4 しかサポートしてなければこちらをセット.
      #resolveprotocol: fake # socks サーバに名前解決をさせる
      
      #
      # ルーティング設定
      #
      
      # [ループバックには直接接続]
      route {
      	from: 0.0.0.0/0   to: 127.0.0.0/8  via: direct
      	command: connect udpassociate # bind 以外全て. bind を入れると混乱する
      }
      
      # [直接接続]
      route {
      	from: 0.0.0.0/0 to: 0.0.0.0/0 via: direct
      	command: bind
      }
      
      # [名前解決だけは直接つなげる時]
      #route {
      #	from: 0.0.0.0/0 to: 10.1.1.1/32 port = domain via: direct
      #}
      
      # [ローカルネットワークには直接接続]
      #route {
      #	from: 0.0.0.0/0   to: 10.0.0.0/8   via: direct
      #}
      
      # [プロキシサーバを通って外部に接続]
      #route {
      #	from: 0.0.0.0/0 to: 0.0.0.0/0 via: 10.1.1.1 port = 1080 
      #	command: bind
      #}
      
      # for poor souls trapped behind a msproxy server.
      #route {
      #	from: 0.0.0.0/0   to: 0.0.0.0/0   via: 10.1.1.1 port = 1745
      #	protocol: tcp			 # server supports tcp
      #	proxyprotocol: msproxy_v2        # server runs msproxy_v2
      #}
      
      # [細かく書いた場合]
      #route {
      #	from: 0.0.0.0/0   to: 0.0.0.0/0   via: 10.1.1.1 port = 1080
      #	protocol: tcp udp                # server supports tcp and udp.
      #	proxyprotocol: socks_v4 socks_v5 # server supports socks v4 and v5.
      #	method: none #username		 # we are willing to authenticate via
      #					 # method "none", not "username".
      #}
      
      # [ドメイン名で指定した場合]
      #route {
      #	from: 0.0.0.0/0   to: .   via: 10.1.1.1 port = 1080
      #	protocol: tcp udp                # server supports tcp and udp.
      #	proxyprotocol: socks_v4 socks_v5 # server supports socks v4 and v5.
      #	method: none #username		 # we are willing to authenticate via
      #					 # method "none", not "username".
      #}
      
      # [HTTP のプロキシーサーバを使う場合]
      
      #route {
      #	from: 0.0.0.0/0   to: 0.0.0.0/0   via: 10.1.1.1 port = 3128
      #	command: connect		 # only thing a httproxy supports. 
      #	proxyprotocol: http_v1.0
      #}
      
      #route {
      #	from: 0.0.0.0/0   to: .   via: 10.1.1.1 port = 3128
      #	command: connect		 # only thing a httproxy supports. 
      #	proxyprotocol: http_v1.0
      #}
      
    13. # cd /etc/rc2.d
    14. # ln -s ../init.d/socksd S99socksd
    15. # cd /etc/rc0.d
    16. # ln -s /etc/init.d/socksd K02socksd
    17. ログの更新スクリプトを設定
      # crontab -e で以下を追加 (毎週日曜日に更新)
      30 0 * * 0 /usr/local/sbin/newlog /var/log/socks.log; /etc/init.d/socksd restart
      
    18. SOCKSサーバの起動
      # /etc/init.d/socksd start

    クライアントについて

    1. SSH は --with-socks5 を追加して make し直せばよい

    クライアント使用法

    1. # /usr/local/bin/socksify [通常のコマンド]
    Windows SOCKS クライアント
    (SOCKScap から eBorder に名称が変更になっている)
    1. General 設定
      Settings: Use manual setup
      Does not require authentication を選択
      Enable proxy を選択
      
    2. Proxy 設定
      Name or address: idniks
      Port: 1080
      Direct connect for addreses ending with: 133.91.65. 133.91.64.
      (スペースで区切る)
      
    3. Applications 設定
      Proxy selection: Proxy all
      Exclude list... : IE, Winamp
      
    4. DNS 設定
      特に設定なし(Other domains: Try local,then remote)
      
    5. Diagnostics も特に設定なし
  • ← index へ