Esempio n. 1
0
def _cleanup_options():
    """
    Cleanup configuration attributes.
    """
    if conf.agent:
        conf.agent = re.sub(r"[\r\n]", "", conf.agent)

    if conf.cookie:
        conf.cookie = re.sub(r"[\r\n]", "", conf.cookie)
        conf.cookie = extract_cookies(conf.cookie)

    if conf.delay:
        conf.delay = float(conf.delay)

    if conf.retry:
        conf.retry = min(conf.retry, 10)

    if conf.url:
        conf.url = conf.url.strip()

    if conf.poc and conf.poc.lower().startswith('ssvid-'):
        conf.poc = conf.poc.lower()

    if conf.url_file:
        conf.url_file = os.path.expanduser(conf.url_file)
        check_file(conf.url_file)

    if conf.plugins:
        conf.plugins = conf.plugins.split(',')
        conf.plugins = [i.strip() for i in conf.plugins]
        conf.plugins = list(set(conf.plugins))

    if conf.connect_back_port:
        conf.connect_back_port = int(conf.connect_back_port)
Esempio n. 2
0
def _cleanup_options():
    """
    Cleanup configuration attributes.
    """
    if conf.agent:
        conf.agent = re.sub(r"[\r\n]", "", conf.agent)

    if conf.cookie:
        if isinstance(conf.cookie, str):
            conf.cookie = re.sub(r"[\r\n]", "", conf.cookie)
            conf.cookie = extract_cookies(conf.cookie)
        elif not isinstance(conf.cookie, dict):
            raise PocsuiteHeaderTypeException(
                'Does not support type for cookie')
    if conf.delay:
        conf.delay = float(conf.delay)

    if conf.retry:
        conf.retry = min(conf.retry, 10)

    if conf.url:
        if isinstance(conf.url, str):
            conf.url = [conf.url]
        conf.url = [x.strip() for x in conf.url]

    if conf.poc:
        if isinstance(conf.poc, str):
            conf.poc = [conf.poc]
        conf.poc = [
            poc.lower() if poc.lower().startswith('ssvid-') else poc
            for poc in conf.poc
        ]

    if conf.url_file:
        conf.url_file = os.path.expanduser(conf.url_file)
        check_file(conf.url_file)

    if conf.plugins:
        conf.plugins = conf.plugins.split(',')
        conf.plugins = [i.strip() for i in conf.plugins]
        conf.plugins = list(set(conf.plugins))

    if conf.connect_back_port:
        conf.connect_back_port = int(conf.connect_back_port)

    conf.origin_socks = None
Esempio n. 3
0
def _set_pocs_modules():
    # TODO
    # load poc scripts .pyc file support
    if conf.poc:
        # step1. load system packed poc from pocsuite3/pocs folder
        exists_poc_with_ext = list(
            filter(lambda x: x not in ['__init__.py', '__init__.pyc'],
                   os.listdir(paths.POCSUITE_POCS_PATH)))
        exists_pocs = dict([os.path.splitext(x) for x in exists_poc_with_ext])
        for poc in conf.poc:
            load_poc_sucess = False
            if any([poc in exists_poc_with_ext, poc in exists_pocs]):
                poc_name, poc_ext = os.path.splitext(poc)
                if poc_ext in ['.py', '.pyc']:
                    file_path = os.path.join(paths.POCSUITE_POCS_PATH, poc)
                else:
                    file_path = os.path.join(paths.POCSUITE_POCS_PATH,
                                             poc + exists_pocs.get(poc))
                if file_path:
                    info_msg = "loading PoC script '{0}'".format(file_path)
                    logger.info(info_msg)
                    load_poc_sucess = load_file_to_module(file_path)

            # step2. load poc from given file path
            try:
                if not load_poc_sucess:
                    if not poc.startswith('ssvid-') and check_file(poc):
                        info_msg = "loading PoC script '{0}'".format(poc)
                        logger.info(info_msg)
                        load_poc_sucess = load_file_to_module(poc)
            except PocsuiteSystemException:
                logger.error('PoC file "{0}" not found'.format(repr(poc)))
                continue

            # step3. load poc from seebug website using plugin 'poc_from_seebug'
            if not load_poc_sucess:
                if poc.startswith('ssvid-'):
                    info_msg = "loading Poc script 'https://www.seebug.org/vuldb/{0}'".format(
                        poc)
                    logger.info(info_msg)
                    if "poc_from_seebug" not in conf.plugins:
                        conf.plugins.append('poc_from_seebug')
                    load_poc_sucess = True

    load_keyword_poc_sucess = False
    if conf.vul_keyword:
        # step4. load poc with vul_keyword search seebug website
        info_msg = "loading PoC script from seebug website using search keyword '{0}' ".format(
            conf.vul_keyword)
        logger.info(info_msg)

        conf.plugins.append('poc_from_seebug')
        load_keyword_poc_sucess = True

    if all([not kb.registered_pocs, not load_keyword_poc_sucess]):
        error_msg = "no PoC loaded, please check your PoC file"
        logger.error(error_msg)
        raise PocsuiteSystemException(error_msg)
Esempio n. 4
0
def _set_pocs_modules():
    # TODO
    # load poc scripts .pyc file support
    if conf.poc:
        load_poc_sucess = False
        # step1. load system packed poc from pocsuite3/pocs folder
        for found in glob.glob(os.path.join(paths.POCSUITE_POCS_PATH,
                                            "*.py*")):
            dirname, filename = os.path.split(found)
            poc_name = os.path.splitext(filename)[0]
            for poc in conf.poc:
                if found.endswith(('__init__.py', '__init__.pyc')):
                    continue
                if poc in (filename, poc_name):
                    info_msg = "loading PoC script '{0}'".format(found)
                    logger.info(info_msg)
                    load_poc_sucess = load_file_to_module(found)

        # step2. load poc from given file path
        try:
            if not load_poc_sucess:
                for poc in conf.poc:
                    if not poc.startswith('ssvid-') and check_file(poc):
                        info_msg = "loading PoC script '{0}'".format(poc)
                        logger.info(info_msg)
                        load_poc_sucess = load_file_to_module(poc)
        except PocsuiteSystemException:
            logger.error('PoC file "{0}" not found'.format(repr(conf.poc)))
            raise SystemExit

        # step3. load poc from seebug website using plugin 'poc_from_seebug'
        if not load_poc_sucess:
            for poc in conf.poc:
                if poc.startswith('ssvid-'):
                    info_msg = "loading Poc script 'https://www.seebug.org/vuldb/{0}'".format(
                        poc)
                    logger.info(info_msg)
                    if "poc_from_seebug" not in conf.plugins:
                        conf.plugins.append('poc_from_seebug')
                    load_poc_sucess = True

    if conf.vul_keyword:
        # step4. load poc with vul_keyword search seebug website
        info_msg = "loading PoC script from seebug website using search keyword '{0}' ".format(
            conf.vul_keyword)
        logger.info(info_msg)

        conf.plugins.append('poc_from_seebug')
        load_poc_sucess = True

    if (conf.poc or conf.vul_keyword) and not load_poc_sucess:
        error_msg = ""
        logger.error(error_msg)
        raise PocsuiteSyntaxException(error_msg)