Beispiel #1
0
def probe_scan(frontend, filename):
    routing_key = current_task.request.delivery_info['routing_key']
    if routing_key == 'dlq':
        log.error("filename %s scan timeout", filename)
        raise ValueError("Timeout")
    try:
        tmpname = None
        # retrieve queue name and the associated plugin
        probe = probes[routing_key]
        log.debug("filename %s probe %s", filename, probe)
        (fd, tmpname) = tempfile.mkstemp()
        os.close(fd)
        ftp_ctrl.download_file(frontend, filename, tmpname)
        results = probe.run(tmpname)
        handle_output_files(results, frontend, filename)
        return bytes_to_utf8(results)
    except Exception as e:
        log.exception(e)
        raise probe_scan.retry(countdown=2, max_retries=3, exc=e)
    finally:
        # Some AV always delete suspicious file
        if tmpname is not None and os.path.exists(tmpname):
            log.debug("filename %s probe %s removing tmp_name %s",
                      filename, probe, tmpname)
            os.remove(tmpname)
Beispiel #2
0
def probe_scan(frontend, filename):
    routing_key = current_task.request.delivery_info['routing_key']
    if routing_key == 'dlq':
        log.error("filename %s scan timeout", filename)
        raise ValueError("Timeout")
    try:
        tmpname = None
        # retrieve queue name and the associated plugin
        probe = probes[routing_key]
        log.debug("filename %s probe %s", filename, probe)
        (fd, tmpname) = tempfile.mkstemp()
        os.close(fd)
        ftp_ctrl.download_file(frontend, filename, tmpname)
        results = probe.run(tmpname)
        handle_output_files(results, frontend, filename)
        return bytes_to_utf8(results)
    except Exception as e:
        log.exception(e)
        raise probe_scan.retry(countdown=2, max_retries=3, exc=e)
    finally:
        # Some AV always delete suspicious file
        if tmpname is not None and os.path.exists(tmpname):
            log.debug("filename %s probe %s removing tmp_name %s", filename,
                      probe, tmpname)
            os.remove(tmpname)
Beispiel #3
0
 def test_download_file(self, m_IrmaSFTPv2):
     filename = "file4"
     m_ftp = MagicMock()
     m_IrmaSFTPv2().__enter__.return_value = m_ftp
     module.download_file("frontend", "srcname", filename)
     m_ftp.download_file.assert_called_once_with(".", "srcname", filename)