コード例 #1
0
ファイル: output_hub.py プロジェクト: yunsoul/sslyze
    def command_line_parsed(
        self,
        available_plugins: Set[Type[Plugin]],
        args_command_list: Any,
        malformed_servers: List[ServerStringParsingError],
    ) -> None:
        # Configure the console output
        should_print_text_results = (
            not args_command_list.quiet and args_command_list.xml_file != "-" and args_command_list.json_file != "-"
        )
        if should_print_text_results:
            self._output_generator_list.append(ConsoleOutputGenerator(sys.stdout))

        # Configure the JSON output
        if args_command_list.json_file:
            json_file_to = (
                sys.stdout
                if args_command_list.json_file == "-"
                else open(args_command_list.json_file, "wt", encoding="utf-8")
            )
            self._output_generator_list.append(JsonOutputGenerator(json_file_to))  # type: ignore

        # Configure the XML output
        if args_command_list.xml_file:
            xml_file_to = (
                sys.stdout
                if args_command_list.xml_file == "-"
                else open(args_command_list.xml_file, "wt", encoding="utf-8")
            )
            self._output_generator_list.append(XmlOutputGenerator(xml_file_to))  # type: ignore

        # Forward the notification
        for out_generator in self._output_generator_list:
            out_generator.command_line_parsed(available_plugins, args_command_list, malformed_servers)
コード例 #2
0
    def command_line_parsed(self, available_plugins, args_command_list,
                            malformed_servers):
        # type: (Set[Type[Plugin]], Any, List[ServerStringParsingError]) -> None
        # Configure the console output
        should_print_text_results = not args_command_list.quiet and args_command_list.xml_file != '-' \
                                    and args_command_list.json_file != '-'
        if should_print_text_results:
            self._output_generator_list.append(
                ConsoleOutputGenerator(sys.stdout))

        # Configure the JSON output
        if args_command_list.json_file:
            json_file_to = sys.stdout if args_command_list.json_file == '-' else open(
                args_command_list.json_file, 'wt')
            self._output_generator_list.append(
                JsonOutputGenerator(json_file_to))  # type: ignore

        # Configure the XML output
        if args_command_list.xml_file:
            xml_file_to = sys.stdout if args_command_list.xml_file == '-' else open(
                args_command_list.xml_file, 'wt')
            self._output_generator_list.append(
                XmlOutputGenerator(xml_file_to))  # type: ignore

        # Forward the notification
        for out_generator in self._output_generator_list:
            out_generator.command_line_parsed(available_plugins,
                                              args_command_list,
                                              malformed_servers)
コード例 #3
0
    def command_line_parsed(self, available_plugins, args_command_list):
        # Configure the console output
        should_print_text_results = not args_command_list.quiet and args_command_list.xml_file != '-' \
                                    and args_command_list.json_file != '-'
        if should_print_text_results:
            self._output_generator_list.append(
                ConsoleOutputGenerator(sys.stdout))

        # Configure the JSON output
        json_file_to = None
        if args_command_list.json_file:
            json_file_to = sys.stdout if args_command_list.json_file == '-' else open(
                args_command_list.json_file, 'w')
        if json_file_to:
            self._output_generator_list.append(
                JsonOutputGenerator(json_file_to))

        # Configure the XML output
        xml_file_to = None
        if args_command_list.xml_file:
            xml_file_to = sys.stdout if args_command_list.xml_file == '-' else open(
                args_command_list.xml_file, 'w')
        if xml_file_to:
            self._output_generator_list.append(XmlOutputGenerator(xml_file_to))

        # Forward the notification
        for out_generator in self._output_generator_list:
            out_generator.command_line_parsed(available_plugins,
                                              args_command_list)
