line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id: Shell.pm 8 2010-06-04 11:43:42Z gomor $ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
package Net::Packet::Shell; |
5
|
1
|
|
|
1
|
|
7291
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
81
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.22'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my @subList = qw( |
11
|
|
|
|
|
|
|
F sr sd sd2 sd3 sniff dsniff read |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my @layerList = qw( |
15
|
|
|
|
|
|
|
ETH RAW SLL NULL ARP IPv4 IPv6 TCP UDP VLAN ICMPv4 PPPoE PPP PPPLCP LLC CDP |
16
|
|
|
|
|
|
|
STP OSPF IGMPv4 |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
5
|
use Exporter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
110
|
|
20
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
21
|
|
|
|
|
|
|
our @EXPORT = ( |
22
|
|
|
|
|
|
|
'nps', |
23
|
|
|
|
|
|
|
'$Env', |
24
|
|
|
|
|
|
|
@subList, |
25
|
|
|
|
|
|
|
@layerList, |
26
|
|
|
|
|
|
|
@Net::Packet::Env::EXPORT_OK, |
27
|
|
|
|
|
|
|
@Net::Packet::Utils::EXPORT_OK, |
28
|
|
|
|
|
|
|
@Net::Packet::Consts::EXPORT_OK, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
1663
|
use Net::Packet; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use Net::Write::Layer2; |
33
|
|
|
|
|
|
|
use Net::Write::Layer3; |
34
|
|
|
|
|
|
|
use Data::Dumper; |
35
|
|
|
|
|
|
|
use Term::ReadLine; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
$Env->noFrameAutoDesc(1); |
38
|
|
|
|
|
|
|
$Env->noFrameAutoDump(1); |
39
|
|
|
|
|
|
|
$Env->noDescAutoSet(1); |
40
|
|
|
|
|
|
|
$Env->noDumpAutoSet(0); |
41
|
|
|
|
|
|
|
$Env->doFrameReturnList(1); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
_resetEnv(); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _resetEnv { |
46
|
|
|
|
|
|
|
$Env->noFramePadding(1); |
47
|
|
|
|
|
|
|
$Env->noFrameComputeLengths(0); |
48
|
|
|
|
|
|
|
$Env->noFrameComputeChecksums(0); |
49
|
|
|
|
|
|
|
$Env->doIPv4Checksum(0); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _frame { |
53
|
|
|
|
|
|
|
my $f = Net::Packet::Frame->new; |
54
|
|
|
|
|
|
|
for my $l (@_) { |
55
|
|
|
|
|
|
|
do { $f->l2($l); next } if $l->isLayer2; |
56
|
|
|
|
|
|
|
do { $f->l3($l); next } if $l->isLayer3; |
57
|
|
|
|
|
|
|
do { $f->l4($l); next } if $l->isLayer4; |
58
|
|
|
|
|
|
|
do { $f->l7($l); next } if $l->isLayer7; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
$f->pack; |
61
|
|
|
|
|
|
|
$f; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
*F = sub { _frame(@_) }; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
{ |
67
|
|
|
|
|
|
|
no strict 'refs'; |
68
|
|
|
|
|
|
|
for my $l (@layerList) { |
69
|
|
|
|
|
|
|
*$l = sub { my $r = "Net::Packet::$l"->new(@_); $r->pack; $r }; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub sr { |
74
|
|
|
|
|
|
|
do { print "Nothing to send\n"; return } unless $_[0]; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $d = Net::Write::Layer2->new(dev => $Env->dev); |
77
|
|
|
|
|
|
|
$d->open; |
78
|
|
|
|
|
|
|
$d->send(shift()); |
79
|
|
|
|
|
|
|
$d->close; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub sd { |
83
|
|
|
|
|
|
|
do { print "Nothing to send\n"; return } unless $_[0]; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
return sd2(@_) if $_[0]->l2; |
86
|
|
|
|
|
|
|
return sd3(@_) if $_[0]->l3; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub sd2 { |
90
|
|
|
|
|
|
|
my ($f) = @_; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
do { print "Nothing to send\n"; return } unless $f; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$Env->doIPv4Checksum(1); |
95
|
|
|
|
|
|
|
$Env->noFrameComputeLengths(0); |
96
|
|
|
|
|
|
|
$Env->noFrameComputeChecksums(0); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$f->pack; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $d = Net::Write::Layer2->new(dev => $Env->dev); |
101
|
|
|
|
|
|
|
$d->open; |
102
|
|
|
|
|
|
|
$d->send($f->raw); |
103
|
|
|
|
|
|
|
$d->close; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
_resetEnv(); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub sd3 { |
109
|
|
|
|
|
|
|
my ($f) = @_; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
do { print "Nothing to send\n"; return } unless $f; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
do { print "We can only send IPv4 frames at layer 3\n"; return } |
114
|
|
|
|
|
|
|
if ($f->l2 || ($f->l3 && ! $f->l3->isIpv4)); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$Env->doIPv4Checksum(0); |
117
|
|
|
|
|
|
|
$Env->noFrameComputeLengths(0); |
118
|
|
|
|
|
|
|
$Env->noFrameComputeChecksums(0); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my $dst = $f->l3->dst; |
121
|
|
|
|
|
|
|
$f->pack; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $d = Net::Write::Layer3->new(dev => $Env->dev, dst => $dst); |
124
|
|
|
|
|
|
|
$d->open; |
125
|
|
|
|
|
|
|
$d->send($f->raw); |
126
|
|
|
|
|
|
|
$d->close; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
_resetEnv(); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub sniff { |
132
|
|
|
|
|
|
|
my ($filter) = @_; |
133
|
|
|
|
|
|
|
my $d = Net::Packet::Dump->new( |
134
|
|
|
|
|
|
|
noStore => 1, |
135
|
|
|
|
|
|
|
); |
136
|
|
|
|
|
|
|
$d->filter($filter) if $filter; |
137
|
|
|
|
|
|
|
$d->start; |
138
|
|
|
|
|
|
|
while (1) { |
139
|
|
|
|
|
|
|
if (my $f = $d->next) { |
140
|
|
|
|
|
|
|
for (@$f) { |
141
|
|
|
|
|
|
|
print $_->l2->print."\n" if $_->l2; |
142
|
|
|
|
|
|
|
print $_->l3->print."\n" if $_->l3; |
143
|
|
|
|
|
|
|
print $_->l4->print."\n" if $_->l4; |
144
|
|
|
|
|
|
|
print $_->l7->print."\n" if $_->l7; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub dsniff { |
151
|
|
|
|
|
|
|
my ($filter) = @_; |
152
|
|
|
|
|
|
|
my $d = Net::Packet::Dump->new( |
153
|
|
|
|
|
|
|
noStore => 1, |
154
|
|
|
|
|
|
|
); |
155
|
|
|
|
|
|
|
$d->filter($filter) if $filter; |
156
|
|
|
|
|
|
|
$d->start; |
157
|
|
|
|
|
|
|
while (1) { |
158
|
|
|
|
|
|
|
if (my $f = $d->next) { |
159
|
|
|
|
|
|
|
for my $c (@$f) { |
160
|
|
|
|
|
|
|
if ($c->l7) { |
161
|
|
|
|
|
|
|
my $data = $c->l7->data; |
162
|
|
|
|
|
|
|
next unless $data =~ /^user\s+|^pass\s+/i; |
163
|
|
|
|
|
|
|
print $c->l3->dst.':'.$c->l4->dst.'> '.$data."\n"; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub read { |
171
|
|
|
|
|
|
|
my ($file) = @_; |
172
|
|
|
|
|
|
|
do { print "Please specify a pcap file to read\n"; return } unless $file; |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
my $d = Net::Packet::Dump->new( |
175
|
|
|
|
|
|
|
file => $file, |
176
|
|
|
|
|
|
|
mode => NP_DUMP_MODE_OFFLINE, |
177
|
|
|
|
|
|
|
overwrite => 0, |
178
|
|
|
|
|
|
|
unlinkOnClean => 0, |
179
|
|
|
|
|
|
|
noStore => 1, |
180
|
|
|
|
|
|
|
); |
181
|
|
|
|
|
|
|
$d->start; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
my $n = 0; |
184
|
|
|
|
|
|
|
while (my $fr = $d->next) { |
185
|
|
|
|
|
|
|
++$n; |
186
|
|
|
|
|
|
|
print 'Number of frames in chunk: '.scalar(@$fr)."\n"; |
187
|
|
|
|
|
|
|
for (@$fr) { |
188
|
|
|
|
|
|
|
print 'Frame number: '.$n."\n"; |
189
|
|
|
|
|
|
|
print $_->print."\n"; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
print "\n"; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
$d->stop; |
195
|
|
|
|
|
|
|
$d->clean; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub nps { |
199
|
|
|
|
|
|
|
my $prompt = 'nps> '; |
200
|
|
|
|
|
|
|
my $name = 'NPS'; |
201
|
|
|
|
|
|
|
my $term = Term::ReadLine->new($name); |
202
|
|
|
|
|
|
|
$term->ornaments(0); |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
$term->Attribs->{completion_function} = sub { |
205
|
|
|
|
|
|
|
( @subList, @layerList ) |
206
|
|
|
|
|
|
|
}; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
{ |
209
|
|
|
|
|
|
|
no strict; |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
while (my $line = $term->readline($prompt)) { |
212
|
|
|
|
|
|
|
$line =~ s/s*read/Net::Packet::Shell::read/; |
213
|
|
|
|
|
|
|
eval($line); |
214
|
|
|
|
|
|
|
warn($@) if $@; |
215
|
|
|
|
|
|
|
print "\n"; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
print "\n"; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
END { |
223
|
|
|
|
|
|
|
if ($Env->dump) { |
224
|
|
|
|
|
|
|
$Env->dump->stop; |
225
|
|
|
|
|
|
|
$Env->dump->clean; |
226
|
|
|
|
|
|
|
} |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
1; |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
__END__ |