~~~~~

~~~~~

オープンを運営したいトルルーター。

私の退出方針は縮小終了ポリシー

しかし、私はまた、Tor ネットワークが私のリソースを悪用することを困難にしたいと考えています。

クライアントが Tor 経由で実行することを防止したいケース:

  • 非常に多くのパケットで 1 つのサイトを攻撃します。
  • IPブロック全体の積極的なネットスキャン

クライアントが Tor 経由で行うことを禁止したくないケース:

  • 数百の画像ファイルをクラウドにアップロードする
  • トレントのシード

私の質問は、これはそもそも実行可能なのか、そしてどのように実行可能なのかということです。

最初に考えたのはファイアウォール (Linux/iptables または *BSD/ipfw/pf) でしたが、Onion ルーターの固有の特性により、これはおそらく役に立たないでしょう。

このトピックに関して、torproject チームによる開発は進行中ですか?

また、Tor 出口ノードのセキュリティを確保するための一般的なヒントもお願いします。

更新 (2012 年 9 月)

役に立つ回答と他のいくつかの調査から、これはできないと思います。

出口ノードを悪用して DDOS に加担するのを阻止するためにできる最善のことは、1 つの IP に向けられた非常に頻繁なパケットを検出することです。

「非常に頻繁」のしきい値は、ノードの合計帯域幅によって異なります...これが間違っていると、誤検知が発生し、リアルタイム TCP アプリの正当なトラフィックと、非常に多くのクライアントから 1 つの宛先に送信されるトラフィックがブロックされます。

更新 (2014 年 12 月)

私の予測は明らかに正しかった。インターネット プロバイダーからネットワークの不正使用に関する苦情がいくつかあったのだ。

iptablesサービスのシャットダウンを回避するには、次の一連のルールを採用する必要がありました(ONEW送信 TCP SYN (別名 NEW) パケットのチェーンです)。

十分かどうかはわかりませんが、ここにあります:

-A ONEW -o lo -j ACCEPT
-A ONEW -p udp --dport 53 -m limit --limit 2/sec --limit-burst 5 -j ACCEPT
-A ONEW -m hashlimit --hashlimit-upto 1/second --hashlimit-mode dstip --hashlimit-dstmask 24 --hashlimit-name ONEW -j ACCEPT
-A ONEW -m limit --limit 1/sec -j LOG --log-prefix "REJECTED: "
-A ONEW -j REJECT --reject-with icmp-admin-prohibited

答え1

それを念頭に置いて:

  • 私の現在の理解では、Tor クライアントはおよそ 10 分ごとに仮想回線を切り替えます。つまり、ソース IP はその時間枠で変化します。その期間よりも長く、悪意があると思われる動作を防ぐことは不可能でしょう。

  • Tor が TCP トラフィックのみをプロキシし、他のプロトコルはプロキシしないという事実により、悪用される可能性がかなり制限されることに注意してください。

iptables既存のものと異なる方法で新しい発信 TCP 接続を扱うことができます。既存の TCP 接続チェーンを通過するESTABLISHED,RELATED必要があるものはすべてACCEPTED、そのチェーンに含まれ、そのチェーンに捕らわれない発信 TCP はレート制限される可能性があります。発信 Tor トラフィックはすべてこれに従う必要があります。

上記と「短縮終了ポリシー」の使用を組み合わせるのが、できる最善策だと思います。

理想的には、以下のもの以外は Tor ボックスで実行しないでください。

  • おそらく少なくとも SSH は稼働しているはずですので、22 以外のポートに設定してください。
  • おそらく、表示するためにシンプルなウェブサーバーを実行する必要があるでしょう。このページ. chroot されたmini-httpdインスタンスで十分です。 は使用しないでくださいinetd

他の用途に使用されているボックスでTorを実行しないでください。Tor の法的 FAQそしてその意味を十分に理解してください。またこれらすべてを読んで実行してください

答え2

送信元 IP が一定ではないため、これらの攻撃を防ぐのは通常よりも困難になります。ただし、私の知る限り、Tor のルートは数分おきにしか変更されません。

したがって、ソース IP の背後にネットワーク全体が存在すると想定する必要があるため、一部の標準の制限/フィルタリング ルールをより高いしきい値で展開することは可能です。

