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