| 1 | # | ||||||||||||||||||||||||||||
| 2 | # $Id: AddSignature.pm 22 2015-01-04 16:42:47Z gomor $ | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | package Net::SinFP3::Output::AddSignature; | ||||||||||||||||||||||||||||
| 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(Net::SinFP3::Output); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | our @AS = qw( | |||||||||||||||||||||||||||
| 10 | trusted | ||||||||||||||||||||||||||||
| 11 | ); | ||||||||||||||||||||||||||||
| 12 | 1 | __PACKAGE__->cgBuildIndices; | |||||||||||||||||||||||||||
| 13 | 1 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Net::SinFP3::Ext::DBI::Signature; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Net::SinFP3::Ext::DBI::IpVersion; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Net::SinFP3::Ext::DBI::SystemClass; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Net::SinFP3::Ext::DBI::Vendor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Net::SinFP3::Ext::DBI::Os; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use Net::SinFP3::Ext::DBI::OsVersion; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use Net::SinFP3::Ext::DBI::OsVersionFamily; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Net::SinFP3::Ext::DBI::OsVersionChildren; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use Net::SinFP3::Ext::DBI::PatternBinary; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use Net::SinFP3::Ext::DBI::PatternTcpFlags; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use Net::SinFP3::Ext::DBI::PatternTcpWindow; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use Net::SinFP3::Ext::DBI::PatternTcpOptions; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use Net::SinFP3::Ext::DBI::PatternTcpMss; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 1 | ▶ | use Net::SinFP3::Ext::DBI::PatternTcpWScale; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use Net::SinFP3::Ext::DBI::PatternTcpOLength; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # For easier access | ||||||||||||||||||||||||||||
| 34 | 1 | my $tIpVersion = 'Net::SinFP3::Ext::DBI::IpVersion'; | |||||||||||||||||||||||||||
| 35 | 1 | my $tPatternBinary = 'Net::SinFP3::Ext::DBI::PatternBinary'; | |||||||||||||||||||||||||||
| 36 | 1 | my $tPatternTcpFlags = 'Net::SinFP3::Ext::DBI::PatternTcpFlags'; | |||||||||||||||||||||||||||
| 37 | 1 | my $tPatternTcpWindow = 'Net::SinFP3::Ext::DBI::PatternTcpWindow'; | |||||||||||||||||||||||||||
| 38 | 1 | my $tPatternTcpOptions = 'Net::SinFP3::Ext::DBI::PatternTcpOptions'; | |||||||||||||||||||||||||||
| 39 | 1 | my $tPatternTcpMss = 'Net::SinFP3::Ext::DBI::PatternTcpMss'; | |||||||||||||||||||||||||||
| 40 | 1 | my $tPatternTcpWScale = 'Net::SinFP3::Ext::DBI::PatternTcpWScale'; | |||||||||||||||||||||||||||
| 41 | 1 | my $tPatternTcpOLength = 'Net::SinFP3::Ext::DBI::PatternTcpOLength'; | |||||||||||||||||||||||||||
| 42 | 1 | my $tSystemClass = 'Net::SinFP3::Ext::DBI::SystemClass'; | |||||||||||||||||||||||||||
| 43 | 1 | my $tVendor = 'Net::SinFP3::Ext::DBI::Vendor'; | |||||||||||||||||||||||||||
| 44 | 1 | my $tOs = 'Net::SinFP3::Ext::DBI::Os'; | |||||||||||||||||||||||||||
| 45 | 1 | my $tOsVersion = 'Net::SinFP3::Ext::DBI::OsVersion'; | |||||||||||||||||||||||||||
| 46 | 1 | my $tOsVersionFamily = 'Net::SinFP3::Ext::DBI::OsVersionFamily'; | |||||||||||||||||||||||||||
| 47 | 1 | my $tOsVersionChildren = 'Net::SinFP3::Ext::DBI::OsVersionChildren'; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 0 | my $self = shift->SUPER::new( | |||||||||||||||||||||||||||
| 51 | trusted => 0, | ||||||||||||||||||||||||||||
| 52 | @_, | ||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | return $self; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=19 SCAR=59.4
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my $self = shift->SUPER::run(@_) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | my $global = $self->global; | |||||||||||||||||||||||||||
| 62 | 0 | my $log = $global->log; | |||||||||||||||||||||||||||
| 63 | 0 | my @results = $global->result; | |||||||||||||||||||||||||||
| 64 | 0 | my $db = $global->db; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | my $r = $results[0]; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if (ref($r) =~ /^Net::SinFP3::Result::PortError$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | $log->error("We cannot add a signature for a port in error"); | |||||||||||||||||||||||||||
| 70 | 0 | return; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | my $buf = ''; | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | $buf .= 'P1: '.$r->s1->print."\n" if $r->s1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $buf .= 'P2: '.$r->s2->print."\n" if $r->s2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | $buf .= 'P3: '.$r->s3->print."\n" if $r->s3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | $buf .= "[+] Results for target: [".$r->ip."]:".$r->port."\n"; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if (ref($r) =~ /^Net::SinFP3::Result::Unknown$/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 81 | 0 | $buf .= $r->print; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | elsif (ref($r) =~ /^Net::SinFP3::Result::Active$/) { | ||||||||||||||||||||||||||||
| 84 | 0 | for my $r (@results) { | |||||||||||||||||||||||||||
| 85 | 0 | $buf .= $r->print."\n"; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||||||||||
| 89 | 0 | $log->error("Don't know what to do with this result object [". | |||||||||||||||||||||||||||
| 90 | ref($r)."]"); | ||||||||||||||||||||||||||||
| 91 | 0 | return; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | my $s2 = $r->s2; | |||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($s2 && length($s2->O) <= 9) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$s2 and length $s2->O <= 9
MC/DC0%0/2
$s2 and length $s2->O <= 9
$s2
length $s2->O <= 9
Truth table0%0/3
A and B
A= $s2B= length $s2->O <= 9
| |||||||||||||||||||||||||||||
| 96 | 0 | $buf .= '[!] WARNING: not enough TCP options for P2 reply, '. | |||||||||||||||||||||||||||
| 97 | 'result may be false'."\n"; | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | print $buf."\n"; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # Disconnect, give access to this process, it is not using | ||||||||||||||||||||||||||||
| 103 | # the same Perl interface to SQLite | ||||||||||||||||||||||||||||
| 104 | 0 | $db->post; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | my $dbh = Net::SinFP3::Ext::DBI->connection( | |||||||||||||||||||||||||||
| 107 | "dbi:SQLite:dbname=".$db->file, | ||||||||||||||||||||||||||||
| 108 | '', | ||||||||||||||||||||||||||||
| 109 | '', | ||||||||||||||||||||||||||||
| 110 | { AutoCommit => 0 }, | ||||||||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | my $p1 = $r->s1->print; | |||||||||||||||||||||||||||
| 114 | 0 | my $p2 = $r->s2->print; | |||||||||||||||||||||||||||
| 115 | 0 | my $p3 = $r->s3->print; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | my @patternsP1 = (split('\s+', $p1))[0..6]; | |||||||||||||||||||||||||||
| 118 | 0 | my @patternsP2 = (split('\s+', $p2))[0..6]; | |||||||||||||||||||||||||||
| 119 | 0 | my @patternsP3 = (split('\s+', $p3))[0..6]; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | # Get possible option if a match is similar to this new signature | ||||||||||||||||||||||||||||
| 122 | 0 | my %systemClassList = (); | |||||||||||||||||||||||||||
| 123 | 0 | my %vendorList = (); | |||||||||||||||||||||||||||
| 124 | 0 | my %osList = (); | |||||||||||||||||||||||||||
| 125 | 0 | my %osVersionList = (); | |||||||||||||||||||||||||||
| 126 | 0 | my %osVersionFamilyList = (); | |||||||||||||||||||||||||||
| 127 | 0 | my $addOsVersionChildren = 0; | |||||||||||||||||||||||||||
| 128 | 0 | for my $o (@results) { | |||||||||||||||||||||||||||
| 129 | 0 | ▶ | if ($o->matchType eq "S1S2S3" && $o->matchMask eq "BH0FH0WH0OH0MH0SH0LH0") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$o->matchType eq "S1S2S3" and $o->matchMask eq "BH0FH0WH0OH0MH0SH0LH0"
MC/DC0%0/2
$o->matchType eq "S1S2S3" and $o->matchMask eq "BH0FH0WH0OH0MH0SH0LH0"
$o->matchType eq "S1S2S3"
$o->matchMask eq "BH0FH0WH0OH0MH0SH0LH0"
Truth table0%0/3
A and B
A= $o->matchType eq "S1S2S3"B= $o->matchMask eq "BH0FH0WH0OH0MH0SH0LH0"
| |||||||||||||||||||||||||||||
| 130 | 0 | print "[-] A HEURISTIC0 match was found, you may want to add an ". | |||||||||||||||||||||||||||
| 131 | "OsVersionChildren instead.\n"; | ||||||||||||||||||||||||||||
| 132 | 0 | ▶ | _addOsVersionChildren($o) && $addOsVersionChildren++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 0 | $systemClassList {$o->systemClass}++; | |||||||||||||||||||||||||||
| 135 | 0 | $vendorList {$o->vendor}++; | |||||||||||||||||||||||||||
| 136 | 0 | $osList {$o->os}++; | |||||||||||||||||||||||||||
| 137 | 0 | $osVersionList {$o->osVersion}++; | |||||||||||||||||||||||||||
| 138 | 0 | $osVersionFamilyList{$o->osVersionFamily}++; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | # We only wanted to add osVersionChildren | ||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ($addOsVersionChildren) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 0 | return 1; | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | 0 | print "[+] POSSIBLE systemClass : [", join(' ', keys %systemClassList), "]\n"; | |||||||||||||||||||||||||||
| 145 | 0 | print "[+] POSSIBLE vendor : [", join(' ', keys %vendorList), "]\n"; | |||||||||||||||||||||||||||
| 146 | 0 | print "[+] POSSIBLE os : [", join(' ', keys %osList), "]\n"; | |||||||||||||||||||||||||||
| 147 | 0 | print "[+] POSSIBLE osVersion : [", join(' ', keys %osVersionList), "]\n"; | |||||||||||||||||||||||||||
| 148 | 0 | print "[+] POSSIBLE osVersionFamily: [", join(' ', keys %osVersionFamilyList), "]\n"; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | # Add new possible patterns | ||||||||||||||||||||||||||||
| 151 | 0 | for my $p (\@patternsP1, \@patternsP2, \@patternsP3) { | |||||||||||||||||||||||||||
| 152 | 0 | _addNewPatternBinary ({ patternBinaryHeuristic0 => $p->[0] }); | |||||||||||||||||||||||||||
| 153 | 0 | _addNewPatternTcpFlags ({ patternTcpFlagsHeuristic0 => $p->[1] }); | |||||||||||||||||||||||||||
| 154 | 0 | _addNewPatternTcpWindow ({ patternTcpWindowHeuristic0 => $p->[2] }); | |||||||||||||||||||||||||||
| 155 | 0 | _addNewPatternTcpOptions({ patternTcpOptionsHeuristic0 => $p->[3] }); | |||||||||||||||||||||||||||
| 156 | 0 | _addNewPatternTcpMss ({ patternTcpMssHeuristic0 => $p->[4] }); | |||||||||||||||||||||||||||
| 157 | 0 | _addNewPatternTcpWScale ({ patternTcpWScaleHeuristic0 => $p->[5] }); | |||||||||||||||||||||||||||
| 158 | 0 | _addNewPatternTcpOLength({ patternTcpOLengthHeuristic0 => $p->[6] }); | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | # Get input from user | ||||||||||||||||||||||||||||
| 162 | 0 | my $systemClass = _getSystemClass(); | |||||||||||||||||||||||||||
| 163 | 0 | my $vendor = _getVendor(); | |||||||||||||||||||||||||||
| 164 | 0 | my $os = _getOs(); | |||||||||||||||||||||||||||
| 165 | 0 | my $osVersion = _getOsVersion(); | |||||||||||||||||||||||||||
| 166 | 0 | my $osVersionFamily = _getOsVersionFamily(); | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | # Add new possible elements | ||||||||||||||||||||||||||||
| 169 | 0 | my $nSystemClass = _addNewElementSystemClass ({ systemClass => $systemClass }); | |||||||||||||||||||||||||||
| 170 | 0 | my $nVendor = _addNewElementVendor ({ vendor => $vendor }); | |||||||||||||||||||||||||||
| 171 | 0 | my $nOs = _addNewElementOs ({ os => $os }); | |||||||||||||||||||||||||||
| 172 | 0 | my $nOsVersion = _addNewElementOsVersion ({ osVersion => $osVersion }); | |||||||||||||||||||||||||||
| 173 | 0 | my $nOsVersionFamily = _addNewElementOsVersionFamily({ osVersionFamily => $osVersionFamily }); | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | # Get stored IDs | ||||||||||||||||||||||||||||
| 176 | 0 | my ($idBinaryP1, $idTcpFlagsP1, $idTcpWindowP1, $idTcpOptionsP1, | |||||||||||||||||||||||||||
| 177 | $idTcpMssP1, $idTcpWScaleP1, $idTcpOLengthP1) = | ||||||||||||||||||||||||||||
| 178 | _selectPatterns(\@patternsP1); | ||||||||||||||||||||||||||||
| 179 | 0 | my ($idBinaryP2, $idTcpFlagsP2, $idTcpWindowP2, $idTcpOptionsP2, | |||||||||||||||||||||||||||
| 180 | $idTcpMssP2, $idTcpWScaleP2, $idTcpOLengthP2) = | ||||||||||||||||||||||||||||
| 181 | _selectPatterns(\@patternsP2); | ||||||||||||||||||||||||||||
| 182 | 0 | my ($idBinaryP3, $idTcpFlagsP3, $idTcpWindowP3, $idTcpOptionsP3, | |||||||||||||||||||||||||||
| 183 | $idTcpMssP3, $idTcpWScaleP3, $idTcpOLengthP3) = | ||||||||||||||||||||||||||||
| 184 | _selectPatterns(\@patternsP3); | ||||||||||||||||||||||||||||
| 185 | 0 | ▶ | my @idIpVersion = $tIpVersion->search( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | ipVersion => $self->global->ipv6 ? 'IPv6' : 'IPv4', | ||||||||||||||||||||||||||||
| 187 | ); | ||||||||||||||||||||||||||||
| 188 | 0 | my $idIpVersion = $idIpVersion[0]->idIpVersion; | |||||||||||||||||||||||||||
| 189 | 0 | my $idSystemClass = $nSystemClass->idSystemClass; | |||||||||||||||||||||||||||
| 190 | 0 | my $idVendor = $nVendor->idVendor; | |||||||||||||||||||||||||||
| 191 | 0 | my $idOs = $nOs->idOs; | |||||||||||||||||||||||||||
| 192 | 0 | my $idOsVersion = $nOsVersion->idOsVersion; | |||||||||||||||||||||||||||
| 193 | 0 | my $idOsVersionFamily = $nOsVersionFamily->idOsVersionFamily; | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | # Add the signature | ||||||||||||||||||||||||||||
| 196 | 0 | ▶ | my $sig = Net::SinFP3::Ext::DBI::Signature->insert({ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | idIpVersion => $idIpVersion, | ||||||||||||||||||||||||||||
| 198 | trusted => $self->trusted ? 1 : 0, | ||||||||||||||||||||||||||||
| 199 | idSystemClass => $idSystemClass, | ||||||||||||||||||||||||||||
| 200 | idVendor => $idVendor, | ||||||||||||||||||||||||||||
| 201 | idOs => $idOs, | ||||||||||||||||||||||||||||
| 202 | idOsVersion => $idOsVersion, | ||||||||||||||||||||||||||||
| 203 | idOsVersionFamily => $idOsVersionFamily, | ||||||||||||||||||||||||||||
| 204 | idS1PatternBinary => $idBinaryP1, | ||||||||||||||||||||||||||||
| 205 | idS1PatternTcpFlags => $idTcpFlagsP1, | ||||||||||||||||||||||||||||
| 206 | idS1PatternTcpWindow => $idTcpWindowP1, | ||||||||||||||||||||||||||||
| 207 | idS1PatternTcpOptions => $idTcpOptionsP1, | ||||||||||||||||||||||||||||
| 208 | idS1PatternTcpMss => $idTcpMssP1, | ||||||||||||||||||||||||||||
| 209 | idS1PatternTcpWScale => $idTcpWScaleP1, | ||||||||||||||||||||||||||||
| 210 | idS1PatternTcpOLength => $idTcpOLengthP1, | ||||||||||||||||||||||||||||
| 211 | idS2PatternBinary => $idBinaryP2, | ||||||||||||||||||||||||||||
| 212 | idS2PatternTcpFlags => $idTcpFlagsP2, | ||||||||||||||||||||||||||||
| 213 | idS2PatternTcpWindow => $idTcpWindowP2, | ||||||||||||||||||||||||||||
| 214 | idS2PatternTcpOptions => $idTcpOptionsP2, | ||||||||||||||||||||||||||||
| 215 | idS2PatternTcpMss => $idTcpMssP2, | ||||||||||||||||||||||||||||
| 216 | idS2PatternTcpWScale => $idTcpWScaleP2, | ||||||||||||||||||||||||||||
| 217 | idS2PatternTcpOLength => $idTcpOLengthP2, | ||||||||||||||||||||||||||||
| 218 | idS3PatternBinary => $idBinaryP3, | ||||||||||||||||||||||||||||
| 219 | idS3PatternTcpFlags => $idTcpFlagsP3, | ||||||||||||||||||||||||||||
| 220 | idS3PatternTcpWindow => $idTcpWindowP3, | ||||||||||||||||||||||||||||
| 221 | idS3PatternTcpOptions => $idTcpOptionsP3, | ||||||||||||||||||||||||||||
| 222 | idS3PatternTcpMss => $idTcpMssP3, | ||||||||||||||||||||||||||||
| 223 | idS3PatternTcpWScale => $idTcpWScaleP3, | ||||||||||||||||||||||||||||
| 224 | idS3PatternTcpOLength => $idTcpOLengthP3, | ||||||||||||||||||||||||||||
| 225 | }); | ||||||||||||||||||||||||||||
| 226 | 0 | $sig->update; | |||||||||||||||||||||||||||
| 227 | 0 | $sig->dbi_commit; | |||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 0 | return 1; | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 0 | ▶ | sub __getInput { | ||||||||||||||||||||||||||
|
Subroutine
__getInput: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 233 | 0 | my ($type) = @_; | |||||||||||||||||||||||||||
| 234 | 0 | print "Enter $type:\n"; | |||||||||||||||||||||||||||
| 235 | 0 | my $value; | |||||||||||||||||||||||||||
| 236 | 0 | ▶ | while (<>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | 0 | chomp; | |||||||||||||||||||||||||||
| 238 | 0 | $value .= $_; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | 0 | ▶ | die("No $type entered") unless $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | 0 | return $value; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | 0 | ▶ | sub _getSystemClass { __getInput('systemClass') } | ||||||||||||||||||||||||||
|
Subroutine
_getSystemClass: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 244 | 0 | ▶ | sub _getVendor { __getInput('vendor') } | ||||||||||||||||||||||||||
|
Subroutine
_getVendor: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 245 | 0 | ▶ | sub _getOs { __getInput('os') } | ||||||||||||||||||||||||||
|
Subroutine
_getOs: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 246 | 0 | ▶ | sub _getOsVersion { __getInput('osVersion') } | ||||||||||||||||||||||||||
|
Subroutine
_getOsVersion: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 247 | 0 | ▶ | sub _getOsVersionFamily { __getInput('osVersionFamily') } | ||||||||||||||||||||||||||
|
Subroutine
_getOsVersionFamily: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 248 | 0 | ▶ | sub _getOsVersionChildren { | ||||||||||||||||||||||||||
|
Subroutine
_getOsVersionChildren: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 249 | 0 | my $list = __getInput('osVersionChildren (comma speparated list)'); | |||||||||||||||||||||||||||
| 250 | 0 | my @osVersionChildrenList = split('\s*,\s*', $list); | |||||||||||||||||||||||||||
| 251 | 0 | return \@osVersionChildrenList; | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 0 | ▶ | sub _selectPatterns { | ||||||||||||||||||||||||||
|
Subroutine
_selectPatterns: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 255 | 0 | my ($p) = @_; | |||||||||||||||||||||||||||
| 256 | 0 | my @idPatternBinary = $tPatternBinary->search (patternBinaryHeuristic0 => $p->[0]); | |||||||||||||||||||||||||||
| 257 | 0 | my @idPatternTcpFlags = $tPatternTcpFlags->search (patternTcpFlagsHeuristic0 => $p->[1]); | |||||||||||||||||||||||||||
| 258 | 0 | my @idPatternTcpWindow = $tPatternTcpWindow->search (patternTcpWindowHeuristic0 => $p->[2]); | |||||||||||||||||||||||||||
| 259 | 0 | my @idPatternTcpOptions = $tPatternTcpOptions->search(patternTcpOptionsHeuristic0 => $p->[3]); | |||||||||||||||||||||||||||
| 260 | 0 | my @idPatternTcpMss = $tPatternTcpMss->search (patternTcpMssHeuristic0 => $p->[4]); | |||||||||||||||||||||||||||
| 261 | 0 | my @idPatternTcpWScale = $tPatternTcpWScale->search (patternTcpWScaleHeuristic0 => $p->[5]); | |||||||||||||||||||||||||||
| 262 | 0 | my @idPatternTcpOLength = $tPatternTcpOLength->search(patternTcpOLengthHeuristic0 => $p->[6]); | |||||||||||||||||||||||||||
| 263 | return ( | ||||||||||||||||||||||||||||
| 264 | 0 | $idPatternBinary[0]->idPatternBinary, | |||||||||||||||||||||||||||
| 265 | $idPatternTcpFlags[0]->idPatternTcpFlags, | ||||||||||||||||||||||||||||
| 266 | $idPatternTcpWindow[0]->idPatternTcpWindow, | ||||||||||||||||||||||||||||
| 267 | $idPatternTcpOptions[0]->idPatternTcpOptions, | ||||||||||||||||||||||||||||
| 268 | $idPatternTcpMss[0]->idPatternTcpMss, | ||||||||||||||||||||||||||||
| 269 | $idPatternTcpWScale[0]->idPatternTcpWScale, | ||||||||||||||||||||||||||||
| 270 | $idPatternTcpOLength[0]->idPatternTcpOLength, | ||||||||||||||||||||||||||||
| 271 | ); | ||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 0 | ▶ | sub __addNewPattern { | ||||||||||||||||||||||||||
|
Subroutine
__addNewPattern: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 275 | 0 | my ($table, $element) = @_; | |||||||||||||||||||||||||||
| 276 | 0 | my @search = $table->search(%$element); | |||||||||||||||||||||||||||
| 277 | 0 | ▶ | if (@search < 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 278 | 0 | my @values = keys %$element; | |||||||||||||||||||||||||||
| 279 | 0 | my $key = $values[0]; # We fetch the first and only one key | |||||||||||||||||||||||||||
| 280 | 0 | my $value = $element->{$key}; # We fetch first key value | |||||||||||||||||||||||||||
| 281 | 0 | (my $field = $key) =~ s/Heuristic0$//; | |||||||||||||||||||||||||||
| 282 | 0 | print "[+] New pattern: [$value] for field [$field]\n"; | |||||||||||||||||||||||||||
| 283 | 0 | print "Enter heuristic1 value (enter CTRL+D on a new line when done):\n"; | |||||||||||||||||||||||||||
| 284 | 0 | my $h1; | |||||||||||||||||||||||||||
| 285 | 0 | ▶ | while (<>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 286 | 0 | chomp; | |||||||||||||||||||||||||||
| 287 | 0 | $h1 .= $_; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | 0 | print "Enter heuristic2 value (enter CTRL+D on a new line when done):\n"; | |||||||||||||||||||||||||||
| 290 | 0 | my $h2; | |||||||||||||||||||||||||||
| 291 | 0 | ▶ | while (<>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | 0 | chomp; | |||||||||||||||||||||||||||
| 293 | 0 | $h2 .= $_; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | 0 | ▶ | $h1 = $value unless $h1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | 0 | ▶ | $h2 = $value unless $h2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 297 | 0 | return __addNewElement($table, { | |||||||||||||||||||||||||||
| 298 | $field.'Heuristic0' => $value, | ||||||||||||||||||||||||||||
| 299 | $field.'Heuristic1' => $h1, | ||||||||||||||||||||||||||||
| 300 | $field.'Heuristic2' => $h2, | ||||||||||||||||||||||||||||
| 301 | }); | ||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | 0 | return $search[0]; | |||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 0 | ▶ | sub _addNewPatternBinary { __addNewPattern($tPatternBinary, @_) } | ||||||||||||||||||||||||||
|
Subroutine
_addNewPatternBinary: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 307 | 0 | ▶ | sub _addNewPatternTcpFlags { __addNewPattern($tPatternTcpFlags, @_) } | ||||||||||||||||||||||||||
|
Subroutine
_addNewPatternTcpFlags: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 308 | 0 | ▶ | sub _addNewPatternTcpWindow { __addNewPattern($tPatternTcpWindow, @_) } | ||||||||||||||||||||||||||
|
Subroutine
_addNewPatternTcpWindow: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 309 | 0 | ▶ | sub _addNewPatternTcpOptions { __addNewPattern($tPatternTcpOptions, @_) } | ||||||||||||||||||||||||||
|
Subroutine
_addNewPatternTcpOptions: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 310 | 0 | ▶ | sub _addNewPatternTcpMss { __addNewPattern($tPatternTcpMss, @_) } | ||||||||||||||||||||||||||
|
Subroutine
_addNewPatternTcpMss: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 311 | 0 | ▶ | sub _addNewPatternTcpWScale { __addNewPattern($tPatternTcpWScale, @_) } | ||||||||||||||||||||||||||
|
Subroutine
_addNewPatternTcpWScale: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 312 | 0 | ▶ | sub _addNewPatternTcpOLength { __addNewPattern($tPatternTcpOLength, @_) } | ||||||||||||||||||||||||||
|
Subroutine
_addNewPatternTcpOLength: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 0 | ▶ | sub __addNewElement { | ||||||||||||||||||||||||||
|
Subroutine
__addNewElement: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 315 | 0 | my ($table, $element) = @_; | |||||||||||||||||||||||||||
| 316 | 0 | my @search = $table->search(%$element); | |||||||||||||||||||||||||||
| 317 | 0 | ▶ | if (@search < 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | 0 | my $new = $table->insert($element); | |||||||||||||||||||||||||||
| 319 | 0 | $new->update; | |||||||||||||||||||||||||||
| 320 | 0 | print "[+] Added new element: ",Dumper($element),"\n"; | |||||||||||||||||||||||||||
| 321 | 0 | return $new; | |||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | 0 | return $search[0]; | |||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||
| 325 | 0 | ▶ | sub _addNewElementSystemClass { __addNewElement($tSystemClass, @_) } | ||||||||||||||||||||||||||
|
Subroutine
_addNewElementSystemClass: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 326 | 0 | ▶ | sub _addNewElementVendor { __addNewElement($tVendor, @_) } | ||||||||||||||||||||||||||
|
Subroutine
_addNewElementVendor: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 327 | 0 | ▶ | sub _addNewElementOs { __addNewElement($tOs, @_) } | ||||||||||||||||||||||||||
|
Subroutine
_addNewElementOs: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 328 | 0 | ▶ | sub _addNewElementOsVersion { __addNewElement($tOsVersion, @_) } | ||||||||||||||||||||||||||
|
Subroutine
_addNewElementOsVersion: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 329 | 0 | ▶ | sub _addNewElementOsVersionFamily { __addNewElement($tOsVersionFamily, @_) } | ||||||||||||||||||||||||||
|
Subroutine
_addNewElementOsVersionFamily: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 330 | 0 | ▶ | sub _addNewElementOsVersionChildren { __addNewElement($tOsVersionChildren, @_) } | ||||||||||||||||||||||||||
|
Subroutine
_addNewElementOsVersionChildren: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 0 | ▶ | sub _addOsVersionChildren { | ||||||||||||||||||||||||||
|
Subroutine
_addOsVersionChildren: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 333 | 0 | my ($result) = @_; | |||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 0 | my $idSignature = $result->idSignature; | |||||||||||||||||||||||||||
| 336 | 0 | print "Would you like to add OsVersionChildren for this one? (CTRL+D for not)\n". | |||||||||||||||||||||||||||
| 337 | "=> [", $result->os, " ", $result->osVersion, "]\n"; | ||||||||||||||||||||||||||||
| 338 | 0 | my $input = ''; | |||||||||||||||||||||||||||
| 339 | 0 | ▶ | while (<>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | 0 | chomp; | |||||||||||||||||||||||||||
| 341 | 0 | $input .= $_; | |||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | 0 | ▶ | return unless $input; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 0 | my $osVersionChildrenList = _getOsVersionChildren(); | |||||||||||||||||||||||||||
| 346 | 0 | my @idOsVersionList = (); | |||||||||||||||||||||||||||
| 347 | 0 | for my $o (@$osVersionChildrenList) { | |||||||||||||||||||||||||||
| 348 | 0 | my $new = _addNewElementOsVersion({ osVersion => $o }); | |||||||||||||||||||||||||||
| 349 | 0 | push @idOsVersionList, $new->idOsVersion; | |||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | 0 | for my $o (@idOsVersionList) { | |||||||||||||||||||||||||||
| 352 | 0 | _addNewElementOsVersionChildren({ | |||||||||||||||||||||||||||
| 353 | idSignature => $idSignature, | ||||||||||||||||||||||||||||
| 354 | idOsVersion => $o, | ||||||||||||||||||||||||||||
| 355 | }); | ||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||
| 357 | 0 | $tOsVersionChildren->dbi_commit; | |||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 0 | return 1; | |||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | 1 | 1; | |||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | __END__ | ||||||||||||||||||||||||||||