フィルタリングできる項目:

  • 不正な、または典型的なフィンガープリント/スキャン パケット (不正な TCP/IP フラグ、XMAS、ほとんどの ICMP タイプなど)
  • 進行中または新規接続に適合しない無効なパケット (-m 状態)
  • かなり高いしきい値から始まる新しい接続

ただし、このようなことは通常、受信トラフィックに対して行われることに注意してください。「顧客」がどのようなプロトコルを実行するかは不明であり、迷惑/不明瞭な方法で制限する可能性があります。

また、新しい (またはステートレスな) パケットのレート制限については、拒否された (明らかに攻撃でない限りドロップしない) パケットがランダム化される、より複雑なスキームを検討することもできます。この方法では、全体的なレートが現在制限に達している場合でも、一般ユーザーはリロードを試みて運が良ければ成功しますが、同時ポート スキャナーはレート制限を回避できません。

また、Tor メーリング リストでも質問してください。おそらく、このような考えを持つのはあなたが最初ではないでしょう。https://lists.torproject.org/cgi-bin/mailman/listinfo

答え3

まず、iptablesでこのすべてを解決することを提案するつもりはありません。理想的な出口Torノードは、いくつかのVPNトンネルを介してトラフィックをロードバランスし、ISPがパケットと実際の宛先に気付かないようにし、またはキャッシュプロキシを使用して、人気のある宛先への繰り返しの送信要求を維持します。静的コンテンツを最小限に抑える...これらのオプションを検討している間、ここにバンドエイド虐待苦情問題のため;

使用した情報源

http://www.ossramblings.com/using_iptables_rate_limiting_to_prevent_portscans

http://blog.nintechnet.com/how-to-block-w00tw00t-at-isc-sans-dfind-and-other-web-vulnerability-scanners/

2 つのソース リンクをルールに組み合わせて、ポート スキャンに Tor 出口ノードを使用しようとするボットを妨害できます。これらのルールにより nmap のハングタイムが発生するため、出口ノードを使用するハッカーの不満が大きくなる可能性があることに注意してください。

#!/bin/bash
## Network interface used by Tor exit daemon
_tor_iface="eth1"
## Ports that Tor exit daemon binds to, maybe comma or space sepperated.
_tor_ports="9050,9051"
## Time to ban connections out in secconds, default equates to 10 minutes, same as default Tor cercut.
_ban_time="600"
## How long to monitor conections in seconds, default equates to 10 minutes.
_outgoing_tcp_update_seconds="600"
## How many new connections can be placed to a server in aloted update time limits. May nead to increes this depending on exit node usage and remote servers usages.
_outgoing_tcp_hitcount="8"
## How long to monitor connections for in minuets, default is 15 minutes but could be lessoned.
_outgoing_tcp_burst_minute="15"
## Hom many connections to accept untill un-matched
_outgoing_tcp_burst_limit="1000"

iptables -N out_temp_ban -m comment --comment "Make custom chain for tracking ban time limits" || exit 1
iptables -A out_temp_ban -m recent --set --name temp_tcp_ban -p TCP -j DROP -m comment --comment "Ban any TCP packet coming to this chain" || exit 1

