cuckoosandbox / community

Repository of modules and signatures contributed by the community
324 stars 175 forks source link

processing clamav.py #361

Open primmus opened 7 years ago

primmus commented 7 years ago

import os

from cuckoo.common.exceptions import CuckooProcessingError from cuckoo.common.abstracts import Processing from cuckoo.common.files import Files

try: import clamd HAVE_CLAMAV = True except ImportError: HAVE_CLAMAV = False

class Clamav(Processing):

def run(self):
    """Get ClamAV signatures matches.
    @return: matched ClamAV signatures.
    """
    self.key = "clamav"
    scan = []

    if HAVE_CLAMAV:
        if os.path.getsize(self.file_path) > 0:
            try:
                cd = clamd.ClamdUnixSocket()
            except:
                log.warning("failed to connect to clamd socket")
            try:
                r=cd.scan(self.file_path)
            except Exception as e:
                log.warning("failed to scan file with clamav %s",e)
            for key in r:
                if r[key][0] == "FOUND":
                    scan = r[key][1]

    return scan