VPSでiptablesを見る(Tor非終了リレーを実行)

VPSでiptablesを見る(Tor非終了リレーを実行)

私のiptablesルールを確認するのに役立つ人がいますか(新しいTor中継サーバーを実行する)?

私は完全に更新されたDebian GNU / Linux 11(bullseye)を実行しています。

基本的にINPUTチェーンのすべてを削除し、SSHポートは検閲されているので、見てわかるようにXXYYZ...ボットが22を押すよりも多くの操作を実行するようにカスタムポートに変更しました.

次に、このファイルをコピーして貼り付けますrules.v4

# Latest revision on 2021-Jul-25

*filter

:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]

--append INPUT --match conntrack --ctstate NEW --protocol tcp ! --syn --match comment --comment "protection: non-syn packets" --jump DROP
--append INPUT --match conntrack --ctstate INVALID --match comment --comment "protection: malformed packets" --jump DROP
--append INPUT --in-interface lo --match comment --comment "loopback: compulsory" --jump ACCEPT
--append INPUT --protocol icmp --icmp-type echo-request --match limit --limit 2/second --limit-burst 5 --match comment --comment "ICMP: ping only" --jump ACCEPT
--append INPUT --match conntrack --ctstate RELATED,ESTABLISHED --match comment --comment "Tor: traffic" --jump ACCEPT
--append INPUT --match conntrack --ctstate NEW,ESTABLISHED --protocol tcp --match tcp --destination-port XXYYZ --match comment --comment "SSH: global obfuscated" --jump ACCEPT
--append INPUT --protocol tcp --match tcp --destination-port 9001 --match comment --comment "Tor: OR" --jump ACCEPT
--append INPUT --protocol tcp --match tcp --destination-port 9030 --match comment --comment "Tor: Dir" --jump ACCEPT

COMMIT

約1日の稼働時間中の現在の出力は次のとおりです。

# iptables -L INPUT -v --line-numbers

Chain INPUT (policy DROP 29718 packets, 3008K bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1      234  131K DROP       tcp  --  any    any     anywhere             anywhere             ctstate NEW tcp flags:!FIN,SYN,RST,ACK/SYN /* protection: non-syn packets */
2      374 45284 DROP       all  --  any    any     anywhere             anywhere             ctstate INVALID /* protection: malformed packets */
3       96  4800 ACCEPT     all  --  lo     any     anywhere             anywhere             /* loopback: compulsory */
4       24   902 ACCEPT     icmp --  any    any     anywhere             anywhere             icmp echo-request limit: avg 2/sec burst 5 /* ICMP: ping only */
5    3736K 2726M ACCEPT     all  --  any    any     anywhere             anywhere             ctstate RELATED,ESTABLISHED /* Tor: traffic */
6       30  1800 ACCEPT     tcp  --  any    any     anywhere             anywhere             ctstate NEW,ESTABLISHED tcp dpt:XXYYZ /* SSH: global obfuscated */
7    12493  743K ACCEPT     tcp  --  any    any     anywhere             anywhere             tcp dpt:9001 /* Tor: OR */
8     7948  423K ACCEPT     tcp  --  any    any     anywhere             anywhere             tcp dpt:9030 /* Tor: Dir */

サーバーが正常に動作しているようですが、過度の自信、より良い言葉が足りないからです。

ベストアンサー1

あなたの情報のために:

*filter
-N RNNS
-A RNNS -p tcp ! --syn -j REJECT --reject-with tcp-reset
# accept (new) syn
-A RNNS -j ACCEPT

-N ALLOW
# tcp (r)eset (n)ew but (n)ot (s)yn
# -j RNNS is fine too since the chain has a "fallback" verdict at the end
-A ALLOW -p tcp --dport 9001 -g RNNS
-A ALLOW -p tcp --dport 9030 -g RNNS
-A ALLOW -p tcp --dport 12345 -g RNNS
# for (new) udp, just accept
-A ALLOW -p udp --dport 54321 -j ACCEPT
# others' fate will be determined by the chain policy of INPUT
# because we came to this chain by -g
# but well, -g ALLOW was the last rule anyway, so -j would have worked too
# and you can -j DROP here anyway

-P INPUT DROP
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -m conntrack --ctstate INVALID -j DROP
# -A INPUT -m conntrack --ctstate INVALID ! -p tcp -j DROP
# could only be of conntrack state NEW; oh well, also see UNTRACKED
-A INPUT -i lo -j ACCEPT
# -A INPUT -i lo -g RNNS
-A INPUT -p icmp --icmp-type echo-request -m limit --limit 2/second --limit-burst 5 -j ACCEPT
# chain policy; optimization / optional
-A INPUT -p icmp -j RETURN
# won't be ICMP
-A INPUT -g ALLOW

-P FORWARD DROP
-P OUTPUT ACCEPT
COMMIT

同じチェーン内では、ルールの順序は重要かもしれませんが、論理関係がないルール間の順序は確かにそうではありません(チェーンを参照ALLOW)。 「最適化」として、私たちはより「重要な一致」に優先順位を付けますが、「/ Mightはtrueです(チェーンの--ctstate最初の2つのルールを参照してくださいINPUT。)

おすすめ記事