iptablesへのポート転送は動作しなくなりました。

iptablesへのポート転送は動作しなくなりました。

SSHハニーポットカウリーをインストールし、実際のSSHが別のポートを使用するように設定しました。ハニーポットはポートを使用する必要があります。N。 Iptablesはポート22間トラフィックをルーティングするように設定されています%PORT

iptables -t nat -A PREROUTING -p tcp --dport 22 -j REDIRECT --to-port %PORT

Cowrieはうまくいきます。次のように動作します。

ssh root@localhost -p %PORT

うまくいかないのは次のとおりです。

ssh root@localhost

リモート接続でも同様です(%PORTポートは開いていないため機能しません。

ssh: connect to host localhost port 22: Connection refused

実際のSSH自体はどこかの秘密ポートでうまく機能します。

iptablesのnatルールは次のとおりです。

Chain PREROUTING (policy ACCEPT)
num  target     prot opt source               destination
1    REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:ssh redir ports %PORT

Chain POSTROUTING (policy ACCEPT)
num  target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

以下はiptablesのグローバルルールです。

Chain INPUT (policy DROP)
num  target     prot opt source               destination
1    f2b-dovecot-pop3imap  tcp  --  anywhere             anywhere             multiport dports pop3,imap2
2    f2b-sshd   tcp  --  anywhere             anywhere             multiport dports ssh
3    ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
4    ACCEPT     all  --  anywhere             anywhere
5    ACCEPT     icmp --  anywhere             anywhere             icmp echo-request
[... removed some mappings not related to this toppics (http-specific, some mail-ports)]
15   ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:%REAL_SSH_PORT ctstate NEW,ESTABLISHED

Chain FORWARD (policy DROP)
num  target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

Chain f2b-dovecot-pop3imap (1 references)
num  target     prot opt source               destination
1    RETURN     all  --  anywhere             anywhere

Chain f2b-sshd (1 references)
num  target     prot opt source               destination
1    REJECT     all  --  XXXXXXX  anywhere             reject-with icmp-port-unreachable
2    REJECT     all  --  XXXXXXX  anywhere             reject-with icmp-port-unreachable
3    REJECT     all  --  XXXXXXX  anywhere             reject-with icmp-port-unreachable
4    REJECT     all  --  XXXXXXX       anywhere             reject-with icmp-port-unreachable
5    RETURN     all  --  anywhere             anywhere

いくつかの注意:

  1. 別のソースポート(99など)を選択しても機能しません。

  2. ローカルコンピュータから接続するときにこのようなローカルポート転送ルールを使用するとうまく機能します。

    iptables -t nat -A OUTPUT -p tcp --dport 22 -j REDIRECT --to-port %PORT
    

ここで私が見ていないものは何ですか?

ベストアンサー1

@wurtel ありがとうございます。実際に事前作業中です。いいえ港を開くことを意味する。また、次のようにSSH-honeypotsポートを開く必要がありました。

iptables -A INPUT -p tcp --dport %PORT -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT

おすすめ記事