| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::Netcat; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1622
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
67
|
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
99
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
9
|
use base qw( Class::Accessor::Fast Class::ErrorHandler ); |
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
2452
|
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ |
|
9
|
|
|
|
|
|
|
netcat |
|
10
|
|
|
|
|
|
|
options |
|
11
|
|
|
|
|
|
|
timeout |
|
12
|
|
|
|
|
|
|
stdin |
|
13
|
|
|
|
|
|
|
stdout |
|
14
|
|
|
|
|
|
|
stderr |
|
15
|
|
|
|
|
|
|
command |
|
16
|
|
|
|
|
|
|
/); |
|
17
|
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
14089
|
use IPC::Run qw( run ); |
|
|
2
|
|
|
|
|
164889
|
|
|
|
2
|
|
|
|
|
154
|
|
|
19
|
2
|
|
|
2
|
|
22
|
use Carp qw( carp ); |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
1799
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our %options = ( |
|
22
|
|
|
|
|
|
|
ipv4only => '-4', |
|
23
|
|
|
|
|
|
|
ipv6only => '-6', |
|
24
|
|
|
|
|
|
|
staylistening => '-k', |
|
25
|
|
|
|
|
|
|
listenmode => '-l', |
|
26
|
|
|
|
|
|
|
nodns => '-n', |
|
27
|
|
|
|
|
|
|
randomports => '-r', |
|
28
|
|
|
|
|
|
|
md5sign => '-S', |
|
29
|
|
|
|
|
|
|
rfc854telnet => '-y', |
|
30
|
|
|
|
|
|
|
unixsocket => '-U', |
|
31
|
|
|
|
|
|
|
udpsocket => '-u', |
|
32
|
|
|
|
|
|
|
verbose => '-v', |
|
33
|
|
|
|
|
|
|
scanmode => '-z', |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
tcprecvbuff => '-I length', |
|
36
|
|
|
|
|
|
|
tcpsendbuff => '-O length', |
|
37
|
|
|
|
|
|
|
delaypkt => '-i interval', |
|
38
|
|
|
|
|
|
|
sourceport => '-p source_port', |
|
39
|
|
|
|
|
|
|
sourceip => '-s source', |
|
40
|
|
|
|
|
|
|
toskeyword => '-T tos', |
|
41
|
|
|
|
|
|
|
timeout => '-w timeout', |
|
42
|
|
|
|
|
|
|
port => '-port port', |
|
43
|
|
|
|
|
|
|
dest => '-dest destination_to_connect_to' |
|
44
|
|
|
|
|
|
|
); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new { |
|
47
|
2
|
|
|
2
|
1
|
212
|
my $class = shift; |
|
48
|
2
|
|
50
|
|
|
22
|
my $self = { |
|
49
|
|
|
|
|
|
|
nc => shift || 'nc', |
|
50
|
|
|
|
|
|
|
options => [], |
|
51
|
|
|
|
|
|
|
timeout => 0, |
|
52
|
|
|
|
|
|
|
}; |
|
53
|
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
19587
|
system("$self->{nc} > /dev/null 2>&1"); |
|
55
|
2
|
|
|
|
|
86
|
my $ret = $? >> 8; |
|
56
|
2
|
50
|
33
|
|
|
130
|
if ( $ret != 0 and $ret != 1 ) { |
|
57
|
0
|
|
|
|
|
0
|
carp "Can't find nc command."; |
|
58
|
0
|
|
|
|
|
0
|
exit 0; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
132
|
bless $self, $class; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub execute { |
|
65
|
2
|
|
|
2
|
1
|
433
|
my ($lflag, $printflg, $opts, %h, $ncdest, $ncport, $uflag) = (); |
|
66
|
|
|
|
|
|
|
|
|
67
|
2
|
|
|
|
|
16
|
my $self = shift; |
|
68
|
2
|
|
|
|
|
28
|
$opts = $self->{options}; |
|
69
|
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
15
|
%h = %{$opts}; |
|
|
2
|
|
|
|
|
27
|
|
|
71
|
|
|
|
|
|
|
|
|
72
|
2
|
|
|
|
|
24
|
my @ncopts = (); |
|
73
|
2
|
|
|
|
|
35
|
for my $key (keys(%h)) { |
|
74
|
2
|
|
|
|
|
9
|
my $value = $h{$key}; |
|
75
|
2
|
50
|
|
|
|
33
|
if($key =~ /\-port/) { |
|
76
|
0
|
|
|
|
|
0
|
$ncport = $value; |
|
77
|
0
|
|
|
|
|
0
|
next; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
2
|
50
|
|
|
|
17
|
if($key =~ /\-dest/) { |
|
80
|
0
|
|
|
|
|
0
|
$ncdest = $value; |
|
81
|
0
|
|
|
|
|
0
|
next; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
2
|
50
|
|
|
|
22
|
if(int($value) != 1) { |
|
84
|
0
|
|
|
|
|
0
|
push @ncopts, $key . ' ' . $value; |
|
85
|
|
|
|
|
|
|
} else { |
|
86
|
2
|
50
|
|
|
|
119
|
$printflg = 1 if ($key =~ /\-v/); |
|
87
|
2
|
50
|
|
|
|
20
|
$uflag = 1 if ($key =~ /\-U/); |
|
88
|
2
|
50
|
|
|
|
116
|
$lflag = 1 if ($key =~ /\-l/); |
|
89
|
2
|
|
|
|
|
24
|
push @ncopts, $key; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
} |
|
93
|
2
|
|
|
|
|
159
|
my $cmd = $self->{nc}; |
|
94
|
2
|
|
|
|
|
22
|
my $ncoptsline = join ' ', @ncopts; |
|
95
|
2
|
50
|
33
|
|
|
196
|
if(defined($ncdest) and $ncdest =~ /\S/ and defined($uflag) and $uflag == 1) { |
|
|
|
50
|
33
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
96
|
0
|
|
|
|
|
0
|
$ncoptsline = $ncoptsline . " " . $ncdest; |
|
97
|
|
|
|
|
|
|
} elsif(defined($ncport) and $ncport =~ /\d/ and defined($lflag) and $lflag == 1) { |
|
98
|
0
|
|
|
|
|
0
|
$ncoptsline = $ncoptsline . " " . $ncport; |
|
99
|
|
|
|
|
|
|
} elsif(defined($ncdest) and $ncdest =~ /\S/ and defined($ncport) and $ncport =~ /\d/) { |
|
100
|
0
|
|
|
|
|
0
|
$ncoptsline = $ncoptsline . " " . join " ", $ncdest, $ncport; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
2
|
|
|
|
|
16
|
my $fullcmd = $cmd . " " . $ncoptsline ; |
|
103
|
2
|
50
|
33
|
|
|
1001
|
print "Command line is: $fullcmd\n" if(defined($printflg) and $printflg == 1); |
|
104
|
2
|
|
|
|
|
22
|
my @runcmd = split / /, $fullcmd; |
|
105
|
|
|
|
|
|
|
|
|
106
|
2
|
|
|
|
|
38
|
run \@runcmd; |
|
107
|
2
|
|
|
|
|
22400
|
return 0; |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
*exec = \&execute; |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |