コード例 #1
0
ファイル: test_services.py プロジェクト: vaginessa/irma
 def test_check_probe_unknown_probe(self, m_celery_brain):
     probelist = ['probe1', 'probe2', 'probe6']
     all_probelist = ['probe1', 'probe2', 'probe3']
     m_celery_brain.probe_list.return_value = all_probelist
     with self.assertRaises(IrmaValueError) as context:
         module.check_probe(probelist)
     self.assertEqual(str(context.exception), "probe probe6 unknown")
コード例 #2
0
def launch_v1(scan_id: uuid,
              probes: comma_separated_list = None,
              force: smart_boolean = False,
              mimetype_filtering: smart_boolean = True,
              resubmit_files: smart_boolean = True,
              ):
    """ Launch a scan.
        The request should be performed using a POST request method.
    """
    session = db.session
    scan = Scan.load_from_ext_id(scan_id, session)

    # handle scan parameter
    # cached results: "force" (default: False)
    scan.force = force

    # use mimetype for probelist: "mimetype_filtering" (default: True)
    scan.mimetype_filtering = mimetype_filtering

    # rescan file outputted from probes "resubmit_files" (default: True)
    scan.resubmit_files = resubmit_files
    session.commit()

    msg = "scan %s: Force %s MimeF %s"
    msg += "Resub %s Probes %s"
    log.debug(msg, scan_id, scan.force, scan.mimetype_filtering,
              scan.resubmit_files, probes)
    probelist = probe_ctrl.check_probe(probes)
    log.info("scan %s: probes used: %s", scan_id, probelist)
    scan.set_probelist(probelist)
    session.commit()
    # launch_asynchronous scan via frontend task
    celery_frontend.scan_launch(str(scan_id))

    return scan_schema.dump(scan).data
コード例 #3
0
ファイル: controllers.py プロジェクト: quarkslab/irma
def launch_v1(scan_id: uuid,
              probes: comma_separated_list = None,
              force: smart_boolean = False,
              mimetype_filtering: smart_boolean = True,
              resubmit_files: smart_boolean = True,
              ):
    """ Launch a scan.
        The request should be performed using a POST request method.
    """
    session = db.session
    scan = Scan.load_from_ext_id(scan_id, session)

    # handle scan parameter
    # cached results: "force" (default: False)
    scan.force = force

    # use mimetype for probelist: "mimetype_filtering" (default: True)
    scan.mimetype_filtering = mimetype_filtering

    # rescan file outputted from probes "resubmit_files" (default: True)
    scan.resubmit_files = resubmit_files
    session.commit()

    msg = "scan %s: Force %s MimeF %s"
    msg += "Resub %s Probes %s"
    log.debug(msg, scan_id, scan.force, scan.mimetype_filtering,
              scan.resubmit_files, probes)
    probelist = probe_ctrl.check_probe(probes)
    log.info("scan %s: probes used: %s", scan_id, probelist)
    scan.set_probelist(probelist)
    session.commit()
    # launch_asynchronous scan via frontend task
    celery_frontend.scan_launch(str(scan_id))

    return scan_schema.dump(scan).data
コード例 #4
0
ファイル: models.py プロジェクト: quarkslab/irma
    def __init__(self, date, ip, force=True, mimetype_filtering=True,
                 resubmit_files=True, files_ext=[], probes=None):
        super(Scan, self).__init__()
        self.external_id = UUID.generate()
        self.date = date
        self.ip = ip
        self.force = force
        self.mimetype_filtering = mimetype_filtering
        self.resubmit_files = resubmit_files

        self.set_status(IrmaScanStatus.empty)

        if files_ext:
            for fe in files_ext:
                log.info("scan {} adding file {}"
                         .format(self.external_id, fe.external_id))
                fe.scan = self
            self.set_status(IrmaScanStatus.ready)

        self.set_probelist(probe_ctrl.check_probe(probes))

        log.debug("scan {}: created".format(self.external_id))
        log.debug("scan {}: Force {} MimeF {} Resub {} Probes {}"
                  .format(self.external_id, self.force,
                          self.mimetype_filtering, self.resubmit_files,
                          probes))
