WIP - Append brute force attack protection (#1506)

This commit is contained in:
Christophe Maudoux 2018-09-28 00:03:46 +02:00
parent a26d8cfe73
commit 1662f471bb
13 changed files with 54 additions and 1207 deletions

File diff suppressed because it is too large Load Diff

View File

@ -140,21 +140,21 @@ sub display {
); );
} }
# 1.4 Brute-Force attack detected # # 1.4 Brute-Force attack detected
elsif ( $req->{error} == PE_WAIT ) { # elsif ( $req->{error} == PE_WAIT ) {
$self->logger->debug('Display: waiting before retrying authentication'); # $self->logger->debug('Display: waiting before retrying authentication');
$self->logger->debug('Hidden values -> '. Dumper( $req->{portalHiddenFormValues})); # $self->logger->debug('Hidden values -> '. Dumper( $req->{portalHiddenFormValues}));
$skinfile = 'info'; # $skinfile = 'info';
%templateParams = ( # %templateParams = (
AUTH_ERROR => $self->error, # AUTH_ERROR => $self->error,
AUTH_ERROR_TYPE => $req->error_type, # AUTH_ERROR_TYPE => $req->error_type,
MSG => '<span trspan="' . "PE$req->{error}" . '">">' . "PE$req->{error}" . '</span>', # MSG => '<span trspan="' . "PE$req->{error}" . '">">' . "PE$req->{error}" . '</span>',
URL => $req->{urldc}, # URL => $req->{urldc},
HIDDEN_INPUTS => $self->buildHiddenForm($req), # HIDDEN_INPUTS => $self->buildHiddenForm($req),
ACTIVE_TIMER => $req->data->{activeTimer}, # ACTIVE_TIMER => $req->data->{activeTimer},
FORM_METHOD => $self->conf->{infoFormMethod}, # FORM_METHOD => $self->conf->{infoFormMethod},
); # );
} # }
# 1.4 OpenID menu page # 1.4 OpenID menu page
elsif ($req->{error} == PE_OPENID_EMPTY elsif ($req->{error} == PE_OPENID_EMPTY
@ -330,6 +330,7 @@ sub display {
# * Logout message # * Logout message
# * Bad URL error # * Bad URL error
elsif ($req->{error} == PE_LOGOUT_OK elsif ($req->{error} == PE_LOGOUT_OK
or $req->{error} == PE_WAIT
or $req->{error} == PE_BADURL ) or $req->{error} == PE_BADURL )
{ {
%templateParams = ( %templateParams = (

View File

@ -1,6 +1,5 @@
package Lemonldap::NG::Portal::Plugins::BruteForceProtection; package Lemonldap::NG::Portal::Plugins::BruteForceProtection;
use Data::Dumper;
use strict; use strict;
use Mouse; use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_WAIT); use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_WAIT);
@ -21,40 +20,41 @@ sub run {
my ( $self, $req ) = @_; my ( $self, $req ) = @_;
my $countFailed = 0; my $countFailed = 0;
my $lastFailedLoginEpoch = 0; my @lastFailedLoginEpoch = ();
# Last failed login epoch before this authentication -> Auth_N-1 # Auth_N-2 failed login epoch
if ( defined $req->sessionInfo->{_loginHistory}->{failedLogin} ) { if ( defined $req->sessionInfo->{_loginHistory}->{failedLogin} ) {
$countFailed = @{ $req->sessionInfo->{_loginHistory}->{failedLogin} }; $countFailed = @{ $req->sessionInfo->{_loginHistory}->{failedLogin} };
} }
if ( defined $req->sessionInfo->{_loginHistory}->{failedLogin}->[1] ){
$lastFailedLoginEpoch = $req->sessionInfo->{_loginHistory}->{failedLogin}->[1]->{_utime} $self->logger->debug( " Number of failedLogin = $countFailed" );
return PE_OK if ( $countFailed < 3 );
foreach ( 0 .. 2 ) {
if ( defined $req->sessionInfo->{_loginHistory}->{failedLogin}->[$_] )
{
push @lastFailedLoginEpoch,
$req->sessionInfo->{_loginHistory}->{failedLogin}->[$_]
->{_utime};
}
} }
# If Auth. N-1 older than 10 minutes -> another try allowed # If Auth_N-2 older than 5 minutes -> another try allowed
if ( ( time - $lastFailedLoginEpoch ) > 600 ) { return PE_OK
$lastFailedLoginEpoch = 0; if ( ( $lastFailedLoginEpoch[0] - $lastFailedLoginEpoch[2] ) > 300 );
}
# Delta between the two last failed logins -> Auth_N - Auth_N-1 # Delta between the two last failed logins -> Auth_N - Auth_N-1
my $delta = time - $lastFailedLoginEpoch; my $delta = time - $lastFailedLoginEpoch[1];
$self->logger->debug( " successLogin -> " . Dumper( $req->sessionInfo->{_loginHistory}->{successLogin} ) ); $self->logger->debug( " Local time = " . time );
$self->logger->debug( " failedLogin -> " . Dumper( $req->sessionInfo->{_loginHistory}->{failedLogin} ) ); $self->logger->debug(" Delta time - lastFailedLoginN-1 = $delta");
$self->logger->debug(" Number of failedLogin -> $countFailed");
$self->logger->debug(" Last failedLogin epoch -> $lastFailedLoginEpoch");
$self->logger->debug( " Local time = " . localtime );
$self->logger->debug(" Delta Auth_N - Auth_N-1 = $delta");
# If Delta between the two last failed logins < 10s and more than 2 failedLogins => waiting = failedLogins * 10s # Delta between the two last failed logins < 30s => wait
if ( $countFailed > 2 and ( $delta < 10 ) ) { return PE_OK unless ( $delta < 31 );
#sleep $countFailed * 10; # Account locked
shift @{ $req->sessionInfo->{_loginHistory}->{failedLogin} };
return PE_WAIT; return PE_WAIT;
}
return PE_OK;
} }
1; 1;

View File

@ -85,7 +85,7 @@
"PE83":"U2F verification failed. Retry or contact your administrator", "PE83":"U2F verification failed. Retry or contact your administrator",
"PE84":"You're not authorized to access to this host", "PE84":"You're not authorized to access to this host",
"PE85":" الموقع البعيد يطلب جلسة جديدة (ولم يتم تحميل برنامج ترقية الجلسة).\nسجل الخروج و أعد المحاولة", "PE85":" الموقع البعيد يطلب جلسة جديدة (ولم يتم تحميل برنامج ترقية الجلسة).\nسجل الخروج و أعد المحاولة",
"PE86":"You must wait before trying to authenticate again", "PE86":"Your account is locked. You must wait 30s before authenticate again",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.", "2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"قبول", "accept":"قبول",
"accessDenied":"ليس لديك إذن بالدخول لهذا التطبيق", "accessDenied":"ليس لديك إذن بالدخول لهذا التطبيق",

View File

@ -85,7 +85,7 @@
"PE83":"U2F-Überprüfung fehlgeschlagen. Versuchen Sie es erneut oder wenden Sie sich an Ihren Administrator", "PE83":"U2F-Überprüfung fehlgeschlagen. Versuchen Sie es erneut oder wenden Sie sich an Ihren Administrator",
"PE84":"Sie sind nicht berechtigt, auf diesen Host zuzugreifen", "PE84":"Sie sind nicht berechtigt, auf diesen Host zuzugreifen",
"PE85":"Die Gegenseite fragt nach einer neueren Sitzung (und das UpgradeSession-Plugin wurde nicht geladen). Abmelden und erneut versuchen", "PE85":"Die Gegenseite fragt nach einer neueren Sitzung (und das UpgradeSession-Plugin wurde nicht geladen). Abmelden und erneut versuchen",
"PE86":"You must wait before trying to authenticate again", "PE86":"Your account is locked. You must wait 30s before authenticate again",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.", "2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"Akzeptieren", "accept":"Akzeptieren",
"accessDenied":"Sie haben keine Zugriffsberechtigung für diese Anwendung", "accessDenied":"Sie haben keine Zugriffsberechtigung für diese Anwendung",

View File

@ -85,7 +85,7 @@
"PE83":"U2F verification failed. Retry or contact your administrator", "PE83":"U2F verification failed. Retry or contact your administrator",
"PE84":"You're not authorized to access to this host", "PE84":"You're not authorized to access to this host",
"PE85":"The remote site ask for a newer session (and UpgradeSession plugin isn't loaded). Logout and retry", "PE85":"The remote site ask for a newer session (and UpgradeSession plugin isn't loaded). Logout and retry",
"PE86":"You must wait before trying to authenticate again", "PE86":"Your account is locked. You must wait 30s before authenticate again",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.", "2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"Accept", "accept":"Accept",
"accessDenied":"You have no access authorization for this application", "accessDenied":"You have no access authorization for this application",

View File

@ -85,7 +85,7 @@
"PE83":"U2F verification failed. Retry or contact your administrator", "PE83":"U2F verification failed. Retry or contact your administrator",
"PE84":"You're not authorized to access to this host", "PE84":"You're not authorized to access to this host",
"PE85":"The remote site ask for a newer session (and UpgradeSession plugin isn't loaded). Logout and retry", "PE85":"The remote site ask for a newer session (and UpgradeSession plugin isn't loaded). Logout and retry",
"PE86":"You must wait before trying to authenticate again", "PE86":"Your account is locked. You must wait 30s before authenticate again",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.", "2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"Accept", "accept":"Accept",
"accessDenied":"You have no access authorization for this application", "accessDenied":"You have no access authorization for this application",

View File

@ -85,7 +85,7 @@
"PE83":"La vérification U2F a échoué. Réessayez ou contactez votre administrateur", "PE83":"La vérification U2F a échoué. Réessayez ou contactez votre administrateur",
"PE84":"Vous n'êtes pas autorisé à accéder à ce site", "PE84":"Vous n'êtes pas autorisé à accéder à ce site",
"PE85":"Le site souhaite une authentification plus récente (et le plugin UpgradeSession n'est pas chargé). Déconnectez-vous et réessayez", "PE85":"Le site souhaite une authentification plus récente (et le plugin UpgradeSession n'est pas chargé). Déconnectez-vous et réessayez",
"PE86":"Vous devez attendre avant de pouvoir vous ré-authentifier", "PE86":"Votre compte est verrouillé. Vous devez attendre 30s avant de vous ré-authentifier.",
"2fRegRequired":"Ce service requiert une authentification à deux facteurs. Enregistrez un équipement ici et retournez au portail.", "2fRegRequired":"Ce service requiert une authentification à deux facteurs. Enregistrez un équipement ici et retournez au portail.",
"accept":"Accepter", "accept":"Accepter",
"accessDenied":"Vous n'avez pas les droits d'accès à cette application", "accessDenied":"Vous n'avez pas les droits d'accès à cette application",

View File

@ -85,7 +85,7 @@
"PE83":"U2F verification failed. Retry or contact your administrator", "PE83":"U2F verification failed. Retry or contact your administrator",
"PE84":"Non sei autorizzato ad accedere a questo host", "PE84":"Non sei autorizzato ad accedere a questo host",
"PE85":"Il sito remoto richiede una sessione più recente (e il plug-in di UpgradeSession non viene caricato). Disconnetti e riprova", "PE85":"Il sito remoto richiede una sessione più recente (e il plug-in di UpgradeSession non viene caricato). Disconnetti e riprova",
"PE86":"You must wait before trying to authenticate again", "PE86":"Your account is locked. You must wait 30s before authenticate again",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.", "2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"Accetta", "accept":"Accetta",
"accessDenied":"Non hai un'autorizzazione di accesso per questa applicazione", "accessDenied":"Non hai un'autorizzazione di accesso per questa applicazione",

View File

@ -85,7 +85,7 @@
"PE83":"U2F verification failed. Retry or contact your administrator", "PE83":"U2F verification failed. Retry or contact your administrator",
"PE84":"You're not authorized to access to this host", "PE84":"You're not authorized to access to this host",
"PE85":"The remote site ask for a newer session (and UpgradeSession plugin isn't loaded). Logout and retry", "PE85":"The remote site ask for a newer session (and UpgradeSession plugin isn't loaded). Logout and retry",
"PE86":"You must wait before trying to authenticate again", "PE86":"Your account is locked. You must wait 30s before authenticate again",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.", "2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"Accept", "accept":"Accept",
"accessDenied":"You have no access authorization for this application", "accessDenied":"You have no access authorization for this application",

View File

@ -85,7 +85,7 @@
"PE83":"U2F verification failed. Retry or contact your administrator", "PE83":"U2F verification failed. Retry or contact your administrator",
"PE84":"You're not authorized to access to this host", "PE84":"You're not authorized to access to this host",
"PE85":"The remote site ask for a newer session (and UpgradeSession plugin isn't loaded). Logout and retry", "PE85":"The remote site ask for a newer session (and UpgradeSession plugin isn't loaded). Logout and retry",
"PE86":"You must wait before trying to authenticate again", "PE86":"Your account is locked. You must wait 30s before authenticate again",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.", "2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"Accept", "accept":"Accept",
"accessDenied":"You have no access authorization for this application", "accessDenied":"You have no access authorization for this application",

View File

@ -85,7 +85,7 @@
"PE83":"U2F verification failed. Retry or contact your administrator", "PE83":"U2F verification failed. Retry or contact your administrator",
"PE84":"You're not authorized to access to this host", "PE84":"You're not authorized to access to this host",
"PE85":"The remote site ask for a newer session (and UpgradeSession plugin isn't loaded). Logout and retry", "PE85":"The remote site ask for a newer session (and UpgradeSession plugin isn't loaded). Logout and retry",
"PE86":"You must wait before trying to authenticate again", "PE86":"Your account is locked. You must wait 30s before authenticate again",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.", "2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"Accept", "accept":"Accept",
"accessDenied":"You have no access authorization for this application", "accessDenied":"You have no access authorization for this application",

View File

@ -85,7 +85,7 @@
"PE83":"Xác minh U2F không thành công", "PE83":"Xác minh U2F không thành công",
"PE84":"Bạn không được phép truy cập vào máy chủ lưu trữ này", "PE84":"Bạn không được phép truy cập vào máy chủ lưu trữ này",
"PE85":"Trang web từ xa yêu cầu một phiên mới (và plugin UpgradeSession không được tải). Đăng xuất và thử lại ", "PE85":"Trang web từ xa yêu cầu một phiên mới (và plugin UpgradeSession không được tải). Đăng xuất và thử lại ",
"PE86":"You must wait before trying to authenticate again", "PE86":"Your account is locked. You must wait 30s before authenticate again",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.", "2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"Chấp nhận", "accept":"Chấp nhận",
"accessDenied":"Bạn không có quyền truy cập vào ứng dụng này", "accessDenied":"Bạn không có quyền truy cập vào ứng dụng này",