User Tools

Site Tools


doc:appunti:linux:sa:procmail_sanitizer_clamav

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
doc:appunti:linux:sa:procmail_sanitizer_clamav [2020/06/16 13:13] – [Cosa succede se clamd è fermo] niccolodoc:appunti:linux:sa:procmail_sanitizer_clamav [2020/07/22 11:50] – [Sanitizer] niccolo
Line 1: Line 1:
-====== Scansione antivirus con procmailsanitizer clamav ======+====== Antivirus con ProcmailSanitizer ClamAV ======
  
-Se si utilizza **procmail** come //local delivery agent//, è sufficiente aggiungere questa regola in **$HOME/.procmailrc** per abilitare il filtro antivirus con il programma **sanitizer**:+===== Procmail =====
  
 +Se si utilizza **procmail** come //local delivery agent//, è sufficiente aggiungere questa regola in **$HOME/.procmailrc** per abilitare il filtro antivirus tramite il programma **sanitizer**:
  
 <file> <file>
 +#-------------------------------------------------------------------------
 +# $HOME/.procmailrc
 +#-------------------------------------------------------------------------
 PATH=/usr/local/bin:/usr/bin:/bin PATH=/usr/local/bin:/usr/bin:/bin
 SHELL=/bin/bash SHELL=/bin/bash
Line 19: Line 23:
 </file> </file>
  
-Il programma sanitizer si configura tramite **/etc/sanitizer.cfg**:+===== Sanitizer ===== 
 + 
 +Il programma sanitizer funziona come filtro sui messaggi di posta, analizzando gli allegati secondo la configurazione indicata in  **/etc/sanitizer.cfg**:
  
 <file> <file>
 +#-------------------------------------------------------------------------
 +# Active features.
 +#-------------------------------------------------------------------------
 +feat_verbose      = 0    # Warn user about unscanned parts, etc.
 +feat_log_inline   = 0    # Inline logs: 0 = Off, 1 =  Maybe, 2 = Force
 +feat_log_stderr   = 0    # Print log to standard error.
 +feat_log_xml      = 0    # Don't use XML format for logs.
 +feat_log_trace    = 0    # Omit trace info from logs.
 +feat_log_after    = 0    # Don't add any scratch space to part headers.
 +feat_files        = 1    # Enable filename-based policy decisions.
 +feat_mime_files   = 1    # Always check the mime-type's default name too.
 +feat_force_name   = 0    # Force all parts (except text/html parts) to
 +                         # have file names.
 +feat_boundaries   = 0    # Replace all boundary strings with our own
 +                         # NOTE:  Always breaks PGP/MIME messages!
 +feat_lengths      = 1    # Protect against buffer overflows and null
 +                         # values.
 +feat_scripts      = 1    # Defang incoming shell scripts.
 +feat_html         = 0    # Defang active HTML content.
 +feat_webbugs      = 0    # Web-bugs are allowed.
 +feat_trust_pgp    = 0    # Don't scan PGP signed message parts.
 +feat_uuencoded    = 1    # Sanitize inline uuencoded files.
 +feat_forwards     = 1    # Sanitize forwarded messages.
 +feat_testing      = 0    # This isn't a test-case configuration.
 +feat_fixmime      = 1    # Fix invalid MIME, if possible.
 +feat_paranoid     = 0    # Don't be excessively paranoid about MIME headers etc.
 +
 #------------------------------------------------------------------------- #-------------------------------------------------------------------------
 # Create saved files using this template. The directory must exist and # Create saved files using this template. The directory must exist and
 # be writable by the user running the sanitizer. # be writable by the user running the sanitizer.
 +#    $d - Day of month (01-31)
 +#    $m - Month number (01-12)
 +#    $y - Two digit year (00-99)
 +#    $Y - Four digit year
 +#    $H - Hour (00-23)
 +#    $M - Minute (00-59)
 +#    $S - Second (00-59)
 +#
 +#    $P - This process's PID, in hex.
 +#    $T - The current Unix time, in hex.
 +#    $F - A safe version of the original file name.
 +#    $  - A random character, from [A-Z0-9].
 #------------------------------------------------------------------------- #-------------------------------------------------------------------------
 file_name_tpl = /home/quarantine/$Y$m$d-$T-$F.$$ file_name_tpl = /home/quarantine/$Y$m$d-$T-$F.$$
