lib/Net/SinFP3/Ext/TCP.pm

filter: Statementstmt 20.8% 19 / 91 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 31.2% 5 / 16 Podpod 100% 1 / 1 totaltotal 15.6% 25 / 160 CC 24 SCAR 47.6
CC
24
Cov
14%
_analyzeTcpOptions
272.0
__analyzeTcpSeq
20.0
__analyzeTcpAck
20.0
CRAP 116.7
« lib/Net/SinFP3/Search/Active.pm ↑ Summary lib/Net/SinFP3.pm »
1 #
2 # $Id: TCP.pm,v 008243d3e89a 2018/07/21 14:54:07 gomor $
3 #
4 package Net::SinFP3::Ext::TCP;
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use base qw(Class::Gomor::Array);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 our @AS = qw(
10 global
11 next
12 _src
13 _seq
14 _ack
15 );
16 1 __PACKAGE__->cgBuildIndices;
17 1 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
18  
19 1 ▶use Net::Frame::Layer qw(:subs);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Net::Frame::Layer::TCP qw(:consts);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
23 0 my $self = shift->SUPER::new(
24 @_,
25 );
26  
27 0 my $src = $self->_getInitial16bits;
28 0 my $seq = $self->_getInitial32bits;
29 0 my $ack = $self->_getInitial32bits;
30  
31 0 $self->_src($src);
32 0 $self->_seq($seq);
33 0 $self->_ack($ack);
34  
35 0 return $self;
36 }
37  
38 0 ▶sub _getInitial16bits {
Subroutine _getInitial16bits: not called CC=2 SCAR=17.9
39 0 my $self = shift;
40 0 my $i16 = getRandom16bitsInt() - 3;
41 0 ▶ $i16 += 1025 unless $i16 > 1024;
Branch: 1 branch
BranchTrueFalseTotal
unless $i16 > 1024 0 0 0
42 0 return $i16;
43 }
44  
45 0 ▶sub _getInitial32bits {
Subroutine _getInitial32bits: not called CC=2 SCAR=17.9
46 0 my $self = shift;
47 0 my $i32 = getRandom32bitsInt() - 3;
48 0 ▶ $i32 += 666 unless $i32 > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $i32 > 0 0 0 0
49 0 return $i32;
50 }
51  
52 0 ▶sub _getP1Tcp {
Subroutine _getP1Tcp: not called CC=1 SCAR=6.9
53 0 my $self = shift;
54 0 return Net::Frame::Layer::TCP->new(
55 src => $self->_src,
56 seq => $self->_seq,
57 ack => $self->_ack,
58 dst => $self->next->port,
59 x2 => 0,
60 flags => NF_TCP_FLAGS_SYN,
61 win => 5840,
62 options =>
63 "\x02\x04\x05\xb4".
64 "",
65 );
66 }
67  
68 0 ▶sub _getP2Tcp {
Subroutine _getP2Tcp: not called CC=1 SCAR=6.9
69 0 my $self = shift;
70 0 return Net::Frame::Layer::TCP->new(
71 src => $self->_src + 1,
72 seq => $self->_seq + 1,
73 ack => $self->_ack + 1,
74 dst => $self->next->port,
75 x2 => 0,
76 flags => NF_TCP_FLAGS_SYN,
77 win => 5840,
78 options =>
79 "\x02\x04\x05\xb4".
80 "\x08\x0a\x44\x45".
81 "\x41\x44\x00\x00".
82 "\x00\x00\x03\x03".
83 "\x01\x04\x02\x00".
84 "",
85 );
86 }
87  
88 0 ▶sub _getP3Tcp {
Subroutine _getP3Tcp: not called CC=1 SCAR=6.9
89 0 my $self = shift;
90 0 return Net::Frame::Layer::TCP->new(
91 src => $self->_src + 2,
92 seq => $self->_seq + 2,
93 ack => $self->_ack + 2,
94 dst => $self->next->port,
95 x2 => 0,
96 flags => NF_TCP_FLAGS_SYN | NF_TCP_FLAGS_ACK,
97 win => 5840,
98 );
99 }
100  
101 0 ▶sub __analyzeTcpSeq {
Subroutine __analyzeTcpSeq: not called CC=4 SCAR=30.0
102 0 my $self = shift;
103 0 my ($p) = @_;
104 0 my $reqAck = $p->ref->{TCP}->ack;
105 0 my $repSeq = $p->reply->ref->{TCP}->seq;
106 0 my $flag = 1;
107 0 ▶ if ($repSeq == 0 ) { $flag = 0 }
Branch: 3 branches
BranchTrueFalseTotal
if ($repSeq == 0) { } 0 0 0
elsif ($repSeq == $reqAck) { } 0 0 0
elsif ($repSeq == ++$reqAck) { } 0 0 0
108 0 elsif ($repSeq == $reqAck ) { $flag = 2 }
109 0 elsif ($repSeq == ++$reqAck) { $flag = 3 }
110 0 return $flag;
111 }
112  
113 0 ▶sub __analyzeTcpAck {
Subroutine __analyzeTcpAck: not called CC=4 SCAR=30.0
114 0 my $self = shift;
115 0 my ($p) = @_;
116 0 my $reqSeq = $p->ref->{TCP}->seq;
117 0 my $repAck = $p->reply->ref->{TCP}->ack;
118 0 my $flag = 1;
119 0 ▶ if ($repAck == 0 ) { $flag = 0 }
Branch: 3 branches
BranchTrueFalseTotal
if ($repAck == 0) { } 0 0 0
elsif ($repAck == $reqSeq) { } 0 0 0
elsif ($repAck == ++$reqSeq) { } 0 0 0
120 0 elsif ($repAck == $reqSeq ) { $flag = 2 }
121 0 elsif ($repAck == ++$reqSeq) { $flag = 3 }
122 0 return $flag;
123 }
124  
125 0 ▶sub _analyzeTcpFlags {
Subroutine _analyzeTcpFlags: not called CC=1 SCAR=6.9
126 0 my $self = shift;
127 0 my ($p) = @_;
128 0 return sprintf("F0x%02x", $p->reply->ref->{TCP}->flags);
129 }
130  
131 0 ▶sub _analyzeTcpWindow {
Subroutine _analyzeTcpWindow: not called CC=1 SCAR=6.9
132 0 my $self = shift;
133 0 my ($p) = @_;
134 0 return 'W'.$p->reply->ref->{TCP}->win;
135 }
136  
137 0 ▶sub _analyzeTcpOptions {
Subroutine _analyzeTcpOptions: not called CC=16 SCAR=56.1
138 0 my $self = shift;
139 0 my ($p) = @_;
140 # Rewrite timestamp values, if > 0 overwrite with ffff,
141 # for each timestamp. Same with WScale value
142 0 my $mss;
143 my $wscale;
144 0 my $opts;
145 0 ▶ if ($opts = unpack('H*', $p->reply->ref->{TCP}->options)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts = unpack("H*", $p->reply->ref->{"TCP"}->options)) 0 0 0
146 0 ▶ if ($opts =~ /080a(........)(........)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts =~ /080a(........)(........)/) 0 0 0
147 0 ▶ if ($1 && $1 !~ /44454144|00000000/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 and not $1 =~ /44454144|00000000/) 0 0 0
Condition0%0/3
$1 and not $1 =~ /44454144|00000000/
!ll&&!rl&&r
000
MC/DC0%0/2
$1 and not $1 =~ /44454144|00000000/
$1 not $1 =~ /44454144|00000000/
Truth table0%0/3
A and not(B)
A= $1B= not $1 =~ /44454144|00000000/
ABresult
0X0
100
111
148 0 $opts =~ s/(080a)........(........)/$1ffffffff$2/;
149 }
150 0 ▶ if ($2 && $2 !~ /44454144|00000000/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 and not $2 =~ /44454144|00000000/) 0 0 0
Condition0%0/3
$2 and not $2 =~ /44454144|00000000/
!ll&&!rl&&r
000
MC/DC0%0/2
$2 and not $2 =~ /44454144|00000000/
$2 not $2 =~ /44454144|00000000/
Truth table0%0/3
A and not(B)
A= $2B= not $2 =~ /44454144|00000000/
ABresult
0X0
100
111
151 0 $opts =~ s/(080a........)......../$1ffffffff/;
152 }
153 }
154 # Move MSS value in its own field
155 0 ▶ if ($opts =~ /0204(....)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts =~ /0204(....)/) 0 0 0
156 0 ▶ if ($1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1) 0 0 0
157 0 $mss = sprintf("%d", hex($1));
158 0 $opts =~ s/0204..../0204ffff/;
159 }
160 }
161 # Move WScale value in its own field
162 0 ▶ if ($opts =~ /0303(..)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts =~ /0303(..)/) 0 0 0
163 0 ▶ if ($1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1) 0 0 0
164 0 $wscale = sprintf("%d", hex($1));
165 0 $opts =~ s/0303../0303ff/;
166 }
167 }
168 }
169 $opts .= unpack('H*', $p->reply->ref->{TCP}->payload)
170 0 ▶ if $p->reply->ref->{TCP}->payload;
Branch: 1 branch
BranchTrueFalseTotal
if $p->reply->ref->{"TCP"}->payload 0 0 0
171  
172 0 ▶ $opts = '0' unless $opts;
Branch: 1 branch
BranchTrueFalseTotal
unless $opts 0 0 0
173 0 ▶ $mss = '0' unless $mss;
Branch: 1 branch
BranchTrueFalseTotal
unless $mss 0 0 0
174 0 ▶ $wscale = '0' unless $wscale;
Branch: 1 branch
BranchTrueFalseTotal
unless $wscale 0 0 0
175 0 ▶ my $optLen = $opts ? length($opts) / 2 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts ? : 0 0 0
176 0 return [ 'O'.$opts, 'M'.$mss, 'S'.$wscale, 'L'.$optLen ];
177 }
178  
179 1 1;
180  
181 __END__
« lib/Net/SinFP3/Search/Active.pm ↑ Summary lib/Net/SinFP3.pm »