태그 보관물: iptables

iptables

iptables로 무차별 ssh를 차단하지 못함 내가 원하는만큼 시도하지 못하게하는 것처럼 보이지 않습니다.

내 sshd 서버에서 무차별 대입 공격을 차단 (느리게)하려고합니다. 나는이 안내서 http://www.rackaid.com/resources/how-to-block-ssh-brute-force-attacks/ 를 따르고 있으며 기본적으로 아래 두 명령 만 입력하면됩니다.

sudo iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --set
sudo iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent  --update --seconds 60 --hitcount 4 -j DROP

내 sshd 포트는 6622이므로 항목을 “22”에서 “6622”로 변경하고 해당 명령을 입력했습니다. 그런 다음 새 iptables를 간단히 테스트하려고했습니다. 다른 PC로 가서 의도적으로 잘못된 로그인 비밀번호를 여러 번 입력했습니다. 불행히도 새로운 규칙은 내가 원하는만큼 시도하지 못하게하는 것처럼 보이지 않습니다. 아래는 현재 규칙입니다. 내가 무엇을 잘못하고 있지?

# iptables --list

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
DROP       tcp  --  anywhere             anywhere             tcp dpt:6622 state NEW recent: UPDATE seconds: 60 hit_count: 4 name: DEFAULT side: source
           tcp  --  anywhere             anywhere             tcp dpt:6622 state NEW recent: SET name: DEFAULT side: source

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain LOGDROP (0 references)
target     prot opt source               destination
LOG        all  --  anywhere             anywhere             LOG level warning
DROP       all  --  anywhere             anywhere


답변

@banjer가 그의 의견에서 지적했듯이 실제 문제에 대한 잘못된 해결책을 찾고 있습니다.

당신이해야 할 일은 fail2ban을 설정하는 것 입니다. 백그라운드에서 iptables를 사용하여 다양한 소스에서 실패한 액세스 시도를 생성하는 호스트의 연결 시도를 자동으로 차단합니다. 그것은 매우 다재다능하며 다양한 트레스 홀드, 패턴을 찾고 차단하는 방법을 추가하고 수정할 수 있습니다. 사용중인 비표준 포트를 설명하기 위해 기본 ssh jail을 약간 조정해야하지만 어렵지는 않습니다.


답변

다음과 같은 규칙을 사용하여 작업 속도를 늦 춥니 다.

iptables -A DDoS -m limit --limit 12/s --limit-burst 24 -j RETURN
iptables -A DDoS -j LOG --log-prefix "[DDos Attack?] "
iptables -A DDoS -j DROP

다른 곳에서는 다음과 같이 제한합니다.

LOGLIMIT="50/h"
LOGLIMITBURST="10"
iptables -A IANA -p tcp -m limit --limit $LOGLIMIT --limit-burst \
     $LOGLIMITBURST -j DROP

답변

맨 페이지를 읽었습니까?

남자 sshd_config :

 MaxAuthTries
         Specifies the maximum number of authentication attempts
         permitted per connection.  Once the number of failures
         reaches half this value, additional failures are logged.
         The default is 6.
 MaxSessions
         Specifies the maximum number of open sessions permitted
         per network connection.  The default is 10.
 MaxStartups
         Specifies the maximum number of concurrent unauthenticated
         connections to the SSH daemon.  Additional connections
         will be dropped until authentication succeeds or
         the LoginGraceTime expires for a connection. The default is 10:30:100.

         Alternatively, random early drop can be enabled by specifying
         the three colon separated values “start:rate:full” (e.g.
         "10:30:60").  sshd(8) will refuse connection attempts with a
         probability of “rate/100” (30%) if there are currently “start”
         (10) unauthenticated connections.  The probability increases
         linearly and all connection attempts are refused if the
         number of unauthenticated connections reaches “full” (60).

답변

방금 두 가지 규칙 솔루션을 시도했지만 확인했을 때 동일한 문제가 발생했습니다. 그런 다음 게시 된 규칙에 -i eth0옵션 이 있습니다. 나는 그것을 좋은 네트워크 인터페이스로 바꾸었고 마침내 작동하기 시작했다.


답변

대부분의 자습서 -A는 규칙 세트 끝에 추가하는 데 사용 됩니다. OP -I는 색인없이 삽입 하는 데 사용 되었으므로 규칙의 순서가 잘못되었습니다.

iptables 규칙을 디버깅하는 데 유용한 도구는 iptables -vL각 규칙이 적용된 횟수를 계산하여 규칙을 나열하는 것입니다. 예기치 않은 0 카운트를 얻으면 무엇이 잘못되었는지 알 수 있습니다.


답변