iptables: 1개 규칙의 "최근" 모듈에 있는 설정과 검사를 결합합니다.

iptables: 1개 규칙의 "최근" 모듈에 있는 설정과 검사를 결합합니다.

사용recent모듈의 iptablessrc IP 주소가 목록에 있는지 확인하고, 있으면 다른 목록에 추가하려면 어떻게 해야 합니까?

구현하려고 하는데항구 노크iptables이 모듈( )과 함께 사용합니다 recent.

따라서 src IP 주소를 한 목록에서 다른 목록으로 이동하여 최종 목록으로 진행하여 TCP 패킷이 특정 순서로 도착하는지 감지하고 싶습니다. 그러면 src IP가 시스템에 액세스할 수 있습니다.

내 질문은 기본적으로 패킷에 올바른 대상 포트가 있고 올바른 현재 단계(목록)에 있을 때 다음 단계(목록)에 src ip를 추가하는 방법입니다. 이 같은:

1:

# we'd like to accept the already authenticated packets quickly, hence the first rule
iptables -A KNOCKING -m recent --rcheck --seconds 60 --reap --name knockfinal -j ACCEPT

2:

# src ip is not authenticated, let's verify the first knock
# if the first port knock was correct (port 1111), add the src ip to the 'knock1' list
iptables -A KNOCKING -p tcp --dport 1111 -m recent --name knock1 --set -j DROP

삼:

# now, here is the issue...
# how do we both check if the src ip is already in the 'knock1' list
# plus the second port knock was correct (port 2222), and add the src ip to 'knock2' list
# ideally, we would write something like this
iptables -A KNOCKING -m recent --rcheck --seconds 10 --reap --name knock1 -p tcp --dport 2222 -m recent --name knock2 --set -j DROP

나는 iptables를 사용하여 포트 노킹을 설정하는 여러 가지 접근 방식을 읽었지만 이것이 나에게는 가장 사소한 접근 방식인 것처럼 보이므로 이 접근 방식을 사용하여 수행할 수 있는지 확인하거나 거부하고 싶습니다.

답변1

결과적으로 제가 위에 게시한 줄은 정확히 작성되어야 하는 방식입니다. :) 저는 iptables그런 "복잡한" 규칙을 처리할 수 있을 것이라고 기대하는 것에 대해 너무 비관적이었던 것 같습니다.

쉬운 포트 노킹 구성에 대한 구성은 다음과 같습니다.

# set default policy for INPUT chain to DROP
iptables -P INPUT DROP

# accept all local traffic
iptables -A INPUT -i lo -j ACCEPT

# accept all the already-established connections
iptables -A INPUT -p tcp -m state --state RELATED,ESTABLISHED -m multiport --sports 25,80,443,465,587 -j ACCEPT

# add more of your own rules here...

# at the end, redirect all the packets into the KNOCKING chain
# this makes it easy to quickly enable/disable KNOCKING chain, if need be
iptables -A INPUT -j KNOCKING

# if the src ip is already authenticated, accept it
iptables -A KNOCKING -m recent --rcheck --seconds 60 --reap --name knockfinal -j ACCEPT

# if the packet is not authenticated and the first port knock is correct
# add the src ip into the 'knock1' list
iptables -A KNOCKING -p tcp -m tcp --dport 1111 -m recent --set --name knock1 -j DROP

# if the src ip is already in the 'knock1' list (with the expiry time of 10 seconds)
# and the 2nd port knock is correct, add the src ip to the 'knock2' list
iptables -A KNOCKING -p tcp -m recent --rcheck --seconds 10 --reap --name knock1 -m tcp --dport 2222 -m recent --set --name knock2 -j DROP

# if the src ip is already in the 'knock2' list (with the expiry time of 10 seconds)
# and the 3rd port knock is correct, add the src ip to the 'knock3' list
iptables -A KNOCKING -p tcp -m recent --rcheck --seconds 10 --reap --name knock2 -m tcp --dport 3333 -m recent --set --name knock3 -j DROP

# if the src ip is already in the 'knock3' list (with the expiry time of 10 seconds)
# and the 4th port knock is correct, add the src ip to the 'knockfinal' list
iptables -A KNOCKING -p tcp -m recent --rcheck --seconds 10 --reap --name knock3 -m tcp --dport 4444 -m recent --set --name knockfinal -j DROP

# otherwise, we don't do anything and the default INPUT policy will drop the packet

내 생각엔 이것이 지금까지 본 iptables에 대한 가장 짧은 포트 노킹 규칙 세트인 것 같습니다...

관련 정보