Ejemplo n.º 1
0
 def __str__(self):
     status = "Unknown"
     if self.module:
         from sslscan.module import STATUS_NAMES
         status = STATUS_NAMES.get(self.module.status, status)
     return "Unable to load module '{}' with status '{}'".format(
         self.name, status)
Ejemplo n.º 2
0
def print_module_info(args):
    load_modules()
    scanner = Scanner()

    mod_mgr = scanner.get_module_manager()
    modules = mod_mgr.get_modules(base_class=args.base_class)

    module_found = None
    for module in modules:
        if module.name == args.module_name:
            module_found = module

    if module_found is None:
        logger.error("Unable to display help. Module '{0}' not found.".format(
            args.module_name))
        return 1

    module = module_found(scanner=scanner)

    heading = "Module: {}".format(args.module_name)
    print("")
    print(heading)
    print("=" * len(heading))
    print("")

    if module.alias and len(module.alias) > 0:
        print("Alias:")
        print("")
        for alias in module.alias:
            print("* {}".format(alias))
        print("")

    print("Status: {}".format(STATUS_NAMES.get(module.status, "Unknown")))
    print("")
    if module.status_messages:
        for msg in module.status_messages:
            print("* {}".format(msg))
    print("")

    text = module.__doc__
    if text is None:
        text = ""

    text = textwrap.dedent(text)
    text = text.lstrip("\n")

    print(textwrap.fill(text, width=80))
    print("")

    for name in module.config.get_option_names():
        option = module.config.get_option(name)

        text = option.help
        if text is None or text.strip() == "":
            text = "No help text available"

        indent_text = "{0} - ".format(option.name)

        indent_len = len(indent_text)

        print(textwrap.fill(text, initial_indent=indent_text))

        print("{}Type: {}".format(" " * indent_len, option.type))

        print("{}Default: {}".format(" " * indent_len, option.default))

        values = option.values
        if values is not None:
            if callable(values):
                values = values(option)
            print(
                textwrap.fill("Values: {0}".format(", ".join(values)),
                              initial_indent=" " * indent_len,
                              subsequent_indent=" " * indent_len))

    print("")

    return 0
