From 0b1fe0462fe0e7837228129f6c1d89e64a5ab720 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Thu, 18 Feb 2016 10:40:20 +0100 Subject: [PATCH] Introduce message parser for SSH related notifications. This new messge parser is able to detect SSH related brute-force login attempts and to report the source IP-address (IPv4 and IPv6). Signed-off-by: Stefan Schantl --- modules/Parser.pm | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/modules/Parser.pm b/modules/Parser.pm index 9c3fc87..a73192d 100644 --- a/modules/Parser.pm +++ b/modules/Parser.pm @@ -10,6 +10,7 @@ our @EXPORT_OK = qw(IsSupportedParser Parser); # has to be called to parse messages in the right way. my %logfile_parsers = ( "snort" => \&message_parser_snort, + "ssh" => \&message_parser_ssh, ); # @@ -71,4 +72,55 @@ sub message_parser_snort($) { return "$message[0] SNORT A simple Snort Message"; } +# +## The SSH message parser. +# +## This subfunction is used for parsing and detecting different attacks +## against the SSH service. +# +sub message_parser_ssh (@) { + my @message = @_; + + # The name of the parser module. + my $name = "SSH"; + + # Variable to store the grabbed IP-address. + my $address; + + # Variable to store the parsed event. + my $message; + + # Loop through all lines, in case multiple one have + # been passed. + foreach my $line (@message) { + # Check for failed password attempts. + if ($line =~/.*sshd.*Failed password for (.*) from (.*) port.*/) { + # Store the grabbed IP-address. + $address = $2; + + # Set event message. + $message = "Possible SSH-Bruteforce Attack for user: $1."; + } + + # This should catch Bruteforce Attacks with enabled preauth + elsif ($line =~ /.*sshd.*Received disconnect from (.*):.*\[preauth\]/) { + # Store obtained IP-address. + $address = $1; + + # Set event message. + $message = "Possible SSH-Bruteforce Attack - failed preauth."; + } + } + + # Check if at least the IP-address information has been extracted. + if (defined ($address)) { + # Return the extracted values and event message. + return "$address $name $message"; + } + + # If we got here, the provided message is not affected by any filter and + # therefore can be skipped. Return nothing (False) in this case. + return; +} + 1; -- 2.39.2