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

filter: Statementstmt 0.0% 0 / 64 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 105 CC 7 SCAR 23.5
CC
7
Cov
0%
_rewriteTcpOptions
20.0
run
20.0
take
2.0
CRAP 10.5
1 #
2 # $Id: Passive.pm,v 008243d3e89a 2018/07/21 14:54:07 gomor $
3 #
4 package Net::SinFP3::Mode::Passive;
5 use strict;
6 use warnings;
7  
8 use base qw(Net::SinFP3::Mode);
9 our @AS = qw(
10 sp
11 flags
12 frame
13 _tcp
14 );
15 __PACKAGE__->cgBuildIndices;
16 __PACKAGE__->cgBuildAccessorsScalar(\@AS);
17  
18 use Net::SinFP3::Ext::SP;
19 use Net::SinFP3::Ext::TCP;
20  
21 use Net::Frame::Layer::TCP qw(:consts);
22  
23 sub take {
24 return [
25 'Net::SinFP3::Next::Frame',
26 'Net::SinFP3::Next::Passive',
27 ];
28 }
29  
30 sub new {
31 my $self = shift->SUPER::new(
32 sp => Net::SinFP3::Ext::SP->new,
33 @_,
34 );
35  
36 $self->_tcp(Net::SinFP3::Ext::TCP->new);
37  
38 return $self;
39 }
40  
41 # In passive mode, the P2 probe is not our own, so timestamp is not
42 # built as we want. We rewrite it to be able to match.
43 sub _rewriteTcpOptions {
44 my $self = shift;
45  
46 my $sp = $self->sp;
47 #print "[*] DEBUG: ".$sp->O."\n";
48 if ($sp->O =~ m/^(.*080a)(.{8})(.{8})(.*)/) {
49 my $head = $1;
50 my $a = $2;
51 my $b = $3;
52 my $tail = $4;
53 #print "[*] DEBUG: toks: 1[$1] 2[$2] 3[$3] 4[$4]\n";
54 # Some systems put timestamp values to 00. We keep it for
55 # fingerprint matching
56 if ($a !~ /00000000/ && $a !~ /44454144/) {
57 $a = "........";
58 }
59 if ($b !~ /00000000/ && $b !~ /44454144/) {
60 $b = "........";
61 }
62 $sp->O($head.$a.$b.$tail);
63 #print "[*] DEBUG: toks: 1[$head] a[$a] b[$b] 4[$tail]\n";
64 #print "[*] DEBUG: rewriteTcpOptions: [@{[$sp->O]}]\n";
65 }
66  
67 return 1;
68 }
69  
70 sub _getSPSignature {
71 my $self = shift;
72 my ($p) = @_;
73  
74 my $f = $self->_tcp->_analyzeTcpFlags($p);
75 my $w = $self->_tcp->_analyzeTcpWindow($p);
76 my $o = $self->_tcp->_analyzeTcpOptions($p);
77  
78 return Net::SinFP3::Ext::SP->new(
79 F => $f,
80 W => $w,
81 O => $o->[0],
82 M => $o->[1],
83 S => $o->[2],
84 L => $o->[3],
85 );
86 }
87  
88 sub run {
89 my $self = shift->SUPER::run(@_) or return;
90  
91 my $global = $self->global;
92 my $log = $global->log;
93 my $next = $global->next;
94  
95 my $ref = ref($next);
96 if ($ref =~ /^Net::SinFP3::Next::Frame$/) {
97 my $frame = $next->frame;
98 my $flags = $frame->ref->{TCP}->flags;
99 # We only finger SYN frames :) (0x02: SYN)
100 if ($flags != 0x02) {
101 # Do nothing with such frame
102 return;
103 }
104  
105 # XXX: off. Now we use a passive signature for SYN and active for SYN+ACK
106 # SYN will be handled by SignatureP table signatures
107 # SYN+ACK will be handled by Signature table signatures
108 #$self->_updateFrame($frame);
109  
110 # This is a hack to make it looks like in active mode
111 $frame->reply($frame);
112 $self->frame($frame->reply);
113  
114 $self->sp($self->_getSPSignature($frame));
115  
116 # Specific for passive mode
117 $self->_rewriteTcpOptions;
118 }
119 elsif ($ref =~ /^Net::SinFP3::Next::Passive$/) {
120 $self->sp($next->sp);
121 }
122 else {
123 $log->warning("Don't know what to do with this Next object: [$ref]");
124 return;
125 }
126  
127 return 1;
128 }
129  
130 1;
131  
132 __END__