iptables에 대한 포트 전달이 더 이상 작동하지 않습니다.

iptables에 대한 포트 전달이 더 이상 작동하지 않습니다.

SSH 허니팟 cowrie를 설치하고 실제 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

관련 정보