Ejemplo n.º 3
0
def run_scan(args):
    load_modules()
    scanner = Scanner()

    # Enable groups of methods
    if args.enable_ssl:
        for name in ["ssl2", "ssl3"]:
            scanner.config.set_value(name, True)
    if args.enable_tls:
        for name in ["tls10", "tls11", "tls12"]:
            scanner.config.set_value(name, True)

    args_dict = vars(args)
    opt_names = ["ssl2", "ssl3", "tls10", "tls11", "tls12", "dtls10", "dtls12"]
    for name in list(opt_names):
        opt_names.append("no-%s" % name)

    for name in opt_names:
        if name not in args_dict:
            continue
        if not args_dict.get(name):
            continue
        logger.debug("Set %s = %s", name, str(args_dict.get(name)))
        scanner.config.set_value(name, True)

    if len(args.scan) == 0:
        logger.error("No scan module specified")
        return 1

    enabled_ssl_method_found = False
    for name in ["ssl2", "ssl3", "tls10", "tls11", "tls12"]:
        if scanner.config.get_value(name):
            enabled_ssl_method_found = True
            break

    enabled_dtls_method_found = False
    for name in ["dtls10", "dtls12"]:
        if scanner.config.get_value(name):
            enabled_dtls_method_found = True
            break
    if not enabled_ssl_method_found and not enabled_dtls_method_found:
        logger.error("No SSL/TLS or DTLS method enabled. "
                     "Example: Use --tls10 to enable TLS 1.0")
        return 1

    if enabled_ssl_method_found and enabled_dtls_method_found:
        logger.error("SSL/TLS and DTLS are not compatible.")
        return 1

    for module in args.scan:
        name, sep, options = module.partition(":")
        try:
            scanner.append_load(name, options, base_class=BaseScan)
        except ModuleNotFound as e:
            logger.error("Scan module '%s' not found", e.name)
            return 1
        except ModuleLoadStatus as e:
            status_msg = "unknown"
            if e.module:
                status_msg = STATUS_NAMES.get(e.module.status, status_msg)
            logger.error("Unable to load module '%s' with status '%s'", e.name,
                         status_msg)
            return 1
        except ConfigOptionNotFound as e:
            logger.error(
                "Unrecognised command line option '%s' for scan module '%s'.",
                e.name, name)
            return 1

    reports = args.report
    if len(reports) == 0:
        default_report = "term:rating=builtin.0_5"
        logger.debug("No report module specified. Using: %s" % default_report)
        reports.append(default_report)

    for module in reports:
        name, sep, options = module.partition(":")
        try:
            scanner.append_load(name, options, base_class=BaseReport)
        except ModuleNotFound as e:
            logger.error("Report module '%s' not found", e.name)
            return 1
        except ModuleLoadStatus as e:
            status_msg = "unknown"
            if e.module:
                status_msg = STATUS_NAMES.get(e.module.status, status_msg)
            logger.error("Unable to load module '%s' with status '%s'", e.name,
                         status_msg)
            return 1
        except OptionValueError as e:
            logger.error(
                "An error occurred while setting the value of the configuration"
                " option '{1}' to '{2}' for module '{0}'.".format(
                    name, e.option.name, e.value))
            return 1
        except ConfigOptionNotFound as e:
            logger.error(
                "Unrecognised command line option '%s' for report module '%s'.",
                e.name, name)
            return 1

    for host_uri in args.host_uris:
        module = scanner.load_handler_from_uri(host_uri)
        scanner.set_handler(module)
        scanner.reset_knowledge_base()
        scanner.run()

    return 0
Ejemplo n.º 4
0
def print_module_info(args):
    load_modules()
    scanner = Scanner()

    mod_mgr = scanner.get_module_manager()
    modules = mod_mgr.get_modules(base_class=args.base_class)

    module_found = None
    for module in modules:
        if module.name == args.module_name:
            module_found = module

    if module_found is None:
        logger.error(
            "Unable to display help. Module '{0}' not found.".format(
                args.module_name
            )
        )
        return 1

    module = module_found(scanner=scanner)

    heading = "Module: {}".format(args.module_name)
    print("")
    print(heading)
    print("="*len(heading))
    print("")

    if module.alias and len(module.alias) > 0:
        print("Alias:")
        print("")
        for alias in module.alias:
            print("* {}".format(alias))
        print("")

    print(
        "Status: {}".format(
            STATUS_NAMES.get(module.status, "Unknown")
        )
    )
    print("")
    if module.status_messages:
        for msg in module.status_messages:
            print("* {}".format(msg))
    print("")

    text = module.__doc__
    if text is None:
        text = ""

    text = textwrap.dedent(text)
    text = text.lstrip("\n")

    print(textwrap.fill(text, width=80))
    print("")

    for name in module.config.get_option_names():
        option = module.config.get_option(name)

        text = option.help
        if text is None or text.strip() == "":
            text = "No help text available"

        indent_text = "{0} - ".format(
            option.name
        )

        indent_len = len(indent_text)

        print(
            textwrap.fill(
                text,
                initial_indent=indent_text
            )
        )

        print(
            "{}Type: {}".format(
                " "*indent_len,
                option.type
            )
        )

        print(
            "{}Default: {}".format(
                " "*indent_len,
                option.default
            )
        )

        values = option.values
        if values is not None:
            if callable(values):
                values = values(option)
            print(
                textwrap.fill(
                    "Values: {0}".format(
                        ", ".join(values)
                    ),
                    initial_indent=" "*indent_len,
                    subsequent_indent=" "*indent_len
                )
            )

    print("")

    return 0