iptables -N out_vuln_scan -m comment --comment "Make custom chain for mitigating port scans originating from ${_tor_iface}" || exit 1
for _tor_port in ${_tor_ports//,/ }; do
    iptables -A out_vuln_scan -p TCP -o ${_tor_iface} --sport ${_tor_port} -m recent --name temp_tcp_ban --update --seconds ${_ban_time} -j DROP -m comment --comment "Update ban time if IP address is found in temp_tcp_ban list" || exit 1
    iptables -A out_vuln_scan -p TCP -o ${_tor_iface} --sport ${_tor_port} -m state --state NEW -m recent --set -m comment --comment "Monitor number of new conncetions to ${_server_iface}" || exit 1
    iptables -A out_vuln_scan -p TCP -o ${_tor_iface} --sport ${_tor_port} -m state --state NEW -m recent --update --seconds 30 --hitcout 10 -j out_temp_ban -m comment --comment "Ban address when to many new connections are attempted on ${_tor_iface}" || exit 1
done
iptables -A out_vuln_scan -j RETURN -m comment --comment "Return un-matched packets for further processing" || exit 1

## Add rules to accept/allow outbound packets
iptables -N tor_out -m comment --comment "Make custom chain for allowing Tor exit node services" || exit 1
for _tor_port in ${_tor_ports//,/ }; do
    iptables -A tor_out -p TCP -o ${_tor_iface} --sport ${_tor_port} -m state --state NEW -m recent --set --name limit_${_tor_port} -m comment --comment "Track out-going tcp connections from port ${_tor_port}" || exit 1
    iptables -A tor_out -p TCP -o ${_tor_iface} --sport ${_tor_port} -m state --state NEW -m recent --update --seconds ${_outgoing_tcp_update_seconds:-60} --hitcount ${_outgoing_tcp_hitcount:-8} --rttl --name limit_${_tor_port} -j LOG --log-prefix "TCP flooding port ${_tor_port}" -m comment --comment "Log atempts to flood port ${_tor_port} from your server" || exit 1
    iptables -A tor_out -p TCP -o ${_tor_iface} --sport ${_tor_port} -m state --state NEW -m recent --update --seconds ${_outgoing_tcp_update_seconds:-60} --hitcount ${_outgoing_tcp_hitcount:-8} --rttl --name limit_${_tor_port} -j DROP -m comment --comment "Drop attempts to flood port ${_tor_port} from your server" || exit 1
    iptables -A tor_out -p TCP -o ${_tor_iface} --sport ${_tor_port} -m limit --limit ${_outgoing_tcp_burst_minute:-15}/minute --limit-burst ${_outgoing_tcp_burst_limit:-1000} -j ACCEPT -m comment --comment "Accept with conditions new connections from port ${_tor_port} from your server" || exit 1
done
iptables -A tor_out -j RETURN -m comment ---comment "Reurn un-matched packets for further filtering or default polices to take effect." || exit 1
## Activate jumps from default output chain to new custom filtering chains
iptables -A OUTPUT -p TCP -o ${_tor_iface} -j out_vuln_scan -m comment --comment "Jump outbound packets through vulnerability scaning mitigation" || exit 1
iptables -A OUTPUT -p TCP -o ${_tor_iface} -j tor_out -m comment --comment "Jump outbound packets through conditional acceptance" || exit 1

上記を で実行すると、cammasbashを含む変数に対してマジックが実行されます。,

user@host~# bash iptables_limit_tor.sh

変数のリストをもう一度示します

_tor_iface="eth1"
_tor_ports="9050,9051"
_ban_time="600"
_outgoing_tcp_update_seconds="600"
_outgoing_tcp_hitcount="8"
_outgoing_tcp_burst_minute="15"
_outgoing_tcp_burst_limit="1000"

また、新しいアウトバウンド接続をフィルタリングして-m state NEW ! --syn面白い一部のボットが悪用可能なサーバーを見つけるために使用するビジネスチェーンの例を次に示します。上記の2つを前置して、このような不正なチャットをさらにフィルタリングできます。

iptables -N out_bad_packets -m comment --comment "Make new chain for filtering malformed packets" || exit 1
iptables -A out_bad_packets -p TCP --fragment -j out_temp_ban -m comment --comment "Drop all fragmented packets" || exit 1
iptables -A out_bad_packets -p TCP -m state --state INVALID -j out_temp_ban -m comment --comment "Drop all invalid packets" || exit 1
iptables -A out_bad_packets -p TCP ! --syn -m state --state NEW -j out_temp_ban -m comment --comment "Drop new non-syn packets" || exit 1
iptables -A out_bad_packets -p TCP --tcp-flags ALL NONE -j out_temp_ban -m comment --comment "Drop NULL scan" || exit 1
iptables -A out_bad_packets -p TCP --tcp-flags ALL ALL -j out_temp_ban -m comment --comment "Drop XMAS scan"|| exit 1
iptables -A out_bad_packets -p TCP --tcp-flags ALL FIN,URG,PSH -j out_temp_ban -m comment --comment "Drop stealth scan 1" || exit 1
iptables -A out_bad_packets -p TCP --tcp-flags ALL SYN,RST,ACK,FIN,URG -j out_temp_ban -m comment --comment "Drop pscan 1"|| exit 1
iptables -A out_bad_packets -p TCP --tcp-flags SYN,FIN SYN,FIN -j out_temp_ban -m comment --comment "Drop pscan 2" || exit 1
iptables -A out_bad_packets -p TCP --tcp-flags FIN,RST FIN,RST -j out_temp_ban -m comment --comment "Drop pscan 3" || exit 1
iptables -A out_bad_packets -p TCP --tcp-flags SYN,RST SYN,RST -j out_temp_ban -m comment --comment "Drop SYN-RST scan" || exit 1
iptables -A out_bad_packets -p TCP --tcp-flags ACK,URG URG -j out_temp_ban -m comment --comment "Drop URG scans" || exit 1
iptables -A out_bad_packets -p TCP --tcp-flags ALL SYN,FIN -j out_temp_ban -m comment --comment "Drop SYNFIN scan" || exit 1
iptables -A out_bad_packets -p TCP --tcp-flags ALL URG,PSH,FIN -j out_temp_ban -m comment --comment "Drop nmap Xmas scan" || exit 1
iptables -A out_bad_packets -p TCP --tcp-flags ALL FIN -j out_temp_ban -m comment --comment "Drop FIN scan" || exit 1
iptables -A out_bad_packets -p TCP --tcp-flags ALL URG,PSH,SYN,FIN -j out_temp_ban -m comment --comment "Drop nmap-id scan" || exit 1
iptables -A out_bad_packets -p TCP --tcp-flags RST RST -o ${_tor_iface} --sport ${_tor_port} -m limit --limit 2/second --limit-burst 3 -j out_temp_ban -m comment --comment "Mitigate Smurf attacks from excesive RST packets"
iptables -A out_bad_packets -p TCP --tcp-flags RST RST -o ${_tor_iface} --sport ${_tor_port} -m limit --limit 2/second --limit-burst 2 -j RETURN -m comment --comment "Ban Smurf attacks using excesive RST packets"
iptables -A out_bad_packets -j RETURN -m comment --comment "Return un-matched packets for further processing." || exit 1

ただし、上記のチェーンは非常に制限的であり、一致したパケットは、チェーンのルールで選択された秒数の間、IP が禁止されます (テスト用または変更される可能性があります-j out_temp_ban) -j DROP-j REJECTこの一連のルールは、クライアント側で不適切にコーディングされたアプリが新しい Tor サーカットを介して再接続するときに、誤検知を引き起こす可能性もあります。

~~~~~

トラフィックをさらにシェーピングするために検討すべきソフトウェア Linux をチェックしてくださいfirejail。ソースは Github と Source forge にあり、man ページは古いホームページ、WordPress のサブドメインにあります。DigitalOcean には PHP と Firejail を使用した Nginx のガイドがあり、少し変更するだけで、ネットワークをどこで抑制すべきかについてはるかに多くの洞察が得られます。他にも、KVM運用境界内に特定のサービスを維持するために使用できるツールがあります。システムに最適なものを見つけてください。

さらに別のオプションとしては、fail2ban気が狂ったシステム管理者があなたの IP に http または ssl 接続を試みたときに、-m state --state NEW終了通知ページを要求している接続を切断するルールが追加されるように実行することです。これを正常な禁止解除時間制限と組み合わせると、システム管理者がログ汚染についてぶつぶつ言っている間にリモート サーバーが休憩できるようになります ;-) ただし、これは現在の回答の範囲を超えており、終了通知ページの提供に使用しているソフトウェアに依存します。ヒント: nginx と apache はどちらも、URL が要求された場合、構成内の最初の vhost またはサーバー ブロックを提供します。apache または nginx 以外のものを使用している場合は、man ページを参照する必要がありますが、私の場合は、最初の vhost を別のファイルにログするように設定し、fail2ban でそのログの IP を一時的な禁止リストに追加するだけで済みました。これは、パブリック サーバー上のボットを禁止するのにも非常に有効です。ボットは通常 IP アドレスを使用し、ドメイン要求を提供しないと、サーバーがボット トラップ (この場合は終了通知) を表示することになるためです。

制限された Tor 出口ポリシー (これはうまく処理されているようです) を実行してから、トラフィックを VPN トンネルにプッシュするという方法をお勧めします。複数のトンネル間の負荷分散には追加のクレジット ポイントが加算されます。これにより、Tor ネットワーク トラフィックの中断が少なくなり、ISP が出口ノードを実行しているという事実に気付かなくなります...ただし、VPN トラフィックをスニッフィングしてクラッキングしていることを認めない限りは。これは、一時的な禁止やリモート ホストによる自己禁止を許可するルールを実行すると、ノードのクライアントのプライバシーが侵害される可能性があるためです。一方、トラフィックを VPN (またはいくつかの VPN) にプッシュすると、クライアントのプライバシーが保護され、ISP が攻撃に悩まされることがなくなります。リクエスト実行可能な政府によってネットワーク トラフィック ログが収集される可能性がありますwhois www.some.domain

~~~~

編集/更新

~~~~

私は自分の広範なメモを調べ、自分が使用しているパブリックサーバーの設定を取り出しました

ここにfail2banのjail.local節があります

[apache-ipscan]
enabled  = true
port = http,https
filter = apache-ipscan
logpath = /var/log/apache*/*error_ip*
action = iptables-repeater[name=ipscan]
maxretry = 1

そしてこれがフィルターapache-ipscan.confファイルです

[DEFAULT]
_apache_error_msg = \[[^]]*\] \[\S*:error\] \[pid \d+\] \[client <HOST>(:\d{1,5})?\]
[Definition]
failregex = \[client <HOST>\] client denied by server .*(?i)/.*
#^<HOST>.*GET*.*(?!)/.*
#   ^%(_apache_error_msg)s (AH0\d+: )?client denied by server configuration: (uri )?.*$
#            ^%(_apache_error_msg)s script '\S+' not found or unable to stat(, referer: \S+)?\s*$
ignoreregex = 
# DEV Notes: 
# the web server only responds to clients with a valid Host: 
# header. anyone who tries using IP only will get shunted into 
# the dummy-error.log and get a client-denied message
#
# the second regex catches folks with otherwise valid CGI paths but no good Host: header
#
# Author: Paul Heinlein

そしてこれがアクションiptables-repeater.confファイルです

# Fail2Ban configuration file
#
# Author: Phil Hagen <[email protected]>
# Author: Cyril Jaquier
# Modified by Yaroslav Halchenko for multiport banning and Lukas Camenzind for persistent banning
# Modified by S0AndS0 to combine features of previous Authors and Modders
#
[Definition]
# Option:  actionstart
# Notes.:  command executed once at the start of Fail2Ban.
# Values:  CMD
#
actionstart = iptables -N fail2ban-BADIPS-<name>
              iptables -A fail2ban-BADIPS-<name> -j RETURN
          iptables -I INPUT -j fail2ban-BADIPS-<name>
          ## Comment above line and uncomment bello line to use multiport and protocol in addition to named jails
          #iptables -I INPUT -p <protocol> -m multiport --dports <port> -j fail2ban-BADIPS-<name>
          # set up from the static file
          #cat /etc/fail2ban/ip.blocklist.<name> |grep -v ^\s*#|awk '{print $1}' | while read IP; do iptables -I fail2ban-BADIPS-<name> 1 -s $IP -j DROP; done
          cat /etc/fail2ban/ip.blocklist.<name> |grep -v ^\s*#|awk '{print $1}' | while read IP; do iptables -I fail2ban-BADIPS-<name> 1 -d $IP -j DROP; done
          ## Comment above line and uncomment bellow line to check if there are blacklist files to load before attempting to load them
          # if [ -f /etc/fail2ban/ip.blacklist.<name> ]; then cat /etc/fail2ban/ip.blacklist.<name> | grep -e <name>$ | cut -d "," -s -f 1 | while read IP; do iptables -I fail2ban-BADIPS-<name> 1 -s $IP -j DROP; done; fi
# Option:  actionstop
# Notes.:  command executed once at the end of Fail2Ban
# Values:  CMD
#
actionstop = iptables -D INPUT -p <protocol> -m multiport --dports <port> -j fail2ban-BADIPS-<name>
         iptables -F fail2ban-BADIPS-<name> 
         iptables -X fail2ban-BADIPS-<name>
# Option:  actioncheck
# Notes.:  command executed once before each actionban command
# Values:  CMD
#
#actioncheck = iptables -n -L INPUT | grep -q fail2ban-BADIPS-<name>
actioncheck = iptables -n -L OUTPUT | grep -q fail2ban-BADIPS-<name>
# Option:  actionban
# Notes.:  command executed when banning an IP. Take care that the
#          command is executed with Fail2Ban user rights.
# Tags:    <ip>  IP address
#          <failures>  number of failures
#          <time>  unix timestamp of the ban time
# Values:  CMD
#
#actionban = if ! iptables -C fail2ban-BADIPS-<name> -s <ip> -j DROP; then iptables -I fail2ban-BADIPS-<name> 1 -s <ip> -j DROP; fi
actionban = if ! iptables -C fail2ban-BADIPS-<name> -d <ip> -j DROP; then iptables -I fail2ban-BADIPS-<name> 1 -d <ip> -j DROP; fi
# Add offenders to local blacklist, if not already there
        if ! grep -Fxq '<ip>,<name>' /etc/fail2ban/ip.blocklist.<name>; then echo "<ip>,<name> # fail2ban/$( date '+%%Y-%%m-%%d %%T' ): auto-add for BadIP offender" >> /etc/fail2ban/ip.blocklist.<name>; fi
# Report offenders to badips.com
#        wget -q -O /dev/null www.badips.com/add/<name>/<ip>
# Option:  actionunban
# Notes.:  command executed when unbanning an IP. Take care that the
#          command is executed with Fail2Ban user rights.
# Tags:    <ip>  IP address
#          <failures>  number of failures
#          <time>  unix timestamp of the ban time
# Values:  CMD
#
#actionunban = iptables -D fail2ban-REPEAT-<name> -s <ip> -j DROP
actionunban = iptables -D fail2ban-REPEAT-<name> -d <ip> -j DROP
# Disabled clearing out entry from ip.blacklist (somehow happens after each stop of fail2ban)
#sed --in-place '/<ip>,<name>/d' /etc/fail2ban/ip.blacklist.<name>
[Init]
# Defaut name of the chain
# 
# Defaut name of the chain
name = BADIPS
# Option:  port
# Notes.:  specifies port to monitor
# Values:  [ NUM | STRING ]  Default:
# 
#port = ssh
# Option:  protocol
# Notes.:  internally used by config reader for interpolations.
# Values:  [ tcp | udp | icmp | all ] Default: tcp

OUTPUT上記のフィルターは開始/停止アクションをブロックするように編集されていますが、-p TCP -m state --state NEWログに記録された IP アドレスからの新しい送信接続のみが禁止されるように各行に構成を追加する必要があります。

最後に、ドメインを要求していないユーザーを特定のアクセスおよびエラー ログにルーティングする Apache vHost 構成を設定し、許可されたアクセスと拒否されたアクセスを常にエラーとなるように設定します。ループバックでさえ、エラーをポップせずにページを表示できないようにする必要があります。最後になりましたが、Apache のエラー ページを Tor からのデフォルトの終了通知に設定して、単調なメッセージの代わりにそれが提供されるように503404ます。または、fail2ban の iptables アクションに状態行を追加した場合は、終了通知で使用される同じログ ファイルを簡単にポイントできます。その結果、サーバーは、IP アドレスをチェックしたサーバーの IP に新しい接続を確立できなくなりますが、確立された関連する接続は引き続き許可されます。つまり、他のページを参照することはできますが、ユーザーがそれらのページを参照することはできません。

答え4

もっと良い解決策があります: Squid キャッシュサーバー。Squid キャッシュサーバーは、定義して設定したりacldenyそれぞれacceptに使用できますacl。Squid チームが、あなたの質問が見つかった wiki で一連のルールを定義しているのは非常に興味深いことです。そこには iptables,PFまたは、別のレイヤーで作業しているため、他の人があなたの仕事をすることができません。

関連情報