Line 38: Line 83:
 msg_file_save += %SAVEDNAME\n msg_file_save += %SAVEDNAME\n
 msg_file_save += *******************\n msg_file_save += *******************\n
 +
 +#-------------------------------------------------------------------------
 +# We have 2 policies, in addition to the file_default_policy.
 +#-------------------------------------------------------------------------
 +file_list_rules = 2
 +
 +#-------------------------------------------------------------------------
 +# 1) Scan some attachments for virus with Clam AntiVirus.
 +#-------------------------------------------------------------------------
 +# This policy apply to attachments whose file name did not match any
 +# previous policy and matches this regular expression.
 +# The policy action can be:
 +#
 +#   accept   Don't alter the attachment at all.
 +#   defang   Alter the attachment's file name.
 +#   mangle   Change completely the attachment's file name.
 +#   save     Remove the attachment from the message, replace it with a
 +#            text message and save the attachment into a local file.
 +#   drop     The attachment will be deleted and replaced with message.
 +#   unknown  Indeterminate result, check the next policy.
 +#
 +#-------------------------------------------------------------------------
 +# Archives, executables, scripts, etc. This is a perl regular
 +# expression, see "man perlre" for info. The (?i) prefix makes
 +# the regexp case insensitive.
 +file_list_1  = (?i)\.(
 +file_list_1 += 7z|bat|com|chm|cmd|cpl|exe|pif|scr|sys
 +file_list_1 += |dat|doc|m?db|ppt|pps|ppsx|rtf|xls|xlsm|xlsx|wp.?
 +file_list_1 += |class|pl|vb[es]|[sp]?html?|php\d?
 +file_list_1 += |z(ip|oo)|ar[cj]|lha|[tr]ar|rpm|deb|slp|tgz|g?z|bz\d?
 +file_list_1 += )$
  
 # Virus scanner command line. The three exit codes represent the # Virus scanner command line. The three exit codes represent the
 # following scan conditions: clean, disinfected, infected. # following scan conditions: clean, disinfected, infected.
-file_list_1_scanner = 0:1:1:/usr/bin/clamdscan --fdpass --quiet %FILENAME+# NOTICE: clamdscan does not have the "disinfected" condition. 
 +file_list_1_scanner = 0:99:1:/usr/bin/clamdscan --fdpass --quiet %FILENAME
  
 # What policy to apply for each exit code, plus a catch-all default. # What policy to apply for each exit code, plus a catch-all default.
-#   unknown  Indeterminate resultcheck the next policy+file_list_1_policy  = unknown:unknown:save:unknown 
-  save     Remove the attachment from the message, replace it with a + 
-           text message and save the attachment into a local file. + 
-file_list_1_policy  unknown:save:save:save+#------------------------------------------------------------------------- 
 +# 2) White listthis extensions (or Content-Type) will be accepted
 +#------------------------------------------------------------------------- 
 +file_list_2  = (?i)\.( 
 +file_list_2 += 7z|ai|ang|an6|asc|bmp|bz2|cl|csv|dat|doc|docx|dwg|dxf|fh|gif|gz|html?|ics|indd 
 +file_list_2 += |jc3|jc4|jc5|jpe?g|m?db|mov|p7m|od[btsgfp]|ot[btspgf]|pcx|pdf|png|pps|ppsx|ppt|pptx 
 +file_list_2 += |psd|pub|rtf|snp|sxc|tiff?|tgz|txt|vcf|wav|wp.?|xls|xlsm|xlsx|xml|zip 
 +file_list_2 += )$ 
 +file_list_2_scanner = 0; 
 +file_list_2_policy = accept; 
 + 
 + 
 +#------------------------------------------------------------------------- 
 +# Default policy: accept, but mangle file name
 +#------------------------------------------------------------------------- 
 +file_default_policy defang
  
 #------------------------------------------------------------------------- #-------------------------------------------------------------------------
