-
Notifications
You must be signed in to change notification settings - Fork 0
/
evtxcheck.pl
166 lines (144 loc) · 4.68 KB
/
evtxcheck.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#! c:\perl\bin\perl.exe
#-----------------------------------------------------------------------------
# evtxcheck.pl
# Perl script to makes some predefined checks on EVTX files
#
# usage: evtxcheck.pl <path to EVTX file>
#
# NOTE: Requires the use of Microsoft LogParser (in PATH)
#
# copyright 2012 F.Picasso, [email protected]
#-----------------------------------------------------------------------------
use strict;
#-----------------------------------------------------------------------------
my $VERSION = "20120331";
print "EVenTX CHECKer version $VERSION\n";
print "using Microsoft LogParser, makes basic checks on EVTX files\n";
print "copyright 2012 Francesco Picasso\n";
my $infile = shift || die "You must enter a filename.\n";
die "$infile not found.\n" unless (-e $infile);
#-----------------------------------------------------------------------------
my $data;
my @lines;
my $line;
# RECORDS
my $firstRecord = undef;
my $lastRecord = undef;
my $prevRecord = 0;
my $recordWarnN = 0;
my @recordW = [];
# TIME
my $prevTime = 0;
my $timeWarnN = 0;
my @timeW = [];
my $TIMEDELTA = 60; # 1 minute;
# EVENT
my $prevEvt = 0;
my $prevprevEvt = 0;
# COMPUTERNAME
my $compNameNum = 0;
my $compName = '';
my @compNames = [];
my @compNameW = [];
my $recordCount = 0;
my $PIPE = "|";
my $BASE_CMD = "LogParser -i:evt -o:CSV ";
my $SELECT_MAIN = "\"SELECT RecordNumber,TO_UTCTIME(TimeGenerated),TO_INT(TO_UTCTIME(TimeGenerated)),";
$SELECT_MAIN .= "EventID,ComputerName FROM \"$infile\" ORDER BY RecordNumber\"";
#-----------------------------------------------------------------------------
$data = fystem( $BASE_CMD.$SELECT_MAIN.$PIPE );
@lines = map { "$_\n" } split /\n/, $data;
shift(@lines);
foreach $line (@lines) {
local $/ = "\r\n";
chomp( $line );
my @fields = split( /,/, $line );
last unless ( @fields == 5 );
$recordCount++;
my ($record,$timegen,$timenum,$evtid,$compname ) = @fields;
if ( not defined $firstRecord ) {
$firstRecord = $record;
$prevRecord = $record;
}
else {
if ( $record != $prevRecord + 1 ) {
# avoid false positive when SuppressDuplicate is in action
if ( $evtid != 4625 ) {
$recordW[ $recordWarnN++ ] = sprintf( "Missing [%u] records before ".
"RecordNumber: %s, Event: %s, Time: %s",
( $record - $prevRecord - 1 ), $record, $evtid, $timegen );
}
}
$prevRecord = $record;
$lastRecord = $record;
}
if ( ( $timenum + $TIMEDELTA ) < $prevTime ) {
# avoid false positive when SuppressDuplicate is in action
if ( $prevEvt != 4625 and $prevprevEvt != 4625 ) {
$timeW[ $timeWarnN++ ] = sprintf( "Back in time at ".
"RecordNumber: %s, Event: %s, Time: %s", $record, $evtid, $timegen );
}
}
$prevTime = $timenum;
$compname = lc( $compname );
if ( $compname ne $compName ) {
$compName = $compname;
$compNames[ $compNameNum ] = $compName;
$compNameW[ $compNameNum ] = sprintf( "Set to '$compName' at ".
"RecordNumber: %s, Event: %s, Time: %s", $record, $evtid, $timegen );
$compNameNum++;
}
# Event, last two records memory
$prevprevEvt = $prevEvt;
$prevEvt = $evtid;
}
print "\nTotal Records in '$infile': $recordCount\n";
print "\n";
print "----- Missing Records Detection -----\n\n";
print "First Record Number: $firstRecord\n";
print "Last Record Number: $lastRecord\n";
if ( $recordWarnN > 0 ) {
print "\nDETECTED $recordWarnN anomalies\n";
foreach my $a (@recordW) {
print "- $a\n";
}
}
else {
print "\nno missing records detected\n";
}
print "\n";
print "----- Back in Time Detection (Tolerance: $TIMEDELTA secs) -----\n\n";
if ( $timeWarnN > 0 ) {
print "\nDETECTED $timeWarnN anomalies\n";
foreach my $a (@timeW) {
print "- $a\n";
}
}
else {
print "no back time jumps detected\n";
}
print "\n----- ComputerName(s) -----\n\n";
print "ComputerNames(s) used: $compNameNum\n";
foreach my $a (@compNames) {
print "$a\n";
}
if ( $compNameNum > 1 ) {
print "\nDETECTED ".($compNameNum - 1)." changes\n";
foreach my $a (@compNameW) {
print "- $a\n";
}
}
print "\n----------------------------------\n\n";
#-----------------------------------------------------------------------------
sub fystem
{
my $cmd = shift;
my $data = '';
open(ICAT, $cmd) or die "can't fork: $!";
binmode(ICAT);
while(<ICAT>) { $data .= $_; }
close ICAT or die "error executing command '$cmd': [$!] [$?]";
return $data;
}
#-----------------------------------------------------------------------------
1;