| 1 | # | ||
| 2 | # $Id: Active.pm,v 008243d3e89a 2018/07/21 14:54:07 gomor $ | ||
| 3 | # | ||
| 4 | package Net::SinFP3::Result::Active; | ||
| 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 | s1 | ||
| 17 | s2 | ||
| 18 | s3 | ||
| 19 | |||
| 20 | trusted | ||
| 21 | idSignature | ||
| 22 | ipVersion | ||
| 23 | systemClass | ||
| 24 | vendor | ||
| 25 | os | ||
| 26 | osVersion | ||
| 27 | osVersionFamily | ||
| 28 | matchType | ||
| 29 | matchMask | ||
| 30 | matchScore | ||
| 31 | ); | ||
| 32 | our @AA = qw( | ||
| 33 | osVersionChildrenList | ||
| 34 | ); | ||
| 35 | __PACKAGE__->cgBuildIndices; | ||
| 36 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | ||
| 37 | __PACKAGE__->cgBuildAccessorsArray (\@AA); | ||
| 38 | |||
| 39 | use Net::SinFP3::Ext::S; | ||
| 40 | |||
| 41 | sub take { | ||
| 42 | return [ | ||
| 43 | 'Net::SinFP3::Search::Active', | ||
| 44 | ]; | ||
| 45 | } | ||
| 46 | |||
| 47 | sub new { | ||
| 48 | my $self = shift->SUPER::new( | ||
| 49 | ip => '127.0.0.1', | ||
| 50 | port => '1', | ||
| 51 | hostname => 'unknown', | ||
| 52 | reverse => 'unknown', | ||
| 53 | osVersionChildrenList => [], | ||
| 54 | @_, | ||
| 55 | ); | ||
| 56 | |||
| 57 | return $self; | ||
| 58 | } | ||
| 59 | |||
| 60 | sub getPossibleOsList { | ||
| 61 | my $self = shift; | ||
| 62 | my ($resultList) = @_; | ||
| 63 | |||
| 64 | my %os = (); | ||
| 65 | for my $r (@$resultList) { | ||
| 66 | $os{$r->os}++; | ||
| 67 | } | ||
| 68 | |||
| 69 | my @osList = (); | ||
| 70 | if (keys %os > 0) { | ||
| 71 | @osList = map { $_ } keys %os; | ||
| 72 | } | ||
| 73 | |||
| 74 | return \@osList; | ||
| 75 | } | ||
| 76 | |||
| 77 | sub updateMatchScore { | ||
| 78 | my $self = shift; | ||
| 79 | my $score = { | ||
| 80 | 'OH1' => 18, | ||
| 81 | 'WH1' => 10, | ||
| 82 | 'BH1' => 6, | ||
| 83 | 'SH1' => 6, | ||
| 84 | 'FH1' => 4, | ||
| 85 | 'MH1' => 4, | ||
| 86 | 'LH1' => 4, | ||
| 87 | |||
| 88 | 'OH0' => 37, | ||
| 89 | 'WH0' => 21, | ||
| 90 | 'BH0' => 12, | ||
| 91 | 'SH0' => 12, | ||
| 92 | 'FH0' => 6, | ||
| 93 | 'MH0' => 6, | ||
| 94 | 'LH0' => 6, | ||
| 95 | |||
| 96 | 'BH2' => 0, | ||
| 97 | 'FH2' => 0, | ||
| 98 | 'WH2' => 0, | ||
| 99 | 'OH2' => 0, | ||
| 100 | 'MH2' => 0, | ||
| 101 | 'SH2' => 0, | ||
| 102 | 'LH2' => 0, | ||
| 103 | }; | ||
| 104 | my $matchMask = $self->matchMask; | ||
| 105 | my @toks = $matchMask =~ /(BH.)(FH.)(WH.)(OH.)(MH.)(SH.)(LH.)/; | ||
| 106 | my $result = 0; | ||
| 107 | for (@toks) { | ||
| 108 | $result += $score->{$_}; | ||
| 109 | } | ||
| 110 | return $self->matchScore($result); | ||
| 111 | } | ||
| 112 | |||
| 113 | sub printSignature { | ||
| 114 | my $self = shift; | ||
| 115 | |||
| 116 | my $global = $self->global; | ||
| 117 | my $log = $global->log; | ||
| 118 | |||
| 119 | my $buf = ''; | ||
| 120 | $buf .= "Result for target [".$self->ip."]:".$self->port.":"; | ||
| 121 | $buf .= "\nS1: ".$self->s1->print if $self->s1; | ||
| 122 | $buf .= "\nS2: ".$self->s2->print if $self->s2; | ||
| 123 | $buf .= "\nS3: ".$self->s3->print if $self->s3; | ||
| 124 | |||
| 125 | if ($self->s2) { | ||
| 126 | my $s2 = $self->s2; | ||
| 127 | if ($s2 && length($s2->O) <= 9) { | ||
| 128 | $buf .= "\n> WARNING: not enough TCP options for P2 reply, results ". | ||
| 129 | "may be false"; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | return $buf; | ||
| 134 | } | ||
| 135 | |||
| 136 | sub print { | ||
| 137 | my $self = shift; | ||
| 138 | |||
| 139 | my $global = $self->global; | ||
| 140 | my $log = $global->log; | ||
| 141 | |||
| 142 | my $buf = $self->ipVersion; | ||
| 143 | if ($log->level > 2) { | ||
| 144 | $buf .= "[".$self->idSignature."]"; | ||
| 145 | } | ||
| 146 | $buf .= ": [score:".$self->matchScore."]"; | ||
| 147 | $buf .= ': '.$self->matchMask.'/'.$self->matchType. | ||
| 148 | ': '.$self->systemClass. | ||
| 149 | ': '.$self->vendor. | ||
| 150 | ': '.$self->os. | ||
| 151 | ': '.$self->osVersion | ||
| 152 | ; | ||
| 153 | |||
| 154 | my $buf2 = ''; | ||
| 155 | for my $os ($self->osVersionChildrenList) { | ||
| 156 | $buf2 .= "$os, "; | ||
| 157 | } | ||
| 158 | $buf2 =~ s/, $//; | ||
| 159 | if (length($buf2)) { | ||
| 160 | $buf .= " ($buf2)"; | ||
| 161 | } | ||
| 162 | |||
| 163 | return $buf; | ||
| 164 | } | ||
| 165 | |||
| 166 | 1; | ||
| 167 | |||
| 168 | __END__ |