lib/Net/SinFP3/Result/Passive.pm untested

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 94 CC 6 SCAR 22.3
CC
6
Cov
0%
printSignature
20.0
print
12.0
take
2.0
CRAP 9.3
1 #
2 # $Id: Passive.pm,v 008243d3e89a 2018/07/21 14:54:07 gomor $
3 #
4 package Net::SinFP3::Result::Passive;
5 use strict;
6 use warnings;
7  
8 use base qw(Net::SinFP3::Result);
9 our @AS = qw(
10 ip
11 port
12 hostname
13 reverse
14 frame
15  
16 sp
17  
18 trusted
19 idSignatureP
20 ipVersion
21 systemClass
22 vendor
23 os
24 osVersion
25 osVersionFamily
26 matchType
27 matchMask
28 matchScore
29 );
30 our @AA = qw(
31 osVersionChildrenList
32 );
33 __PACKAGE__->cgBuildIndices;
34 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
35 __PACKAGE__->cgBuildAccessorsArray (\@AA);
36  
37 use Net::SinFP3::Ext::SP;
38  
39 sub take {
40 return [
41 'Net::SinFP3::Search::Passive',
42 ];
43 }
44  
45 sub new {
46 my $self = shift->SUPER::new(
47 ip => '127.0.0.1',
48 port => '1',
49 hostname => 'unknown',
50 reverse => 'unknown',
51 osVersionChildrenList => [],
52 @_,
53 );
54  
55 return $self;
56 }
57  
58 sub updateMatchScore {
59 my $self = shift;
60 my $score = {
61 'OH0' => 46,
62 'WH0' => 30,
63 'SH0' => 12,
64 'MH0' => 6,
65 'LH0' => 6,
66 'FH0' => 0,
67  
68 'OH1' => 28,
69 'WH1' => 20,
70 'SH1' => 6,
71 'MH1' => 4,
72 'LH1' => 4,
73 'FH1' => 0,
74  
75 'FH2' => 0,
76 'WH2' => 0,
77 'OH2' => 0,
78 'MH2' => 0,
79 'SH2' => 0,
80 'LH2' => 0,
81 };
82 my $matchMask = $self->matchMask;
83 my @toks = $matchMask =~ /(FH.)(WH.)(OH.)(MH.)(SH.)(LH.)/;
84 my $result = 0;
85 for (@toks) {
86 $result += $score->{$_};
87 }
88 return $self->matchScore($result);
89 }
90  
91 sub printSignature {
92 my $self = shift;
93  
94 my $global = $self->global;
95 my $log = $global->log;
96  
97 my $buf = '';
98 if ($self->frame) {
99 my $frame = $self->frame;
100 my $ip = $frame->ref->{IPv4} || $frame->ref->{IPv6};
101 $buf .= $ip->src.':'.$frame->ref->{TCP}->src.' > '.
102 $ip->dst.':'.$frame->ref->{TCP}->dst."\n";
103 }
104  
105 if ($self->sp) {
106 $buf .= 'SP: '.$self->sp->print;
107 }
108  
109 my $sp = $self->sp;
110 if ($sp && length($sp->O) <= 9) {
111 $buf .= "\n> WARNING: not enough TCP options, results ".
112 "may be false";
113 }
114  
115 return $buf;
116 }
117  
118 sub print {
119 my $self = shift;
120  
121 my $global = $self->global;
122 my $log = $global->log;
123  
124 my $buf = $self->ipVersion;
125 if ($log->level > 2) {
126 $buf .= "[".$self->idSignatureP."]";
127 }
128 $buf .= ": [score:".$self->matchScore."]";
129 $buf .= ': '.$self->matchMask.
130 ': '.$self->systemClass.
131 ': '.$self->vendor.
132 ': '.$self->os.
133 ': '.$self->osVersion
134 ;
135  
136 my $buf2 = '';
137 for my $os ($self->osVersionChildrenList) {
138 $buf2 .= "$os, ";
139 }
140 $buf2 =~ s/, $//;
141 if (length($buf2)) {
142 $buf .= " ($buf2)";
143 }
144  
145 return $buf;
146 }
147  
148 1;
149  
150 __END__