コード例 #4
0
    def test_with_http_tunneling(self):
        output_file = StringIO()
        generator = XmlOutputGenerator(output_file)

        # When scanning through a proxy, we do not know the final server's IP address
        # This makes sure the XML output properly handles that
        tunneling_settings = HttpConnectTunnelingSettings('prôxyé.com', 3128)
        server_info = MockServerConnectivityInfo(http_tunneling_settings=tunneling_settings)

        # noinspection PyTypeChecker
        server_scan = CompletedServerScan(server_info, [])
        generator.server_scan_completed(server_scan)
        generator.scans_completed(1.3)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the output displayed the tunneling settings
        self.assertIn('httpsTunnelHostname="{}"'.format(tunneling_settings.hostname), received_output)
        self.assertIn('httpsTunnelPort="{}"'.format(tunneling_settings.port), received_output)
コード例 #5
0
    def test_with_http_tunneling(self):
        output_file = StringIO()
        generator = XmlOutputGenerator(output_file)

        # When scanning through a proxy, we do not know the final server's IP address
        # This makes sure the XML output properly handles that
        tunneling_settings = HttpConnectTunnelingSettings('prôxyé.com', 3128)
        server_info = MockServerConnectivityInfo(http_tunneling_settings=tunneling_settings)

        # noinspection PyTypeChecker
        server_scan = CompletedServerScan(server_info, [])
        generator.server_scan_completed(server_scan)
        generator.scans_completed(1.3)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the output displayed the tunneling settings
        self.assertIn('httpsTunnelHostname="{}"'.format(tunneling_settings.hostname), received_output)
        self.assertIn('httpsTunnelPort="{}"'.format(tunneling_settings.port), received_output)
コード例 #6
0
    def test(self):
        """The final output only gets written at the end, when calling scans_completed(). Hence we need to call all the
        methods in the right order and validate the final output at the end.
        """
        output_file = StringIO()
        generator = XmlOutputGenerator(output_file)

        generator.command_line_parsed(None, MockCommandLineValues())

        failed_scan = FailedServerScan(
            server_string=u'unibadeéè.com',
            connection_exception=ServerConnectivityError(
                error_msg=u'Some érrôr'))
        generator.server_connectivity_test_failed(failed_scan)

        server_info = MockServerConnectivityInfo()
        generator.server_connectivity_test_succeeded(server_info)

        generator.scans_started()

        plugin_xml_out_1 = Element(u'plugin1', attrib={'test1': 'value1'})
        plugin_xml_out_1.text = u'Plugin ûnicôdé output'
        plugin_result_1 = MockPluginResult('plugin1', u'', plugin_xml_out_1)
        plugin_xml_out_2 = Element(u'plugin2', attrib={'test2': 'value2'})
        plugin_xml_out_2.text = u'other plugin Output'
        plugin_result_2 = MockPluginResult('plugin2', u'', plugin_xml_out_2)

        # noinspection PyTypeChecker
        server_scan = CompletedServerScan(server_info,
                                          [plugin_result_1, plugin_result_2])
        generator.server_scan_completed(server_scan)

        scan_time = 1.3
        generator.scans_completed(scan_time)

        received_output = unicode(output_file.getvalue(), 'utf-8')
        output_file.close()

        # Ensure the output properly listed the connectivity error with unicode escaped as \u sequences
        self.assertIn(u'unibadeéè.com', received_output)
        self.assertIn(u'Some érrôr', received_output)

        # Ensure the output properly listed the online domain
        self.assertIn(server_info.hostname, received_output)
        self.assertIn(str(server_info.port), received_output)
        self.assertIn(server_info.ip_address, received_output)

        # Ensure the output displayed the plugin's XML output
        self.assertIn(plugin_result_1.plugin_command, received_output)
        self.assertIn(plugin_result_2.plugin_command, received_output)
        self.assertIn(plugin_result_1.as_xml().text, received_output)
        self.assertIn(plugin_result_2.as_xml().text, received_output)

        # Ensure the console output displayed the total scan time
        self.assertIn('totalScanTime="{}"'.format(scan_time), received_output)
        self.assertIn(
            'networkTimeout="{}"'.format(MockCommandLineValues().timeout),
            received_output)
        self.assertIn(
            'networkMaxRetries="{}"'.format(
                MockCommandLineValues().nb_retries), received_output)
