コード例 #1
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
コード例 #2
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
コード例 #3
0
def quick_scan(request):
    """ Launch a scan for one file
    """
    session = db.session
    ip = request.remote_addr

    # Create file
    fe = files_ctrl.create(request)
    fe = FileExt.load_from_ext_id(fe['result_id'], session)

    # Create a scan
    scan = Scan(compat.timestamp(), ip, files_ext=[fe, ])
    session.add(scan)
    session.commit()

    # launch_asynchronous scan via frontend task
    celery_frontend.scan_launch(str(scan.external_id))

    return scan_schema.dump(scan).data
コード例 #4
0
ファイル: controllers.py プロジェクト: quarkslab/irma
def quick_scan(request):
    """ Launch a scan for one file
    """
    session = db.session
    ip = request.remote_addr

    # Create file
    fe = files_ctrl.create(request)
    fe = FileExt.load_from_ext_id(fe['result_id'], session)

    # Create a scan
    scan = Scan(compat.timestamp(), ip, files_ext=[fe, ])
    session.add(scan)
    session.commit()

    # launch_asynchronous scan via frontend task
    celery_frontend.scan_launch(str(scan.external_id))

    return scan_schema.dump(scan).data
コード例 #5
0
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", force)
        if type(force) is not bool:
            raise HTTPInvalidParam("Should be boolean", "force")
        mimetype_filtering = scan_options.get("mimetype_filtering",
                                              mimetype_filtering)
        if type(mimetype_filtering) is not bool:
            raise HTTPInvalidParam("Should be boolean",
                                   "mimetype_filtering")
        resubmit_files = scan_options.get("resubmit_files", resubmit_files)
        if type(resubmit_files) is not bool:
            raise HTTPInvalidParam("Should be boolean",
                                   "resubmit_files")
        probes = scan_options.get("probes", probes)

    session = db.session
    ip = request.remote_addr

    files_ext = []
    for fe_id in files_list:
        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")
        files_ext.append(file_ext)

    scan = Scan(compat.timestamp(), ip,
                force=force, mimetype_filtering=mimetype_filtering,
                resubmit_files=resubmit_files, files_ext=files_ext,
                probes=probes)
    session.add(scan)
    session.commit()
    # launch_asynchronous scan via frontend task
    celery_frontend.scan_launch(str(scan.external_id))

    return scan_schema.dump(scan).data
コード例 #6
0
ファイル: controllers.py プロジェクト: quarkslab/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", force)
        if type(force) is not bool:
            raise HTTPInvalidParam("Should be boolean", "force")
        mimetype_filtering = scan_options.get("mimetype_filtering",
                                              mimetype_filtering)
        if type(mimetype_filtering) is not bool:
            raise HTTPInvalidParam("Should be boolean",
                                   "mimetype_filtering")
        resubmit_files = scan_options.get("resubmit_files", resubmit_files)
        if type(resubmit_files) is not bool:
            raise HTTPInvalidParam("Should be boolean",
                                   "resubmit_files")
        probes = scan_options.get("probes", probes)

    session = db.session
    ip = request.remote_addr

    files_ext = []
    for fe_id in files_list:
        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")
        files_ext.append(file_ext)

    scan = Scan(compat.timestamp(), ip,
                force=force, mimetype_filtering=mimetype_filtering,
                resubmit_files=resubmit_files, files_ext=files_ext,
                probes=probes)
    session.add(scan)
    session.commit()
    # launch_asynchronous scan via frontend task
    celery_frontend.scan_launch(str(scan.external_id))

    return scan_schema.dump(scan).data
コード例 #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
コード例 #8
0
ファイル: test_frontendtasks.py プロジェクト: quarkslab/irma
 def test_scan_launch(self, m_async_call):
     arg = "whatever"
     module.scan_launch(arg)
     m_async_call.assert_called()