fail2ban의 ban 알림을 Line Notify를 사용하여 LINE 그룹에 알립니다.

4444 단어 fail2banLineNotify
Line Notify 라는 LINE 서비스를 사용하면 명령 기반으로 모든 그룹에 메시지를 보낼 수 있습니다.
그래서, 무단 액세스 등을 검지한 fail2ban 가, 특정의 IP 주소를 ban 했을 때에, LINE 그룹에 통지하려고 해 보았습니다.

이러한 느낌으로, 스탬프의 송신도 가능합니다.


버전



CentOS 7.3
fail2ban 0.9.6

LINE측 준비



Line Notify 는 브라우저에서 조작합니다. 또한 알림용 LINE 그룹을 만들기 때문에 스마트폰과 브라우저 모두에서 작업이 필요합니다.

LINE 앱에 알림용 그룹 만들기



  • Line Notify을 브라우저에서 열고 LINE 계정으로 로그인합니다.
  • 자신의 LINE 앱 토크에 LINE Notify에서 알림이 오는지 확인하십시오.
  • fail2ban 알림을 위한 그룹을 자신의 LINE 앱에 생성합니다. 이번에는 fail2ban이라는 그룹 이름으로 만들었습니다.
  • 만든 그룹의 구성원에게 LINE Notify를 추가합니다. 이제 LINE 앱 측 준비가 완료되었습니다.

  • Line Notify 알림용 토큰 생성


  • 그런 다음 브라우저의 Line Notify 내 페이지로 이동합니다.
  • Generate token을 클릭합니다.
  • 토큰 설정 화면이 나오므로 토큰 이름과 미리 만든 fail2ban 그룹을 선택합니다. 이번에는 토큰 이름은 TEST입니다. Ganarate token을 클릭합니다.
  • 토큰이 화면에 나오므로 복사해 둡니다.

  • fail2ban 설정



    fail2ban에는 LINE 통지에 대한 액션이 없으므로 새로 작성합니다. 작성한 action을 jail의 정의에 포함합니다.

    액션 만들기


    /etc/fail2ban/action.d 아래에 LINE 통지용의 action 파일을 새롭게 작성합니다. 이번에는 send-line.conf라는 파일로하고 있습니다.
    vi /etc/fail2ban/action.d/send-line.conf 
    

    설정 내용은 이것뿐입니다.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx는 Line Notify에서 얻은 토큰입니다. 교체하십시오.

    /etc/fail2ban/action.d/send-line.conf
    [Definition]
    
    actionban = curl -X POST -H 'Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' -F 'message=[Fail2Ban] <name>: banned <ip>' -F 'stickerPackageId=1' -F 'stickerId=14' https://notify-api.line.me/api/notify
    
    [Init]
    name = default
    
  • message : 문자 메시지
  • stickerPackageId : 스탬프 그룹 ID
  • stickerId : 스탬프 ID

  • 스탬프 그룹 ID 및 스탬프 ID 목록은 다음 URL에서 공개됩니다.
    라인 스탬프 목록 : ttps://devdocs.line.me/files/sticker_list.pdf

    텍스트 통지만으로 좋다면 stickerPackageIdstickerId 를 적절히 제외해 주세요.

    jail 설정



    이번에는 sshd의 jail 설정에 방금 만든 LINE 알림 설정을 포함해 보았습니다.
    vi /etc/fail2ban/jail.d/02-enable-jail.conf
    

    sshd 섹션의 actionsend-line[name=sshd]를 추가합니다.

    /etc/fail2ban/jail.d/02-enable-jail.conf
    [sshd]
    enabled = true
    action  = firewallcmd-multiport[name=sshd, port="ssh", protocol=tcp, blocktype=DROP]
              sendmail-whois-ipjailmatches[name=sshd, [email protected], [email protected]]
              send-line[name=sshd]
    

    이것으로 준비가 완료됩니다.

    확인



    sshd의 jail을 다시로드 해보십시오.
    # fail2ban-client reload sshd
    

    잘하면 ban 알림이 LINE에 올 것입니다.


    참고



    LINE Engineers 'Blog : ぇぇぺぺrs. 네코 rp. 이 m/bぉg/그럼/? p=3819

    좋은 웹페이지 즐겨찾기