コード例 #7
0
    def test(self):
        """The final output only gets written at the end, when calling scans_completed(). Hence we need to call all the
        methods in the right order and validate the final output at the end.
        """
        output_file = StringIO()
        generator = XmlOutputGenerator(output_file)

        failed_parsing = ServerStringParsingError(
            supplied_server_string='www.badpãrsing.com',
            error_message='Pãrsing error'
        )
        generator.command_line_parsed(set(), MockCommandLineValues(), [failed_parsing])

        failed_scan = ServerConnectivityError(
            server_info=MockServerConnectivityTester(hostname='unibadeéè.com'),
            error_message='Some érrôr'
        )
        generator.server_connectivity_test_failed(failed_scan)

        server_info = MockServerConnectivityInfo()
        generator.server_connectivity_test_succeeded(server_info)

        generator.scans_started()

        plugin_xml_out_1 = Element('plugin1', attrib={'test1': 'value1'})
        plugin_xml_out_1.text = 'Plugin ûnicôdé output'
        plugin_result_1 = MockPluginScanResult(server_info, MockPluginScanCommandOne(), '', plugin_xml_out_1)
        plugin_xml_out_2 = Element('plugin2', attrib={'test2': 'value2'})
        plugin_xml_out_2.text = 'other plugin Output'
        plugin_result_2 = MockPluginScanResult(server_info, MockPluginScanCommandTwo(), '', plugin_xml_out_2)

        server_scan = CompletedServerScan(server_info, [plugin_result_1, plugin_result_2])
        generator.server_scan_completed(server_scan)

        scan_time = 1.3
        generator.scans_completed(scan_time)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the output properly listed the parsing error
        self.assertIn('www.badpãrsing.com', received_output)
        self.assertIn('Pãrsing error', received_output)

        # Ensure the output properly listed the connectivity error
        self.assertIn('unibadeéè.com', received_output)
        self.assertIn('Some érrôr', received_output)

        # Ensure the output properly listed the online domain
        self.assertIn(server_info.hostname, received_output)
        self.assertIn(str(server_info.port), received_output)
        self.assertIn(server_info.ip_address, received_output)

        # Ensure the output displayed the plugin's XML output
        self.assertIn(plugin_result_1.scan_command.get_cli_argument(), received_output)
        self.assertIn(plugin_result_2.scan_command.get_cli_argument(), received_output)
        self.assertIn(plugin_result_1.as_xml().text, received_output)
        self.assertIn(plugin_result_2.as_xml().text, received_output)

        # Ensure the console output displayed the total scan time
        self.assertIn('totalScanTime="{}"'.format(scan_time), received_output)