Line 55: Line 147:
 </file> </file>
  
 +Con la direttiva **file_list_1_scanner** si indica il programma filtro da chiamare - nel notro caso **clamdscan** con l'opzione **%%--fdpass%%** - e quali sono i codici di uscita per tre possibili esiti della scansione: **clean** (l'allegato è pulito), **disinfected** (l'allegato era infetto, ma è stato ripulito), **infected** (l'allegato è infetto). Nel caso di clamdscan vale solo l'**exit code 0** per un file **pulito** e l'**exit code 1** per un file **infetto**; non esistendo il caso **disinfected** si è indicato l'inesistente **exit code 99**.
 +
 +La politica da applicare a seguito della scansione è determinata da **file_list_1_policy**. Si devono indicare **quattro possibili azioni** di cui le prime tre corrispondo ai tre esiti della scansione (//clean//, //disinfected// e //infected//) e la quarta è l'azione predefinita.
 +
 +Ricapitolando questa è la politica applicata ai file compresi nella **file_list_1**:
 +
 +^ Esito scansione  ^ Clamdscan Exit Code  ^ Sanitizer Policy  ^
 +| Clean          |    0 | **unknown** (check the next policy).  |
 +| Disinfected    |  N/A | **unknown** (check the next policy).  |
 +| Infected          1 | **save** (remove the attachment from the message).  |
 +| Generic error  |    2 | **unknown** (check the next policy).  |
 +
 +==== Content-Type ed estensioni per Sanitizer ====
 +
 +Nella whitelist #2 vengono indicate delle estensioni per cui l'allegato passa intalterato, cioè non viene //neutralizzato// cambiandogli nome.
  
 +In realtà Sanitizer applica la whitelist sia che corrisponda l'**estensione** del file, sia che corrisponda il **Content-Type**. Non è chiaro come avere la corrispondenza tra i due tipi, ad esempio (empiricamente) si è determinato che il **Content-Type application/octet-stream** corrisponde all'estensione **bin**.
 ===== Cosa succede se clamd è fermo ===== ===== Cosa succede se clamd è fermo =====
  
Line 64: Line 172:
 ^ 2  | Could not connect to clamd on LocalSocket.  | ^ 2  | Could not connect to clamd on LocalSocket.  |
  
-Quindi se il demone non risponde si ottiene un codice di uscita 2.+Se il demone **clamd** non risponde, il programma **clamdscan** restituisce un exit code 2, quindi non si applicano le tre possibili condizioni (clean, disinfected, infected); verrà applicata la policy //catch-all// che nell'esempio sopra è **unknown**,  cioè l'applicazione delle regole successive. 
 + 
 +Nella configurazione mostrata sopra la regola successiva prevede di accettare tali e quali gli allegati che corrispondono a **file_list_2** (in pratica documenti allegati non pericolosi), per tutti gli altri viene applicata la **file_default_policy** che consiste nel **defang**, cioè alterare il nome dell'allegato in modo che non sia più pericoloso (ad esempio la rimozione dell'estensione .exe oppure .com). 
 + 
 +Una configurazione più stringente potrebbe essere quella di applicare la policy **save** (rimozione dell'allegato) anche nel caso //catch-all// (**esito della scansione anomalo** e non previsto). Questa configurazione ha una controindicazione grave: se il demone clamd è fermo per qualche motivo, tutti gli allegati verrebbero eliminati dalla mail, anche quelli puliti ed essenziali come il testo HTML.
doc/appunti/linux/sa/procmail_sanitizer_clamav.txt · Last modified: 2022/04/11 18:13 by niccolo