line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Armadito::Agent::Antivirus::Kaspersky::Task::Scan; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
17069481
|
use strict; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
43
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
63
|
|
5
|
1
|
|
|
1
|
|
5
|
use base 'Armadito::Agent::Task::Scan'; |
|
1
|
|
|
|
|
29
|
|
|
1
|
|
|
|
|
473
|
|
6
|
1
|
|
|
1
|
|
4
|
use IPC::System::Simple qw(capture $EXITVAL EXIT_ANY); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
88
|
|
7
|
1
|
|
|
1
|
|
358
|
use Armadito::Agent::Patterns::Matcher; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
8
|
1
|
|
|
1
|
|
366
|
use Armadito::Agent::Task::Alerts; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
9
|
1
|
|
|
1
|
|
398
|
use Armadito::Agent::Tools::Time qw(computeDuration iso8601ToUnixTimestamp); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
445
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# 2016-11-30 16:04:36 C:\for_eric\75c1ae242d07bb738a5d9a9766c2a7de//data0000 detected Exploit.JS.Pdfka.flm |
12
|
|
|
|
|
|
|
# 2016-11-30 16:04:36 C:\for_eric\779cb6dc0055bdf63cbb2c9f9f3a95cc//data0000 suspicion HEUR:Exploit.Script.Generic |
13
|
|
|
|
|
|
|
# ; --- Statistics --- |
14
|
|
|
|
|
|
|
# ; Time Start: 2016-11-30 16:04:34 |
15
|
|
|
|
|
|
|
# ; Time Finish: 2016-11-30 16:04:37 |
16
|
|
|
|
|
|
|
# ; Processed objects: 131 |
17
|
|
|
|
|
|
|
# ; Total OK: 53 |
18
|
|
|
|
|
|
|
# ; Total detected: 57 |
19
|
|
|
|
|
|
|
# ; Suspicions: 21 |
20
|
|
|
|
|
|
|
# ; Total skipped: 0 |
21
|
|
|
|
|
|
|
# ; Password protected: 0 |
22
|
|
|
|
|
|
|
# ; Corrupted: 0 |
23
|
|
|
|
|
|
|
# ; Errors: 0 |
24
|
|
|
|
|
|
|
# ; ------------------ |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _parseScanOutput { |
27
|
0
|
|
|
0
|
|
|
my ( $self, $output ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $parser = Armadito::Agent::Patterns::Matcher->new( logger => $self->{logger} ); |
30
|
0
|
|
|
|
|
|
$parser->addPattern( 'start_time', '^; Time Start:\s+?(\d+.*)' ); |
31
|
0
|
|
|
|
|
|
$parser->addPattern( 'end_time', '^; Time Finish:\s+?(\d+.*)' ); |
32
|
0
|
|
|
|
|
|
$parser->addPattern( 'scanned_count', '^; Processed objects:\s+?(\d+)' ); |
33
|
0
|
|
|
|
|
|
$parser->addPattern( 'malware_count', '^; Total detected:\s+?(\d+)' ); |
34
|
0
|
|
|
|
|
|
$parser->addPattern( 'suspicious_count', '^; Suspicions:\s+?(\d+)' ); |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $labels = [ 'detection_time', 'filepath', 'name' ]; |
37
|
0
|
|
|
|
|
|
my $pattern = '^(\d{4,}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\s+(.*)\s+detected\s+([\w\.:]+)'; |
38
|
0
|
|
|
|
|
|
$parser->addPattern( 'alerts', $pattern, $labels ); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$pattern = '^(\d{4,}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\s+(.*)\s+suspicion\s+([\w\.:]+)'; |
41
|
0
|
|
|
|
|
|
$parser->addPattern( 'alerts', $pattern, $labels ); |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$parser->run( $output, '\n' ); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$parser->addHookForLabel( 'filepath', \&formatFilePath ); |
46
|
0
|
|
|
|
|
|
$parser->addHookForLabel( 'detection_time', \&LocalToTimestamp ); |
47
|
0
|
|
|
|
|
|
$parser->addHookForLabel( 'start_time', \&LocalToTimestamp ); |
48
|
0
|
|
|
|
|
|
$parser->addHookForLabel( 'end_time', \&LocalToTimestamp ); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return $parser->getResults(); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub formatFilePath { |
54
|
0
|
|
|
0
|
0
|
|
my ($match) = @_; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$match =~ s/\/\/data(\d{4})/\\\\data$1/ms; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return $match; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub LocalToTimestamp { |
62
|
0
|
|
|
0
|
0
|
|
my ($match) = @_; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return iso8601ToUnixTimestamp( $match, "Local" ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub run { |
68
|
0
|
|
|
0
|
1
|
|
my ( $self, %params ) = @_; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$self = $self->SUPER::run(%params); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $bin_path = $self->{agent}->{antivirus}->{scancli_path}; |
73
|
0
|
|
|
|
|
|
my $scan_path = $self->{job}->{obj}->{scan_path}; |
74
|
0
|
|
|
|
|
|
my $scan_options = $self->{job}->{obj}->{scan_options}; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $cmdline = "\"" . $bin_path . "\" SCAN \"" . $scan_path . "\" " . $scan_options; |
77
|
0
|
|
|
|
|
|
my $output = capture( EXIT_ANY, $cmdline ); |
78
|
0
|
|
|
|
|
|
$self->{logger}->info($output); |
79
|
0
|
|
|
|
|
|
$self->{logger}->info( "Program exited with " . $EXITVAL . "\n" ); |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $results = $self->_parseScanOutput($output); |
82
|
0
|
|
|
|
|
|
$results->{progress} = 100; |
83
|
0
|
|
|
|
|
|
$results->{job_id} = $self->{job}->{job_id}; |
84
|
|
|
|
|
|
|
$results->{duration} = computeDuration( |
85
|
|
|
|
|
|
|
start => $results->{start_time}[0], |
86
|
0
|
|
|
|
|
|
end => $results->{end_time}[0] |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $alert_task = Armadito::Agent::Task::Alerts->new( agent => $self->{agent} ); |
90
|
|
|
|
|
|
|
my $alert_jobj = { |
91
|
|
|
|
|
|
|
alerts => $results->{alerts}, |
92
|
|
|
|
|
|
|
job_id => $self->{job}->{job_id} |
93
|
0
|
|
|
|
|
|
}; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
delete( $results->{alerts} ); |
96
|
0
|
|
|
|
|
|
$self->sendScanResults($results); |
97
|
0
|
|
|
|
|
|
$alert_task->run(); |
98
|
0
|
|
|
|
|
|
$alert_task->_sendAlerts($alert_jobj); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 NAME |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Armadito::Agent::Antivirus::Kaspersky::Task::Scan - Scan Task for Kaspersky Antivirus. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 DESCRIPTION |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This task inherits from L<Armadito::Agent::Task:Scan>. Launch an Antivirus on-demand scan and then send a brief report in a json formatted POST request to Armadito plugin for GLPI. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 FUNCTIONS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 run ( $self, %params ) |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Run the task. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 new ( $self, %params ) |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Instanciate Task. |
122
|
|
|
|
|
|
|
|