Beispiel #1
0
    def test_prepare_alive_test_not_supplied_as_enum(self, mock_kb):
        w = DummyDaemon()

        alive_test_out = {
            "1.3.6.1.4.1.25623.1.0.100315:1:checkbox:Do a TCP ping": "no",
            "1.3.6.1.4.1.25623.1.0.100315:2:checkbox:TCP ping tries also TCP-SYN ping": "no",
            "1.3.6.1.4.1.25623.1.0.100315:7:checkbox:TCP ping tries only TCP-SYN ping": "no",
            "1.3.6.1.4.1.25623.1.0.100315:3:checkbox:Do an ICMP ping": "yes",
            "1.3.6.1.4.1.25623.1.0.100315:4:checkbox:Use ARP": "no",
            "1.3.6.1.4.1.25623.1.0.100315:5:checkbox:Mark unrechable Hosts as dead (not scanning)": "yes",
        }

        t_opt = {'alive_test_methods': '1', 'icmp': '1'}
        w.scan_collection.get_target_options = MagicMock(return_value=t_opt)

        ov_setting = {'some_setting': 1}

        with patch.object(Openvas, 'get_settings', return_value=ov_setting):
            p = PreferenceHandler('1234-1234', mock_kb, w.scan_collection, None)
            p._nvts_params = {}
            p.scan_id = '456-789'
            p.kbdb.add_scan_preferences = MagicMock()
            p.prepare_alive_test_option_for_openvas()

            self.assertEqual(p._nvts_params, alive_test_out)
Beispiel #2
0
    def test_set_alive_pinghost(self, mock_kb):
        w = DummyDaemon()

        alive_test_out = [
            "1.3.6.1.4.1.25623.1.0.100315:1:checkbox:Do a TCP ping|||no",
            "1.3.6.1.4.1.25623.1.0.100315:2:checkbox:TCP ping tries also TCP-SYN ping|||no",
            "1.3.6.1.4.1.25623.1.0.100315:7:checkbox:TCP ping tries only TCP-SYN ping|||no",
            "1.3.6.1.4.1.25623.1.0.100315:3:checkbox:Do an ICMP ping|||yes",
            "1.3.6.1.4.1.25623.1.0.100315:4:checkbox:Use ARP|||no",
            "1.3.6.1.4.1.25623.1.0.100315:5:checkbox:Mark unrechable Hosts as dead (not scanning)|||yes",
        ]

        t_opt = {'alive_test': 2}
        w.scan_collection.get_target_options = MagicMock(return_value=t_opt)

        ov_setting = {'some_setting': 1}

        with patch.object(Openvas, 'get_settings', return_value=ov_setting):
            p = PreferenceHandler('1234-1234', mock_kb, w.scan_collection,
                                  None)
            p._nvts_params = {}
            p._openvas_scan_id = '456-789'
            p.kbdb.add_scan_preferences = MagicMock()
            p.prepare_alive_test_option_for_openvas()

            for key, value in p._nvts_params.items():
                self.assertTrue(
                    "{0}|||{1}".format(key, value) in alive_test_out)
Beispiel #3
0
    def test_prepare_nvt_prefs_no_prefs(self, mock_kb):
        w = DummyDaemon()

        p = PreferenceHandler('456-789', mock_kb, w.scan_collection, None)
        p._nvts_params = {}
        p.kbdb.add_scan_preferences = MagicMock()
        p.prepare_nvt_preferences()

        p.kbdb.add_scan_preferences.assert_not_called()
Beispiel #4
0
    def test_prepare_nvt_prefs_no_prefs(self, mock_kb):
        dummy = DummyDaemon()

        p_handler = PreferenceHandler(
            '456-789', mock_kb, dummy.scan_collection, None
        )
        p_handler._nvts_params = {}  # pylint: disable = protected-access
        p_handler.kbdb.add_scan_preferences = MagicMock()
        p_handler.prepare_nvt_preferences()

        p_handler.kbdb.add_scan_preferences.assert_not_called()
Beispiel #5
0
    def test_prepare_alive_test_no_enum_no_alive_test(self, mock_kb):
        w = DummyDaemon()

        t_opt = {'alive_test_methods': '1', 'icmp': '0'}
        w.scan_collection.get_target_options = MagicMock(return_value=t_opt)

        ov_setting = {'some_setting': 1}

        with patch.object(Openvas, 'get_settings', return_value=ov_setting):
            p = PreferenceHandler('1234-1234', mock_kb, w.scan_collection, None)
            p._nvts_params = {}
            p.scan_id = '456-789'
            p.kbdb.add_scan_preferences = MagicMock()
            p.prepare_alive_test_option_for_openvas()

            p.kbdb.add_scan_preferences.assert_not_called()
