Fail2ban이 계속해서 다시 차단을 시도하고 있습니다.

Fail2ban이 계속해서 다시 차단을 시도하고 있습니다.

내가 원하는 것을 수행하기 위해 Fail2ban을 얻는 데 문제가 있습니다. 저는 CLoudFlare에서 IP를 금지하는 작업을 사용합니다. 즉, Cloudflare 측에서 모든 것이 업데이트될 때까지 여전히 많은 요청이 처리됩니다(따라서 사용자는 더 이상 사이트에 액세스할 수 없습니다).

그런 일이 발생할 때까지, fall2ban은 IP를 계속해서 금지하려고 시도하여 수천 개의 요청(ddos의 경우)을 cloudflare에 보내게 되는데, 이는 오랜 시간이 걸리므로 작업이 완료될 때까지 다른 공격자를 금지하지 않습니다. 이전 (이미 금지된) 것들.

그렇다면 Fail2ban이 다시 금지하려는 시도를 막고 무시할 수 있는 방법이 있습니까?

#!/bin/bash

# Make sure that the ip-blacklist file exists
# otherwise we go ahead and create it
if [ ! -e "/etc/fail2ban/ip.blacklist" ] ; then
    touch "/etc/fail2ban/ip.blacklist"
fi

if [[ $1 = ban ]]; then
    if ! grep -q "$2" /etc/fail2ban/ip.blacklist; then
        # Store the IP as we need it later to check if the user is already banned
        echo "$2" >> /etc/fail2ban/ip.blacklist

        # Submit the ban request
    fi 
elif [[ $1 = unban ]]; then
    # Remove the IP from the blacklist 
    perl -ni -e "print unless (/^$2$/);" /etc/fail2ban/ip.blacklist
    #sed -i '/^$2$/d' /etc/fail2ban/ip.blacklist

    # Submit the unban request
fi

답변1

금지 요청을 보낼 때 금지된 IP 목록을 만들고 여기에 IP를 추가하는 것을 고려하세요. IP가 목록에 있으면 작업 스크립트에서 차단 요청을 무시합니다. 또한 금지된 IP 목록에서 IP를 제거하려면 금지 해제 조치를 변경해야 합니다. 다음과 같은 스크립트를 작성하십시오.

#!/bin/bash

# Define ourbanfile
banFile=ip.blacklist

# Ensure we have a banFile will be created if missing
if [ ! -e ${banFile} ]; then
    touch ${banFile}
fi

# Ban or unban as desired
if [[ $1 = ban ]]; then
    if ! grep -q "$2" ${banFile}; then
        # Store the IP as we need it later to check if the user is already banned
        echo "$2" >> ${banFile}

        # Submit the ban request
    fi
elif [[ $1 = unban ]]; then
    # Remove the IP from the blacklist
    perl -ni -e "print unless (/^$2\$/);" ${banFile}
    #sed -i '/^$2$/d' ${banFile}

    # Submit the unban request
fi

# Cat banfile if running on terminal (testing)
tty -s  && cat ${banFile}

# EOF

당신의 행동은 다음과 같습니다:

actionban = /path/to/script ban <IP>
actionunban = /path/to/script unban <IP>

관련 정보