blib/lib/Net/Netcat.pm

filter: Statementstmt 44.8% 26 / 58 Branchbran 4.5% 1 / 22 Conditioncond 5.7% 2 / 35 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 85.7% 6 / 7 Podpod 100% 2 / 2 totaltotal 26.2% 37 / 141 CC 25 SCAR 58.9
CC
25
Cov
25%
execute
506.0
new
4.6
BEGIN
1.0
CRAP 359.9
↑ Summary
1 package Net::Netcat;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 our $VERSION = '0.05';
6  
7 3 ▶use base qw( Class::Accessor::Fast Class::ErrorHandler );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 __PACKAGE__->mk_accessors(qw/
9 netcat
10 options
11 timeout
12 stdin
13 stdout
14 stderr
15 command
16 /);
17  
18 3 ▶use IPC::Run qw( run );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Carp qw( carp );
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 3 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 2 ▶ sub new {
Subroutine new: called CC=4 SCAR=15.2
Pod documented
47 2 my $class = shift;
48 2 ▶ my $self = {
Condition50%1/2
shift() || 'nc'
l!l
02
MC/DC0%0/1
shift() || 'nc'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
49 nc => shift || 'nc',
50 options => [],
51 timeout => 0,
52 };
53  
54 2 system("$self->{nc} > /dev/null 2>&1");
55 2 my $ret = $? >> 8;
56 2 ▶ if ( $ret != 0 and $ret != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret != 0 and $ret != 1) 2 0 2
Condition33%1/3
$ret != 0 and $ret != 1
!ll&&!rl&&r
002
MC/DC0%0/2
$ret != 0 and $ret != 1
$ret != 0 $ret != 1
Truth table33%1/3
A and B
A= $ret != 0B= $ret != 1
ABresult
0X0
100
111
57 2 carp "Can't find nc command.";
58 2 exit 0;
59 }
60  
61 0 bless $self, $class;
62 }
63  
64 0 ▶sub execute {
Subroutine execute: not called CC=22 SCAR=62.3
Pod documented
65 0 my ($lflag, $printflg, $opts, %h, $ncdest, $ncport, $uflag) = ();
66  
67 0 my $self = shift;
68 0 $opts = $self->{options};
69  
70 0 %h = %{$opts};
71  
72 0 my @ncopts = ();
73 0 for my $key (keys(%h)) {
74 0 my $value = $h{$key};
75 0 ▶ if($key =~ /\-port/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /\-port/) 0 0 0
76 0 $ncport = $value;
77 0 next;
78 }
79 0 ▶ if($key =~ /\-dest/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /\-dest/) 0 0 0
80 0 $ncdest = $value;
81 0 next;
82 }
83 0 ▶ if(int($value) != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (int $value != 1) { } 0 0 0
84 0 push @ncopts, $key . ' ' . $value;
85 } else {
86 0 ▶ $printflg = 1 if ($key =~ /\-v/);
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /\-v/ 0 0 0
87 0 ▶ $uflag = 1 if ($key =~ /\-U/);
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /\-U/ 0 0 0
88 0 ▶ $lflag = 1 if ($key =~ /\-l/);
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /\-l/ 0 0 0
89 0 push @ncopts, $key;
90 }
91  
92 }
93 0 my $cmd = $self->{nc};
94 0 my $ncoptsline = join ' ', @ncopts;
95 0 ▶ if(defined($ncdest) and $ncdest =~ /\S/ and defined($uflag) and $uflag == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $ncdest and $ncdest =~ /\S/ and defined $uflag and $uflag == 1) { } 0 0 0
elsif (defined $ncport and $ncport =~ /\d/ and defined $lflag and $lflag == 1) { } 0 0 0
elsif (defined $ncdest and $ncdest =~ /\S/ and defined $ncport and $ncport =~ /\d/) { } 0 0 0
Condition0%0/9
defined $ncdest and $ncdest =~ /\S/ and defined $uflag and $uflag == 1
!ll&&!rl&&r
000
defined $ncdest and $ncdest =~ /\S/ and defined $uflag
!ll&&!rl&&r
000
defined $ncdest and $ncdest =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/4
defined $ncdest and $ncdest =~ /\S/ and defined $uflag and $uflag == 1
defined $ncdest $ncdest =~ /\S/ defined $uflag $uflag == 1
Truth table0%0/5
A and B and C and D
A= defined $ncdestB= $ncdest =~ /\S/C= defined $uflagD= $uflag == 1
ABCDresult
0XXX0
10XX0
110X0
11100
11111
96 0 $ncoptsline = $ncoptsline . " " . $ncdest;
97 ▶ } elsif(defined($ncport) and $ncport =~ /\d/ and defined($lflag) and $lflag == 1) {
Condition0%0/9
defined $ncport and $ncport =~ /\d/ and defined $lflag and $lflag == 1
!ll&&!rl&&r
000
defined $ncport and $ncport =~ /\d/ and defined $lflag
!ll&&!rl&&r
000
defined $ncport and $ncport =~ /\d/
!ll&&!rl&&r
000
MC/DC0%0/4
defined $ncport and $ncport =~ /\d/ and defined $lflag and $lflag == 1
defined $ncport $ncport =~ /\d/ defined $lflag $lflag == 1
Truth table0%0/5
A and B and C and D
A= defined $ncportB= $ncport =~ /\d/C= defined $lflagD= $lflag == 1
ABCDresult
0XXX0
10XX0
110X0
11100
11111
98 0 $ncoptsline = $ncoptsline . " " . $ncport;
99 ▶ } elsif(defined($ncdest) and $ncdest =~ /\S/ and defined($ncport) and $ncport =~ /\d/) {
Condition0%0/9
defined $ncdest and $ncdest =~ /\S/ and defined $ncport and $ncport =~ /\d/
!ll&&!rl&&r
000
defined $ncdest and $ncdest =~ /\S/ and defined $ncport
!ll&&!rl&&r
000
defined $ncdest and $ncdest =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/4
defined $ncdest and $ncdest =~ /\S/ and defined $ncport and $ncport =~ /\d/
defined $ncdest $ncdest =~ /\S/ defined $ncport $ncport =~ /\d/
Truth table0%0/5
A and B and C and D
A= defined $ncdestB= $ncdest =~ /\S/C= defined $ncportD= $ncport =~ /\d/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
100 0 $ncoptsline = $ncoptsline . " " . join " ", $ncdest, $ncport;
101 }
102 0 my $fullcmd = $cmd . " " . $ncoptsline ;
103 0 ▶ print "Command line is: $fullcmd\n" if(defined($printflg) and $printflg == 1);
Branch: 1 branch
BranchTrueFalseTotal
if defined $printflg and $printflg == 1 0 0 0
Condition0%0/3
defined $printflg and $printflg == 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $printflg and $printflg == 1
defined $printflg $printflg == 1
Truth table0%0/3
A and B
A= defined $printflgB= $printflg == 1
ABresult
0X0
100
111
104 0 my @runcmd = split / /, $fullcmd;
105  
106 0 run \@runcmd;
107 0 return 0;
108  
109 }
110  
111 3 *exec = \&execute;
112  
113 __END__
↑ Summary