I am working on writing a script that identifies login attempts that are 5 seconds or less apart, searching for brute force login attempts. So far I have been able to take the log timestamps and convert them to a readable and workable format, by using the script below:
#!/usr/bin/perl
use warnings;
use strict;
open my $IN, '<', 'test.txt' or die $!; # Open the file.
while (<$IN>) { # Process it line by line.
my $timestamp = (split)[1]; # Get the second column.
$timestamp =~ tr/://d; # Remove colons.
print "$timestamp\n";
}
The output I get looks like
102432
102434
104240
etc.
What I want to do is compare the numbers in the array to see if there is a five-second delay or less between login attempts. Something like:
if ($timestamp + 5 <= 2nd element in array) {
print "ahhh brute force"
}
The same thing all the way down the array elements until the end.
if (2nd element in array + 5 <= 3rd element in array) {
print "ahh brute force"
}
etc.
Could someone please point me in the right direction?
Example of input:
2014-08-10 13:20:30 GET Portal/jsjquery-latest.js 404 - "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
$timestampto$timestamp_oldand compare these two on each iteration?