IP- fail2ban, 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' }
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
failure_handler: your.examplebundle.authenticationfailurehandler
logout: true
anonymous: true
fail2ban Symfony2
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