Beispiel #6
0
    def test_prepare_nvt_prefs(self, mock_kb):
        w = DummyDaemon()

        alive_test_out = [
            "1.3.6.1.4.1.25623.1.0.100315:1:checkbox:Do a TCP ping|||no"
        ]

        p = PreferenceHandler('1234-1234', mock_kb, w.scan_collection, None)
        p._nvts_params = {
            "1.3.6.1.4.1.25623.1.0.100315:1:checkbox:Do a TCP ping": "no"
        }
        p.kbdb.add_scan_preferences = MagicMock()
        p.prepare_nvt_preferences()

        p.kbdb.add_scan_preferences.assert_called_with(
            p.scan_id,
            alive_test_out,
        )
Beispiel #7
0
    def test_set_alive_no_invalid_alive_test_no_enum(self, mock_kb):
        dummy = DummyDaemon()

        t_opt = {'alive_test_methods': '1', 'icmp': '-1'}
        dummy.scan_collection.get_target_options = MagicMock(return_value=t_opt)

        ov_setting = {'some_setting': 1}

        with patch.object(Openvas, 'get_settings', return_value=ov_setting):
            p_handler = PreferenceHandler(
                '1234-1234', mock_kb, dummy.scan_collection, None
            )
            p_handler._nvts_params = {}  # pylint: disable = protected-access
            p_handler.scan_id = '456-789'
            p_handler.kbdb.add_scan_preferences = MagicMock()
            p_handler.prepare_alive_test_option_for_openvas()

            p_handler.kbdb.add_scan_preferences.assert_not_called()
Beispiel #8
0
    def test_prepare_nvt_prefs(self, mock_kb):
        dummy = DummyDaemon()

        alive_test_out = [
            "1.3.6.1.4.1.25623.1.0.100315:1:checkbox:Do a TCP ping|||no"
        ]

        p_handler = PreferenceHandler(
            '1234-1234', mock_kb, dummy.scan_collection, None
        )
        p_handler._nvts_params = {  # pylint: disable = protected-access
            "1.3.6.1.4.1.25623.1.0.100315:1:checkbox:Do a TCP ping": "no"
        }
        p_handler.kbdb.add_scan_preferences = MagicMock()
        p_handler.prepare_nvt_preferences()

        p_handler.kbdb.add_scan_preferences.assert_called_with(
            p_handler.scan_id,
            alive_test_out,
        )
Beispiel #9
0
    def test_set_alive_pinghost(self, mock_kb):
        dummy = DummyDaemon()

        alive_test_out = [
            "1.3.6.1.4.1.25623.1.0.100315:1:checkbox:Do a TCP ping|||no",
            "1.3.6.1.4.1.25623.1.0.100315:2:checkbox:"
            "TCP ping tries also TCP-SYN ping|||no",
            "1.3.6.1.4.1.25623.1.0.100315:7:checkbox:"
            "TCP ping tries only TCP-SYN ping|||no",
            "1.3.6.1.4.1.25623.1.0.100315:3:checkbox:Do an ICMP ping|||yes",
            "1.3.6.1.4.1.25623.1.0.100315:4:checkbox:Use ARP|||no",
            "1.3.6.1.4.1.25623.1.0.100315:5:checkbox:"
            "Mark unrechable Hosts as dead (not scanning)|||yes",
        ]

        t_opt = {'alive_test': 2}
        dummy.scan_collection.get_target_options = MagicMock(return_value=t_opt)

        ov_setting = {'some_setting': 1}

        with patch.object(Openvas, 'get_settings', return_value=ov_setting):
            p_handler = PreferenceHandler(
                '1234-1234', mock_kb, dummy.scan_collection, None
            )
            p_handler._nvts_params = {}  # pylint: disable = protected-access
            p_handler.scan_id = '456-789'
            p_handler.kbdb.add_scan_preferences = MagicMock()
            p_handler.prepare_alive_test_option_for_openvas()

            for (
                key,
                value,
            ) in (
                p_handler._nvts_params.items()  # pylint: disable = protected-access
            ):
                self.assertTrue(f"{key}|||{value}" in alive_test_out)