line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# network::grep Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Network::Grep; |
7
|
1
|
|
|
1
|
|
728
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::Network::Read); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
546
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes => { |
19
|
|
|
|
|
|
|
device => [ qw(device) ], |
20
|
|
|
|
|
|
|
filter => [ qw(filter) ], |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
attributes_default => { |
23
|
|
|
|
|
|
|
filter => '', |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
commands => { |
26
|
|
|
|
|
|
|
from_network => [ qw(string filter|OPTIONAL device|OPTIONAL) ], |
27
|
|
|
|
|
|
|
from_pcap_file => [ qw(string pcap_file filter|OPTIONAL) ], |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
require_modules => { |
30
|
|
|
|
|
|
|
'Net::Frame::Simple' => [ ], |
31
|
|
|
|
|
|
|
'Metabrik::File::Pcap' => [ ], |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub brik_use_properties { |
37
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return { |
40
|
0
|
|
0
|
|
|
|
attributes_default => { |
41
|
|
|
|
|
|
|
device => defined($self->global) && $self->global->device || 'eth0', |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub from_network { |
47
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
48
|
0
|
|
|
|
|
|
my ($string, $filter, $device) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
0
|
|
|
|
$device ||= $self->device; |
51
|
0
|
|
0
|
|
|
|
$filter ||= $self->filter; |
52
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('from_network', $string) or return; |
53
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('from_network', $device) or return; |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
$self->open(2, $device, $filter) or return; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my @match = (); |
58
|
0
|
|
|
|
|
|
while (1) { |
59
|
0
|
0
|
|
|
|
|
my $h = $self->next or next; |
60
|
0
|
0
|
|
|
|
|
my $simple = Net::Frame::Simple->newFromDump($h) or next; |
61
|
0
|
|
0
|
|
|
|
my $layer = $simple->ref->{TCP} || $simple->ref->{UDP}; |
62
|
0
|
0
|
0
|
|
|
|
if (defined($layer) && length($layer->payload)) { |
63
|
0
|
|
|
|
|
|
my $payload = $layer->payload; |
64
|
0
|
0
|
|
|
|
|
if ($payload =~ m{$string}) { |
65
|
0
|
|
|
|
|
|
$self->log->info("from_network: payload: [$payload]"); |
66
|
0
|
|
|
|
|
|
push @match, $simple; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return \@match; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub from_pcap_file { |
75
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
76
|
0
|
|
|
|
|
|
my ($string, $pcap_file, $filter) = @_; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
0
|
|
|
|
$filter ||= $self->filter; |
79
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('from_pcap_file', $string) or return; |
80
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('from_pcap_file', $pcap_file) or return; |
81
|
0
|
0
|
|
|
|
|
$self->brik_help_run_file_not_found('from_pcap_file', $pcap_file) or return; |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
my $fp = Metabrik::File::Pcap->new_from_brik_init($self) or return; |
84
|
0
|
0
|
|
|
|
|
$fp->open($pcap_file, 'read', $filter) or return; |
85
|
0
|
0
|
|
|
|
|
my $read = $fp->read or return; |
86
|
0
|
|
|
|
|
|
$fp->close; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my @match = (); |
89
|
0
|
|
|
|
|
|
for my $h (@$read) { |
90
|
0
|
0
|
|
|
|
|
my $simple = Net::Frame::Simple->newFromDump($h) or next; |
91
|
0
|
|
0
|
|
|
|
my $layer = $simple->ref->{TCP} || $simple->ref->{UDP}; |
92
|
0
|
0
|
0
|
|
|
|
if (defined($layer) && length($layer->payload)) { |
93
|
0
|
|
|
|
|
|
my $payload = $layer->payload; |
94
|
0
|
0
|
|
|
|
|
if ($payload =~ m{$string}) { |
95
|
0
|
|
|
|
|
|
$self->log->info("from_pcap_file: payload: [$payload]"); |
96
|
0
|
|
|
|
|
|
push @match, $simple; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return \@match; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |