line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# remote::tcpdump Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Remote::Tcpdump; |
7
|
1
|
|
|
1
|
|
752
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::Client::Ssh); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
888
|
|
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
|
|
|
|
|
|
|
_started => [ qw(INTERNAL) ], |
21
|
|
|
|
|
|
|
_channel => [ qw(INTERNAL) ], |
22
|
|
|
|
|
|
|
_out => [ qw(INTERNAL) ], |
23
|
|
|
|
|
|
|
_dump => [ qw(INTERNAL) ], |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
attributes_default => { |
26
|
|
|
|
|
|
|
username => 'root', |
27
|
|
|
|
|
|
|
hostname => 'localhost', |
28
|
|
|
|
|
|
|
port => 22, |
29
|
|
|
|
|
|
|
_started => 0, |
30
|
|
|
|
|
|
|
_channel => undef, |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
commands => { |
33
|
|
|
|
|
|
|
start => [ ], |
34
|
|
|
|
|
|
|
status => [ ], |
35
|
|
|
|
|
|
|
stop => [ ], |
36
|
|
|
|
|
|
|
next => [ ], |
37
|
|
|
|
|
|
|
nextall => [ ], |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
require_modules => { |
40
|
|
|
|
|
|
|
'Net::Frame::Dump::Offline' => [], |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub brik_use_properties { |
46
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return { |
49
|
0
|
|
0
|
|
|
|
attributes_default => { |
50
|
|
|
|
|
|
|
device => defined($self->global) && $self->global->device || 'eth0', |
51
|
|
|
|
|
|
|
}, |
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub start { |
56
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if ($self->_started) { |
59
|
0
|
|
|
|
|
|
return $self->log->verbose("start: already started"); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
$self->connect or return; |
63
|
0
|
|
|
|
|
|
$self->log->verbose("ssh connection successful"); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $dump = Net::Frame::Dump::Offline->new; |
66
|
0
|
|
|
|
|
|
$self->_dump($dump); |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$self->log->debug("dump file[".$dump->file."]"); |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
open(my $out, '>', $dump->file) |
71
|
|
|
|
|
|
|
or return $self->log->error("cannot open file: $!"); |
72
|
0
|
|
|
|
|
|
my $old = select($out); |
73
|
0
|
|
|
|
|
|
$|++; |
74
|
0
|
|
|
|
|
|
select($old); |
75
|
0
|
|
|
|
|
|
$self->_out($out); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $device = $self->device; |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
my $channel = $self->exec("tcpdump -U -i $device -w - 2> /dev/null") or return; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$self->log->debug("tcpdump started"); |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
$self->_started(1); |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return $self->_channel($channel); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub status { |
89
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
return $self->_started; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub stop { |
95
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
if (! $self->_started) { |
98
|
0
|
|
|
|
|
|
return $self->log->error($self->brik_help_run('start')); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
$self->nextall; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $r = $self->disconnect; |
104
|
0
|
|
|
|
|
|
$self->_dump->stop; |
105
|
0
|
|
|
|
|
|
unlink($self->_dump->file); |
106
|
0
|
|
|
|
|
|
close($self->_out); |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$self->_started(0); |
109
|
0
|
|
|
|
|
|
$self->_channel(undef); |
110
|
0
|
|
|
|
|
|
$self->_out(undef); |
111
|
0
|
|
|
|
|
|
$self->_dump(undef); |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return $r; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub next { |
117
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
118
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
|
if (! $self->_started) { |
120
|
0
|
|
|
|
|
|
return $self->log->error($self->brik_help_run('start')); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
my $channel = $self->_channel; |
124
|
0
|
0
|
|
|
|
|
if (! defined($channel)) { |
125
|
0
|
|
|
|
|
|
return $self->log->error("next: channel not found"); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
my $out = $self->_out; |
129
|
0
|
|
|
|
|
|
while (my $line = <$channel>) { |
130
|
0
|
|
|
|
|
|
print $out $line; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# If reader not already open, we open it |
134
|
0
|
|
|
|
|
|
my $dump = $self->_dump; |
135
|
0
|
0
|
|
|
|
|
if (! $dump->isRunning) { |
136
|
0
|
0
|
|
|
|
|
$dump->start or return $self->log->error("unable to start pcap reader"); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
if (my $h = $dump->next) { |
140
|
0
|
|
|
|
|
|
return $h; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
return; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub nextall { |
147
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
148
|
|
|
|
|
|
|
|
149
|
0
|
0
|
|
|
|
|
if (! $self->_started) { |
150
|
0
|
|
|
|
|
|
return $self->log->error($self->brik_help_run('start')); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my $channel = $self->_channel; |
154
|
0
|
0
|
|
|
|
|
if (! defined($channel)) { |
155
|
0
|
|
|
|
|
|
return $self->log->error("nextall: channel not found"); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
my $out = $self->_out; |
159
|
0
|
|
|
|
|
|
while (my $line = <$channel>) { |
160
|
0
|
|
|
|
|
|
print $out $line; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# If reader not already open, we open it |
164
|
0
|
|
|
|
|
|
my $dump = $self->_dump; |
165
|
0
|
0
|
|
|
|
|
if (! $dump->isRunning) { |
166
|
0
|
0
|
|
|
|
|
$dump->start or return $self->log->error("nextall: unable to start pcap reader"); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
my @next = (); |
170
|
0
|
|
|
|
|
|
while (my $h = $dump->next) { |
171
|
0
|
|
|
|
|
|
push @next, $h; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
return \@next; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
__END__ |