line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Win32::FirewallParser - Microsoft Windows XP SP2 Firewall Log Parser |
2
|
|
|
|
|
|
|
# Copyright (C) 2005-2009 Luke Triantafyllidis |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This library is free software; you can redistribute it and/or modify it |
5
|
|
|
|
|
|
|
# under the same terms as Perl itself. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Win32::FirewallParser; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
29076
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
10
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
11
|
1
|
|
|
1
|
|
5
|
use constant HANDLERS => 0; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
690
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
1
|
|
|
1
|
1
|
785
|
my $class = shift; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
5
|
bless [ [] ], $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub setHandler { |
22
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $handler ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
0
|
die "CODE handler not specified\n" unless ref $handler eq 'CODE'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# setHandler overrides any previous callback functions |
27
|
0
|
|
|
|
|
0
|
$self->[HANDLERS] = [$handler]; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub addHandler { |
31
|
2
|
|
|
2
|
1
|
395
|
my ( $self, $handler ) = @_; |
32
|
|
|
|
|
|
|
|
33
|
2
|
50
|
|
|
|
8
|
die "CODE handler not specified\n" unless ref $handler eq 'CODE'; |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
3
|
push @{ $self->[HANDLERS] }, $handler; |
|
2
|
|
|
|
|
10
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub removeHandler { |
39
|
1
|
|
|
1
|
1
|
365
|
my ( $self, $coderef ) = @_; |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
2
|
map { splice @{ $self->[HANDLERS] }, $_, 1 } |
|
1
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
6
|
|
42
|
1
|
|
|
|
|
4
|
grep { $self->[HANDLERS]->[$_] == $coderef } |
43
|
1
|
|
|
|
|
3
|
0 .. $#{ $self->[HANDLERS] }; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub parseFile { |
47
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
48
|
0
|
|
0
|
|
|
|
my $file = shift || $ENV{'SystemRoot'} . '/pfirewall.log'; |
49
|
0
|
|
|
|
|
|
my $data = {}; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
open my $fh, '<', $file or die "unable to open $file: $!\n"; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
while (<$fh>) { |
54
|
0
|
|
|
|
|
|
chomp; |
55
|
0
|
0
|
|
|
|
|
next if /^(#|$)/; # ignore comments and blank lines |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my ($date, $time, $action, $proto, $from_addr, |
58
|
|
|
|
|
|
|
$to_addr, $from_port, $to_port, $size, $tcp_flags, |
59
|
|
|
|
|
|
|
$tcp_syn, $tcp_ack, $tcp_win, $icmp_type, $icmp_code, |
60
|
|
|
|
|
|
|
$info, $path |
61
|
|
|
|
|
|
|
) = split / /; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$data->{'date'} = $date; |
64
|
0
|
|
|
|
|
|
$data->{'time'} = $time; |
65
|
0
|
|
|
|
|
|
$data->{'action'} = $action; |
66
|
0
|
|
|
|
|
|
$data->{'srcAddr'} = $from_addr; |
67
|
0
|
|
|
|
|
|
$data->{'dstAddr'} = $to_addr; |
68
|
0
|
|
|
|
|
|
$data->{'srcPort'} = $from_port; |
69
|
0
|
|
|
|
|
|
$data->{'dstPort'} = $to_port; |
70
|
0
|
|
|
|
|
|
$data->{'size'} = $size; |
71
|
0
|
|
|
|
|
|
$data->{'tcpFlags'} = $tcp_flags; |
72
|
0
|
|
|
|
|
|
$data->{'tcpSyn'} = $tcp_syn; |
73
|
0
|
|
|
|
|
|
$data->{'tcpAck'} = $tcp_ack; |
74
|
0
|
|
|
|
|
|
$data->{'tcpWin'} = $tcp_win; |
75
|
0
|
|
|
|
|
|
$data->{'icmpType'} = $icmp_type; |
76
|
0
|
|
|
|
|
|
$data->{'icmpCode'} = $icmp_code; |
77
|
0
|
|
|
|
|
|
$data->{'info'} = $info; |
78
|
0
|
|
|
|
|
|
$data->{'path'} = $path; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
map { $_->($data) } @{ $self->[HANDLERS] }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
close $fh; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |