Dynamically running ClamAV's clamscan on file uploads with PHP

前端 未结 3 1132
南方客
南方客 2020-12-29 11:51

Stack,

I want to scan each file that gets uploaded via my php upload script with clam anti-virus\'s clamscan tool. I think I\'ve got a good script written but I wan

相关标签:
3条回答
  • 2020-12-29 12:39

    Just be careful. If your clamscan becomes outdated you'll get feedback in the output:

    It will look like this:

    LibClamAV Warning: ***********************************************************
    LibClamAV Warning: ***  This version of the ClamAV engine is outdated.     ***
    LibClamAV Warning: *** DON'T PANIC! Read http://www.clamav.net/support/faq ***
    LibClamAV Warning: ***********************************************************
    

    Also depending on the version of clamscan the "result" might look like this (and you'll need to parse it accordingly):

    [filename]: OK
    
    ----------- SCAN SUMMARY -----------
    Known viruses: x
    Engine version: x.x.x
    Scanned directories: 0
    Scanned files: 1
    Infected files: 0
    Data scanned: x.xx MB
    Data read: x.xx MB (ratio 0.00:1)
    Time: x.xx sec (0 m x s)
    
    0 讨论(0)
  • 2020-12-29 12:48

    Note that if your server runs a clamav daemon (clamd) it may be possible to use clamdscan instead of clamscan as proposed, this usage is faster since use virus signatures already loaded by clamd.

    0 讨论(0)
  • 2020-12-29 12:50

    I had a lot of trouble with permissions when trying to run this with clamdscan. I found a solution for the permissions problem here: https://wiki.archlinux.org/index.php/ClamAV

    This changed this line:

    $command = 'clamscan ' . $safe_path;
    

    to:

    $command = 'clamdscan  --fdpass ' . $safe_path;
    

    Seemed to successfully pass a good file and flag an EICAR file.

    0 讨论(0)
提交回复
热议问题