Symfony 2.7을 기반으로하는 웹 페이지를 실행하고 있습니다. 이 페이지는 FOSUserBundle
사용자 관리 및 인증을 위해을 사용합니다.
로그 파일에서 페이지가 무차별 대입 스캐너에 의해 자주 "공격"되는 것을 볼 수 있습니다.
두 가지 유형의 스캔이 있습니다.
HTTP 404
응답 을 초래하는 알려진 취약점 (예 : WordPress 파일 등) 검색나는 전에 WordPress를 사용하고 있습니다. 이러한 공격을 자동으로 인식하고 처리하기위한 많은 플러그인과 도구가 있습니다. 404 요청 또는 거부 된 로그인 시도가 특정 임계 값에 도달하면 사용자 / IP가 일정 시간 동안 자동으로 차단됩니다. 일반적으로 몇 분 후 사용자 / ip는 차단 목록에서 자동으로 제거됩니다.
Symfony에 대한 그러한 솔루션을 찾을 수 없었습니다. 이러한 기능을 Symfony에 통합하는 번들이 있습니까?
물론이 기능을 직접 구현하는 것은 그리 어렵지 않습니다. 그러나 이미 존재하는 것을 재발 명하는 것은 의미가 없습니다.
악의적 인 IP를 차단하려면 fail2ban
. 이 블로그 는이를 완벽하게 설명합니다.
<?php
namespace Your\ExampleBundle\EventHandler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler;
class AuthenticationFailureHandler extends DefaultAuthenticationFailureHandler
{
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
if (null !== $this->logger && null !== $request->getClientIp()) {
$this->logger->error(sprintf('Authentication failure for IP: %s', $request->getClientIp()));
}
return parent::onAuthenticationFailure($request, $exception);
}
}
services:
your.examplebundle.authenticationfailurehandler:
class: Your\ExampleBundle\EventHandler\AuthenticationFailureHandler
arguments: ["@http_kernel", "@security.http_utils", {}, "@logger"]
tags:
- { name: 'monolog.logger', channel: 'security' }
# app/config/security.yml
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
failure_handler: your.examplebundle.authenticationfailurehandler
logout: true
anonymous: true
fail2ban에 대한 새 필터를 생성하기 위해 /etc/fail2ban/filter.d/symfony.conf에 다음 내용으로 파일을 생성합니다.
[Definition]
failregex = Authentication\sfailure\sfor\sIP:\s<HOST>\s
쉬웠 죠? 새로운 필터를 사용하는 /etc/fail2ban/jail.local에 감옥을 만들어야합니다. 이 감옥에 대한 정의는 구성에 따라 다르지만 기본 구성은 다음과 같습니다.
[symfony]
enabled = true
filter = symfony
logpath = /var/www/my-project/app/logs/prod.log
port = http,https
bantime = 600
banaction = iptables-multiport
maxretry = 3
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다