コード例 #5
0
    def __init__(self,
                 date,
                 ip,
                 force=True,
                 mimetype_filtering=True,
                 resubmit_files=True,
                 files_ext=[],
                 probes=None):
        super(Scan, self).__init__()
        self.external_id = UUID.generate()
        self.date = date
        self.ip = ip
        self.force = force
        self.mimetype_filtering = mimetype_filtering
        self.resubmit_files = resubmit_files

        self.set_status(IrmaScanStatus.empty)

        if files_ext:
            for fe in files_ext:
                log.info("scan {} adding file {}".format(
                    self.external_id, fe.external_id))
                fe.scan = self
            self.set_status(IrmaScanStatus.ready)

        self.set_probelist(probe_ctrl.check_probe(probes))

        log.debug("scan {}: created".format(self.external_id))
        log.debug("scan {}: Force {} MimeF {} Resub {} Probes {}".format(
            self.external_id, self.force, self.mimetype_filtering,
            self.resubmit_files, probes))
コード例 #6
0
ファイル: test_services.py プロジェクト: vaginessa/irma
 def test_check_probe_None(self, m_celery_brain):
     probelist = None
     all_probelist = ['probe1', 'probe2', 'probe3']
     m_celery_brain.probe_list.return_value = all_probelist
     ret = module.check_probe(probelist)
     self.assertEqual(ret, all_probelist)
コード例 #7
0
ファイル: controllers.py プロジェクト: vaginessa/irma
def launch_v2(request, body):
    """ Launch a scan.
        The request should be performed using a POST request method.
        The input json format is the following:
        {
            files: [fileext1, fileext2...]
            options:
               probes: list of probes or None for all available,
               force: boolean (default False),
               mimetype_filtering: boolean (default True),
               resubmit_files: boolean (default True),
        }
    """
    scan_params = body
    if not scan_params:
        raise HTTPInvalidParam("Missing json parameters", "body")
    files_list = body.get('files', None)

    if files_list is None or len(files_list) == 0:
        raise HTTPInvalidParam("Missing values", "files")

    # Set default values
    force = True
    mimetype_filtering = True
    resubmit_files = True
    probes = None
    # override with given values if set
    scan_options = body.get("options", None)
    if scan_options is not None:
        force = scan_options.get("force", False)
        if type(force) is not bool:
            raise HTTPInvalidParam("Should be boolean", "force")
        mimetype_filtering = scan_options.get("mimetype_filtering", True)
        if type(mimetype_filtering) is not bool:
            raise HTTPInvalidParam("Should be boolean", "mimetype_filtering")
        resubmit_files = scan_options.get("resubmit_files", True)
        if type(resubmit_files) is not bool:
            raise HTTPInvalidParam("Should be boolean", "resubmit_files")
        probes = scan_options.get("probes", None)

    session = db.session
    ip = request.remote_addr
    scan = Scan(compat.timestamp(), ip)
    session.add(scan)

    # handle scan parameter
    # cached results: "force" (default: True)
    scan.force = force

    # use mimetype for probelist: "mimetype_filtering" (default: True)
    scan.mimetype_filtering = mimetype_filtering

    # rescan file outputted from probes "resubmit_files" (default: True)
    scan.resubmit_files = resubmit_files

    scan.set_status(IrmaScanStatus.empty)
    session.commit()

    log.debug("scan %s: created", scan.external_id)

    msg = "scan %s: Force %s MimeF %s"
    msg += " Resub %s Probes %s"
    log.debug(msg, scan.external_id, scan.force, scan.mimetype_filtering,
              scan.resubmit_files, probes)

    for fe_id in files_list:
        log.info("scan %s adding file %s", scan.external_id, fe_id)
        try:
            file_ext = FileExt.load_from_ext_id(fe_id, session)
        except IrmaDatabaseResultNotFound:
            raise HTTPInvalidParam("File %s not found" % fe_id, "files")

        if file_ext.file.path is None:
            raise HTTPInvalidParam(
                "File with hash %s should be ("
                "re)uploaded" % file_ext.file.sha256, "files")

        if file_ext.scan is not None:
            raise HTTPInvalidParam("File %s already scanned" % fe_id, "files")
        file_ext.scan = scan

    scan.set_status(IrmaScanStatus.ready)
    session.commit()

    probelist = probe_ctrl.check_probe(probes)
    scan.set_probelist(probelist)
    session.commit()
    # launch_asynchronous scan via frontend task
    celery_frontend.scan_launch(str(scan.external_id))

    return scan_schema.dump(scan).data