Ejemplo n.º 5
0
def run_scan(args):
    load_modules()
    scanner = Scanner()

    # Enable groups of methods
    if args.enable_ssl:
        for name in ["ssl2", "ssl3"]:
            scanner.config.set_value(name, True)
    if args.enable_tls:
        for name in ["tls10", "tls11", "tls12"]:
            scanner.config.set_value(name, True)

    args_dict = vars(args)
    opt_names = ["ssl2", "ssl3", "tls10", "tls11", "tls12", "dtls10", "dtls12"]
    for name in list(opt_names):
        opt_names.append("no-%s" % name)

    for name in opt_names:
        if name not in args_dict:
            continue
        if not args_dict.get(name):
            continue
        logger.debug("Set %s = %s", name, str(args_dict.get(name)))
        scanner.config.set_value(name, True)

    if len(args.scan) == 0:
        logger.error("No scan module specified")
        return 1

    enabled_ssl_method_found = False
    for name in ["ssl2", "ssl3", "tls10", "tls11", "tls12"]:
        if scanner.config.get_value(name):
            enabled_ssl_method_found = True
            break

    enabled_dtls_method_found = False
    for name in ["dtls10", "dtls12"]:
        if scanner.config.get_value(name):
            enabled_dtls_method_found = True
            break
    if not enabled_ssl_method_found and not enabled_dtls_method_found:
        logger.error(
            "No SSL/TLS or DTLS method enabled. "
            "Example: Use --tls10 to enable TLS 1.0"
        )
        return 1

    if enabled_ssl_method_found and enabled_dtls_method_found:
        logger.error(
            "SSL/TLS and DTLS are not compatible."
        )
        return 1

    for module in args.scan:
        name, sep, options = module.partition(":")
        try:
            scanner.append_load(name, options, base_class=BaseScan)
        except ModuleNotFound as e:
            logger.error("Scan module '%s' not found", e.name)
            return 1
        except ModuleLoadStatus as e:
            status_msg = "unknown"
            if e.module:
                status_msg = STATUS_NAMES.get(e.module.status, status_msg)
            logger.error("Unable to load module '%s' with status '%s'", e.name, status_msg)
            return 1
        except ConfigOptionNotFound as e:
            logger.error(
                "Unrecognised command line option '%s' for scan module '%s'.",
                e.name,
                name
            )
            return 1

    reports = args.report
    if len(reports) == 0:
        default_report = "term:rating=builtin.0_5"
        logger.debug(
            "No report module specified. Using: %s" % default_report
        )
        reports.append(default_report)

    for module in reports:
        name, sep, options = module.partition(":")
        try:
            scanner.append_load(name, options, base_class=BaseReport)
        except ModuleNotFound as e:
            logger.error("Report module '%s' not found", e.name)
            return 1
        except ModuleLoadStatus as e:
            status_msg = "unknown"
            if e.module:
                status_msg = STATUS_NAMES.get(e.module.status, status_msg)
            logger.error("Unable to load module '%s' with status '%s'", e.name, status_msg)
            return 1
        except OptionValueError as e:
            logger.error(
                "An error occurred while setting the value of the configuration"
                " option '{1}' to '{2}' for module '{0}'.".format(
                    name,
                    e.option.name,
                    e.value
                )
            )
            return 1
        except ConfigOptionNotFound as e:
            logger.error(
                "Unrecognised command line option '%s' for report module '%s'.",
                e.name,
                name
            )
            return 1

    for host_uri in args.host_uris:
        module = scanner.load_handler_from_uri(host_uri)
        scanner.set_handler(module)
        scanner.reset_knowledge_base()
        scanner.run()

    return 0
Ejemplo n.º 6
0
 def __str__(self):
     status = "Unknown"
     if self.module:
         from sslscan.module import STATUS_NAMES
         status = STATUS_NAMES.get(self.module.status, status)
     return "Unable to load module '{}' with status '{}'".format(self.name, status)