| 1 | # | ||||||||||||
| 2 | # $Id: Discovery.pm,v 69a3d7308875 2023/04/05 15:11:02 gomor $ | ||||||||||||
| 3 | # | ||||||||||||
| 4 | package OPP::Proc::Discovery; | ||||||||||||
| 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(OPP::Proc); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | __PACKAGE__->cgBuildIndices; | ||||||||||||
| 10 | |||||||||||||
| 11 | 1 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 1 | ▶ | use Onyphe::Api; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 1 | ▶ | use File::Temp qw(tempfile); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | our $VERSION = '1.00'; | ||||||||||||
| 16 | |||||||||||||
| 17 | my $oa = Onyphe::Api->new->init or die("discovery: init failed"); | ||||||||||||
| 18 | $oa->silent(1); | ||||||||||||
| 19 | $oa->verbose(0); | ||||||||||||
| 20 | |||||||||||||
| 21 | # | ||||||||||||
| 22 | # NOTE: datascan category by default | ||||||||||||
| 23 | # | ||||||||||||
| 24 | # | discovery | ||||||||||||
| 25 | # | discovery category:vulnscan | ||||||||||||
| 26 | # | discovery category:datascan tag:open device.class:database | ||||||||||||
| 27 | # | ||||||||||||
| 28 | sub process { | ||||||||||||
| 29 | 0 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
process: not called CC=6 SCAR=37.4
| |||||||||||||
| 30 | 0 | my ($input) = @_; | |||||||||||
| 31 | |||||||||||||
| 32 | 0 | my $options = $self->options; | |||||||||||
| 33 | 0 | ▶ | my $category = $options->{category}[0] || 'datascan'; | ||||||||||
|
Condition0%0/2
$options->{'category'}[0] || 'datascan'
MC/DC0%0/1
$options->{'category'}[0] || 'datascan'
$options->{'category'}[0]
Truth table0%0/2
A
A= $options->{'category'}[0]
| |||||||||||||
| 34 | 0 | my $oql; | |||||||||||
| 35 | 0 | ▶ | if (defined($options->{args})) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 36 | 0 | $oql = $options->{args}; | |||||||||||
| 37 | 0 | $oql =~ s{category\s*:\s*(\S+)\s*}{}g; # Remove category if given | |||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | 0 | my ($fh, $filename) = tempfile(); | |||||||||||
| 41 | 0 | for my $field (keys %$input) { | |||||||||||
| 42 | 0 | my $value = $input->{$field}; | |||||||||||
| 43 | 0 | $value =~ s{"}{\\"}g; | |||||||||||
| 44 | 0 | my $print = "$field:\"$value\""; | |||||||||||
| 45 | 0 | ▶ | if (defined($oql)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | 0 | $print .= " $oql"; | |||||||||||
| 47 | } | ||||||||||||
| 48 | 0 | utf8::encode($print); | |||||||||||
| 49 | 0 | print $fh "$print\n"; | |||||||||||
| 50 | } | ||||||||||||
| 51 | 0 | close($fh); | |||||||||||
| 52 | |||||||||||||
| 53 | #print STDERR "tempfile [$filename]\n"; | ||||||||||||
| 54 | |||||||||||||
| 55 | my $cb = sub { | ||||||||||||
| 56 | 0 | ▶ | my ($results) = @_; | ||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||
| 57 | 0 | for (@$results) { | |||||||||||
| 58 | 0 | ▶ | next if m{.\@category.\s*:\s*.none.}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | 0 | my $docs = $self->from_json($_); | |||||||||||
| 60 | 0 | $docs = $self->flatten($docs); | |||||||||||
| 61 | 0 | $self->output->add($docs); | |||||||||||
| 62 | } | ||||||||||||
| 63 | 0 | }; | |||||||||||
| 64 | |||||||||||||
| 65 | 0 | $oa->bulk_discovery($category, $filename, undef, { trackquery => 'true' }, $cb); | |||||||||||
| 66 | |||||||||||||
| 67 | 0 | ▶ | unlink($filename) if -f $filename; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 68 | |||||||||||||
| 69 | 0 | return 1; | |||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | 1; | ||||||||||||
| 73 | |||||||||||||
| 74 | __END__ | ||||||||||||