| 1 |
#!perl -w |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
aveclient |
| 6 |
|
| 7 |
=head1 DESCRIPTION |
| 8 |
|
| 9 |
This qpsmtpd plugin uses the aveclient of a kaspersky 5.x server-suite. The original kaspersky |
| 10 |
aveclient is called within this plugin to connect to the local socket of the aveserver. |
| 11 |
The aveserver runs as a daemon with all virusdefinitions already loaded, what makes scanning veeery |
| 12 |
quick and performant without much load. |
| 13 |
|
| 14 |
When a virus is detected, the mail is blocked and the connection is denied! Further configuration |
| 15 |
is simple to be added. |
| 16 |
|
| 17 |
=head1 INSTALL AND CONFIG |
| 18 |
|
| 19 |
Place this plugin in the default plugin directory of your qpsmtpd installation. Normaly you can use |
| 20 |
it with default options (nothing specified): |
| 21 |
|
| 22 |
=over 4 |
| 23 |
|
| 24 |
=item B<aveclient> |
| 25 |
|
| 26 |
Optional you may set the path to original aveclient and/or the socket: |
| 27 |
|
| 28 |
=over 4 |
| 29 |
|
| 30 |
=item avclient_bin I</path/to/ave/binary> |
| 31 |
|
| 32 |
Set the path to the original aveclient of kaspersky 5.x server-suite. |
| 33 |
Default: /opt/kav/bin/aveclient |
| 34 |
|
| 35 |
=item avdaemon_sock I</path/to/socket> |
| 36 |
|
| 37 |
Set the path to the unix socket of the original aveserver of kaspersky 5.x server-suite. |
| 38 |
Default: /var/run/aveserver |
| 39 |
|
| 40 |
=item blockonerror I<(1|0)> |
| 41 |
|
| 42 |
Whether to block mails on scanning errors or to accept connections. |
| 43 |
Default: 0 (No) |
| 44 |
|
| 45 |
=back |
| 46 |
|
| 47 |
=back |
| 48 |
|
| 49 |
=head1 EXIT CODES OF aveclient (taken from man aveclient) |
| 50 |
|
| 51 |
When launched with the -s option, aveclient returns one of the following codes (if several files to be scanned are indicated in the |
| 52 |
command line, the return code corresponds to the results of scanning the last file): |
| 53 |
|
| 54 |
0 no viruses have been detected. |
| 55 |
|
| 56 |
1 unable to connect to aveserver. |
| 57 |
|
| 58 |
2 objects with an unknown viral code have been found. |
| 59 |
|
| 60 |
3 suspicious objects have been found. |
| 61 |
|
| 62 |
4 infected objects have been detected. |
| 63 |
|
| 64 |
5 all infected objects have been disinfected. |
| 65 |
|
| 66 |
6 scan results are unavailable: encrypted or password protected file. |
| 67 |
|
| 68 |
7 system error launching the application (file not found, unable to read the file). |
| 69 |
|
| 70 |
8 scan results are unavailable: file is corrupted or input/output error. |
| 71 |
|
| 72 |
9 some of the required parameters are missing from the command line. |
| 73 |
|
| 74 |
=head1 VERSION |
| 75 |
|
| 76 |
0.1rc first proof of concept. |
| 77 |
How is load and performance on larger systems? This is tested whith aprox. 900 Clients |
| 78 |
on a small RH-System (AMD, 768 Mhz, 512 MB) MAXCLIENTS set to 40. |
| 79 |
|
| 80 |
=head1 AUTHOR |
| 81 |
|
| 82 |
Adopted by Marcus Spiegel <[email protected]> from kavscanner plugin of Hanno Hecker. |
| 83 |
|
| 84 |
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 85 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 86 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 87 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 88 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 89 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 90 |
SOFTWARE. |
| 91 |
|
| 92 |
=cut |
| 93 |
|
| 94 |
use File::Temp qw(tempfile); |
| 95 |
use Mail::Address; |
| 96 |
|
| 97 |
sub register { |
| 98 |
my ($self, $qp, @args) = @_; |
| 99 |
|
| 100 |
# defaults to be used |
| 101 |
$self->{_avclient_bin} = "/opt/kav/bin/aveclient"; |
| 102 |
$self->{_avdaemon_sock} = "/var/run/aveserver"; |
| 103 |
$self->{_blockonerror} = 0; |
| 104 |
|
| 105 |
# parse optional arguments |
| 106 |
my %args = @args; |
| 107 |
foreach my $key (keys %args) { |
| 108 |
my $arg = $key; |
| 109 |
$key =~ s/^/_/; |
| 110 |
$self->{$key} = $args{$arg}; |
| 111 |
} |
| 112 |
|
| 113 |
# Untaint client location |
| 114 |
# socket will be tested during scan (response-code) |
| 115 |
if (exists $self->{_avclient_bin} |
| 116 |
&& $self->{_avclient_bin} =~ /^(\/[\/\-\_\.a-z0-9A-Z]*)$/) |
| 117 |
{ |
| 118 |
$self->{_avclient_bin} = $1; |
| 119 |
} |
| 120 |
else { |
| 121 |
$self->log(LOGALERT, |
| 122 |
"FATAL ERROR: No binary aveclient found: '" |
| 123 |
. $self->{_avclient_bin} . "'" |
| 124 |
); |
| 125 |
exit 3; |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
sub hook_data_post { |
| 130 |
my ($self, $transaction) = @_; |
| 131 |
my ($temp_fh, $filename) = tempfile(); |
| 132 |
my $description = 'clean'; |
| 133 |
|
| 134 |
# a temporary file is needed to be scanned |
| 135 |
print $temp_fh $transaction->header->as_string; |
| 136 |
print $temp_fh "\n"; |
| 137 |
|
| 138 |
$transaction->body_resetpos; |
| 139 |
|
| 140 |
while (my $line = $transaction->body_getline) { |
| 141 |
print $temp_fh $line; |
| 142 |
} |
| 143 |
seek($temp_fh, 0, 0); |
| 144 |
|
| 145 |
# Now scan this file |
| 146 |
my $cmd = |
| 147 |
$self->{_avclient_bin} . " -p " |
| 148 |
. $self->{_avdaemon_sock} |
| 149 |
. " -s $filename 2>&1"; |
| 150 |
|
| 151 |
my @output = `$cmd`; |
| 152 |
chomp(@output); |
| 153 |
|
| 154 |
my $result = ($? >> 8); |
| 155 |
my $signal = ($? & 127); |
| 156 |
|
| 157 |
# tidy up a bit |
| 158 |
unlink($filename); |
| 159 |
close $temp_fh; |
| 160 |
|
| 161 |
# check if something went wrong |
| 162 |
if ($signal) { |
| 163 |
$self->log(LOGERROR, "kavscanner exited with signal: $signal"); |
| 164 |
return (DECLINED); |
| 165 |
} |
| 166 |
|
| 167 |
# either we found a virus or something went wrong |
| 168 |
if ($result > 0) { |
| 169 |
if ($result =~ /^(2|3|4|6|8)$/) { |
| 170 |
|
| 171 |
# ok a somewhat virus was found |
| 172 |
shift @output; |
| 173 |
$description = "REPORT: " . join(", ", @output); |
| 174 |
$self->log(LOGWARN, "Virus found! ($description)"); |
| 175 |
|
| 176 |
# we don't want to be disturbed be these, so block mail and DENY connection |
| 177 |
return (DENY, "Virus found: $description"); |
| 178 |
|
| 179 |
} |
| 180 |
else { |
| 181 |
$self->log(LOGCRIT, "aveserver: no viruses have been detected.") |
| 182 |
if ($result =~ /^0$/); |
| 183 |
$self->log(LOGCRIT, |
| 184 |
"aveserver: system error launching the application (file not found, unable to read the file)." |
| 185 |
) |
| 186 |
if ($result =~ /^0$/); |
| 187 |
$self->log(LOGCRIT, |
| 188 |
"aveserver: some of the required parameters are missing from the command line." |
| 189 |
) |
| 190 |
if ($result =~ /^9$/); |
| 191 |
return (DENY, |
| 192 |
"Unable to scan for virus, please contact admin of " |
| 193 |
. $self->qp->config("me") |
| 194 |
. ", if you feel this is an error!" |
| 195 |
) |
| 196 |
if $self->{_blockonerror}; |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
$self->log(LOGINFO, "kavscanner results: $description"); |
| 201 |
$transaction->header->add('X-Virus-Checked', |
| 202 |
'Checked by Kaspersky on ' . $self->qp->config("me")); |
| 203 |
return (DECLINED); |
| 204 |
} |