Esempio n. 1
0
class AVScanner(object):
    def __init__(self):
        self.multi_av = CMultiAV("%s/cmultiav.cfg" % os.path.dirname(__file__))

    def has_virus(self, file, parallel=True):
        with tempfile.NamedTemporaryFile(delete=False) as temporaryfile:
            temporaryfile.write(file.read())
            temporaryfile.close()
            permission = 0o664  # PEP 3127: octal literals
            os.chmod(temporaryfile.name, permission)  # clamav needs permission to scan
            if parallel:
                # TODO: Handle the case for when no scanner is installed ...
                # Currently we say that nothing was found...
                # The single core case works as expected
                ret = self.multi_av.scan(temporaryfile.name, AV_SPEED_MEDIUM)
            else:

                try:
                    ret = self.multi_av.single_scan(temporaryfile.name, AV_SPEED_MEDIUM)
                except OSError:
                    # It would seem a scanner is not installed...
                    return True, "No virus scanner was found on the system..."

            os.unlink(temporaryfile.name)
            for x in list(ret.values()):
                if x != {}:
                    # all is lost as soon as one scanner finds something
                    return True, ret
            return False, None
Esempio n. 2
0
  def POST(self):
    i = web.input(file_upload={})
    if i["file_upload"] is None or i["file_upload"] == "":
      return render.error("No file uploaded or invalid file.")

    buf = i["file_upload"].value
    filename = i["file_upload"].filename

    # Scan the file
    av = CMultiAV()
    ret = av.scan_buffer(buf)

    # Calculate the hashes
    hashes = []
    hashes.append(md5(buf).hexdigest())
    hashes.append(sha1(buf).hexdigest())
    hashes.append(sha256(buf).hexdigest())

    # Save the sample
    db_api = CDbSamples()
    db_api.insert_sample(filename, buf, ret)

    # And show the results
    render = web.template.render(TEMPLATE_PATH)
    return render.results(ret, filename, hashes)
Esempio n. 3
0
  def POST(self):
    i = web.input(file_upload={})
    if "file_upload" not in i or i["file_upload"] is None or i["file_upload"] == "":
      return '{"error": "No file uploaded or invalid file."}'

    buf = i["file_upload"].value
    filename = i["file_upload"].filename

    # Scan the file
    av = CMultiAV()
    report = av.scan_buffer(buf)

    db_api = CDbSamples()
    db_api.insert_sample(filename, buf, report)
    return json.dumps(report)
Esempio n. 4
0
  def POST(self):
    i = web.input(file_upload={}, speed=AV_SPEED_ULTRA)
    if i["file_upload"] is None or i["file_upload"] == "":
      return "{'error':'No file uploaded or invalid file.'}"

    speed = int(i["speed"])
    buf = i["file_upload"].value
    filename = i["file_upload"].filename

    # Scan the file
    av = CMultiAV()
    report = av.scan_buffer(buf, speed)

    db_api = CDbSamples()
    db_api.insert_sample(filename, buf, report)

    return json.dumps(report)
Esempio n. 5
0
        name=name, 
        plugin_type=plugin_type, 
        has_internet=has_internet, 
        speed=speed,
        signature_version=signature_version,
        engine_version=engine_version if engine_version is not None else "-")

    return updated_rows

# -----------------------------------------------------------------------
# MultiAV Instance
try:
  overprovisioning_multiplyer=1
  config_name = "config.cfg"
  scanner_strategy = AutoScaleDockerStrategy(config_name, min_machines=2, max_machines = 5, max_containers_per_machine = cpu_count() * overprovisioning_multiplyer, max_scans_per_container = 1)
  CAV = CMultiAV(scanner_strategy, config_name, auto_start=True, auto_pull=True)
except PullPluginException as e:
  print(e)
  exit(2)
except StartPluginException as e:
  print(e)
  exit(3)
except CreateNetworkException as e:
  print(e)
  exit(4)

if not os.path.isdir(os.path.join(CURRENT_PATH, 'static')):
    raise Exception('runserver.py must be run in the directory {0}'.format(ROOT_PATH))

# -----------------------------------------------------------------------
def convert_result_rows_to_ui_datastructure(rows):
Esempio n. 6
0
def main(path):
    multi_av = CMultiAV()
    ret = multi_av.scan(path, AV_SPEED_ALL)

    import pprint
    pprint.pprint(ret)
Esempio n. 7
0
 def __init__(self):
     self.multi_av = CMultiAV("%s/cmultiav.cfg" % os.path.dirname(__file__))