コード例 #8
0
    def test(self):
        """The final output only gets written at the end, when calling scans_completed(). Hence we need to call all the
        methods in the right order and validate the final output at the end.
        """
        output_file = StringIO()
        generator = XmlOutputGenerator(output_file)

        generator.command_line_parsed(None, MockCommandLineValues())

        failed_scan = FailedServerScan(server_string='unibadeéè.com',
                                       connection_exception=ServerConnectivityError(error_msg='Some érrôr'))
        generator.server_connectivity_test_failed(failed_scan)

        server_info = MockServerConnectivityInfo()
        generator.server_connectivity_test_succeeded(server_info)

        generator.scans_started()

        plugin_xml_out_1 = Element('plugin1', attrib={'test1': 'value1'})
        plugin_xml_out_1.text = 'Plugin ûnicôdé output'
        plugin_result_1 = MockPluginScanResult(server_info, MockPluginScanCommandOne(), '', plugin_xml_out_1)
        plugin_xml_out_2 = Element('plugin2', attrib={'test2': 'value2'})
        plugin_xml_out_2.text = 'other plugin Output'
        plugin_result_2 = MockPluginScanResult(server_info, MockPluginScanCommandTwo(), '', plugin_xml_out_2)

        # noinspection PyTypeChecker
        server_scan = CompletedServerScan(server_info, [plugin_result_1, plugin_result_2])
        generator.server_scan_completed(server_scan)

        scan_time = 1.3
        generator.scans_completed(scan_time)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the output properly listed the connectivity error with unicode escaped as \u sequences
        self.assertIn('unibadeéè.com', received_output)
        self.assertIn('Some érrôr', received_output)

        # Ensure the output properly listed the online domain
        self.assertIn(server_info.hostname, received_output)
        self.assertIn(str(server_info.port), received_output)
        self.assertIn(server_info.ip_address, received_output)

        # Ensure the output displayed the plugin's XML output
        self.assertIn(plugin_result_1.scan_command.get_cli_argument(), received_output)
        self.assertIn(plugin_result_2.scan_command.get_cli_argument(), received_output)
        self.assertIn(plugin_result_1.as_xml().text, received_output)
        self.assertIn(plugin_result_2.as_xml().text, received_output)

        # Ensure the console output displayed the total scan time
        self.assertIn('totalScanTime="{}"'.format(scan_time), received_output)
        self.assertIn('networkTimeout="{}"'.format(MockCommandLineValues().timeout), received_output)
        self.assertIn('networkMaxRetries="{}"'.format(MockCommandLineValues().nb_retries), received_output)
コード例 #9
0
    def test(self):
        """The final output only gets written at the end, when calling scans_completed(). Hence we need to call all the
        methods in the right order and validate the final output at the end.
        """
        output_file = StringIO()
        generator = XmlOutputGenerator(output_file)

        failed_parsing = ServerStringParsingError(
            supplied_server_string='www.badpãrsing.com',
            error_message='Pãrsing error'
        )
        generator.command_line_parsed(set(), MockCommandLineValues(), [failed_parsing])

        failed_scan = ServerConnectivityError(
            server_info=MockServerConnectivityTester(hostname='unibadeéè.com'),
            error_message='Some érrôr'
        )
        generator.server_connectivity_test_failed(failed_scan)

        server_info = MockServerConnectivityInfo()
        generator.server_connectivity_test_succeeded(server_info)

        generator.scans_started()

        plugin_xml_out_1 = Element('plugin1', attrib={'test1': 'value1'})
        plugin_xml_out_1.text = 'Plugin ûnicôdé output'
        plugin_result_1 = MockPluginScanResult(server_info, MockPluginScanCommandOne(), '', plugin_xml_out_1)
        plugin_xml_out_2 = Element('plugin2', attrib={'test2': 'value2'})
        plugin_xml_out_2.text = 'other plugin Output'
        plugin_result_2 = MockPluginScanResult(server_info, MockPluginScanCommandTwo(), '', plugin_xml_out_2)

        server_scan = CompletedServerScan(server_info, [plugin_result_1, plugin_result_2])
        generator.server_scan_completed(server_scan)

        scan_time = 1.3
        generator.scans_completed(scan_time)

        received_output = output_file.getvalue()
        output_file.close()

        # Ensure the output properly listed the parsing error
        assert 'www.badpãrsing.com' in received_output
        assert 'Pãrsing error' in received_output

        # Ensure the output properly listed the connectivity error
        assert 'unibadeéè.com' in received_output
        assert 'Some érrôr' in received_output

        # Ensure the output properly listed the online domain
        assert server_info.hostname in received_output
        assert str(server_info.port) in received_output
        assert server_info.ip_address in received_output

        # Ensure the output displayed the plugin's XML output
        assert plugin_result_1.scan_command.get_cli_argument() in received_output
        assert plugin_result_2.scan_command.get_cli_argument() in received_output
        assert plugin_result_1.as_xml().text in received_output
        assert plugin_result_2.as_xml().text in received_output

        # Ensure the console output displayed the total scan time
        assert 'totalScanTime="{}"'.format(scan_time) in received_output