Beispiel #1
0
    def check_login(self):
        if (self.hostname_input.text() == ""
                or self.username_input.text() == ""
                or self.password_input.text() == ""):
            QMessageBox.about(QMainWindow(), "Error",
                              "Please enter a all Information")
        else:
            try:
                connection = SSHConnection(hostname=self.hostname_input.text())

                with Gmp(connection=connection,
                         transform=ObjectTransform()) as gmp:
                    try:
                        response = gmp.authenticate(
                            username=self.username_input.text(),
                            password=self.password_input.text(),
                        )
                        print(response)
                        self.signal.login_event.emit(gmp, self.window)
                    except GvmResponseError:
                        QMessageBox.about(QMainWindow(), "Error",
                                          "Wrong username or password.")

            except (gaierror, NoValidConnectionsError, GvmError) as ex:
                QMessageBox.about(QMainWindow(), "Error", str(ex))
Beispiel #2
0
    def test_stop_task(self):
        transform = ObjectTransform()

        xml = '<stop_task_response status="200" status_text="OK"/>'

        response = transform(xml)
        self.assertIsInstance(response, StopTaskResponse)
        self.assertEqual(response.status, 200)
        self.assertEqual(response.status_text, "OK")
Beispiel #3
0
    def test_start_task(self):
        transform = ObjectTransform()

        root = get_root_from_file("test_start_task.xml")

        response = transform(root, None)

        self.assertIsInstance(response, StartTaskResponse)
        self.assertEqual(response.report_id,
                         "9cdadab8-d28e-4a29-a2b7-bd63380515e3")
Beispiel #4
0
    def test_create_task(self):
        transform = ObjectTransform()

        root = get_root_from_file("test_create_task.xml")

        response = transform(root, None)

        self.assertIsInstance(response, CreateTaskResponse)
        self.assertEqual(response.status, 201)
        self.assertEqual(response.status_text, "OK, resource created")
        self.assertEqual(response.task_id,
                         "4a8db8ee-0c42-452d-bf64-64e735a71b87")
Beispiel #5
0
    def test_authenticate(self):

        transform = ObjectTransform()

        root = get_root_from_file("test_authenticate.xml")

        response = transform(root, None)

        self.assertIsInstance(response, AuthenticateResponse)
        self.assertIsInstance(response.role, Role)
        self.assertEqual(response.role.name, 'Test')
        self.assertEqual(response.timezone, 'UTC')
        self.assertEqual(response.severity, 'nist')
Beispiel #6
0
    def test_get_targets(self):
        transform = ObjectTransform()

        root = get_root_from_file("test_get_targets.xml")

        permissions = Permission("Everything")

        target_expected1 = Target(
            gmp=None,
            uuid="f8fac1da-de4f-461a-b4cc-7aff71734ec7",
            owner=Owner("admin"),
            name="Test target",
            comment="Test comment",
            creation_time=datetime.datetime(2020, 3, 3, 10, 5, 26),
            modification_time=datetime.datetime(2020, 3, 3, 10, 5, 26),
            writable=True,
            in_use=True,
            permissions=permissions,
            hosts=["192.168.212.44", "192.168.212.46"],
            exclude_hosts=["192.168.212.45"],
            reverse_lookup_only=False,
            reverse_lookup_unify=False,
            trash=None,
            all_info_loaded=False,
            _port_list=None,
        )

        target_expected2 = Target(
            gmp=None,
            uuid="7d27b6b7-b9ec-4543-9620-6e39c74a0c57",
            owner=Owner("admin"),
            name="Target for Test - 2020-03-03 10:37:49",
            comment="Automatically generated by wizard",
            creation_time=datetime.datetime(2020, 3, 3, 10, 37, 49),
            modification_time=datetime.datetime(2020, 3, 3, 10, 37, 49),
            writable=True,
            in_use=True,
            permissions=permissions,
            reverse_lookup_only=False,
            reverse_lookup_unify=False,
            trash=None,
            all_info_loaded=False,
            _port_list=None,
        )

        targets = [target_expected1, target_expected2]
        response = transform(root)

        self.assertEqual(response.targets, targets)
Beispiel #7
0
    def test_get_users(self):
        transform = ObjectTransform()
        root = get_root_from_file("test_get_users.xml")

        groups = [
            Group(uuid="62d425f1-41af-4b62-b6a8-ea0201490eab",
                  name="TestGruppe1"),
            Group(uuid="62d425f1-41af-4b62-b6a8-ea0201490ebb",
                  name="TestGruppe2"),
        ]

        user_expected1 = User(
            uuid="d6dcf91b-e9cf-4700-9d33-34c92ce1c3c8",
            owner=None,
            name="admin",
            comment="comment",
            creation_time=datetime.datetime(2020, 6, 4, 9, 57, 37),
            modification_time=datetime.datetime(2020, 6, 4, 9, 57, 37),
            writable=True,
            in_use=False,
            groups=groups,
            permissions=Permission(name="get_users"),
            user_tags=None,
        )

        user_expected2 = User(
            uuid="ec3266fd-1a35-40db-ab5a-794de9060e04",
            owner=Owner(name="admin"),
            name="TestUser",
            comment="Tester",
            creation_time=datetime.datetime(2020, 6, 4, 14, 35, 20),
            modification_time=datetime.datetime(2020, 6, 4, 14, 35, 20),
            writable=True,
            in_use=False,
            groups=groups,
            permissions=Permission(name="Everything"),
            user_tags=UserTags(count=1, tags=[]),
        )

        users_expected = [user_expected1, user_expected2]

        response = transform(root)

        self.assertIsInstance(response, GetUsersResponse)
        self.assertEqual(response.users, users_expected)
Beispiel #8
0
    def test_get_port_list(self):
        transform = ObjectTransform()

        root = get_root_from_file("test_get_port_list.xml")
        permissions = [
            Permission("Test_Permission1"),
            Permission("Test_Permission2"),
        ]
        port_count = PortCount(3, 2, 1)
        port_ranges = []
        port_ranges.append(
            PortRange(
                "1fa9476e-ba37-4d99-a7fa-90d912250c47",
                1,
                80,
                "tcp",
                "TestComment1",
            ))
        port_ranges.append(
            PortRange(
                "5d203ed9-35ac-48c2-a850-5f9de31af411",
                82,
                113,
                "tcp",
                "TestComment2",
            ))

        port_list = PortList(
            "33d0cd82-57c6-11e1-8ed1-406186ea4fc5",
            Owner("Test_name"),
            "All IANA assigned TCP 2012-02-10",
            "TestComment",
            datetime.datetime(2020, 3, 2, 10, 48, 37),
            datetime.datetime(2020, 3, 2, 10, 48, 37),
            False,
            True,
            permissions,
            port_count,
            port_ranges,
        )

        response = transform(root, None)

        self.assertIsInstance(response, GetPortListsResponse)
        self.assertEqual(response.port_lists, port_list)
Beispiel #9
0
    def test_get_scanners(self):
        transform = ObjectTransform()

        root = get_root_from_file("test_get_scanners.xml")
        permissions = [Permission("get_scanners"), Permission("get_scanners")]
        scanner_expected1 = Scanner(
            uuid="6acd0832-df90-11e4-b9d5-28d24461215b",
            owner=None,
            name="CVE",
            comment=None,
            creation_time=datetime.datetime(2020, 3, 2, 10, 48, 37),
            modification_time=datetime.datetime(2020, 3, 2, 10, 48, 37),
            writable=True,
            in_use=False,
            permissions=permissions,
            port=0,
            scanner_type=3,
            trash=None,
            all_info_loaded=False,
        )

        scanner_expected2 = Scanner(
            uuid="08b69003-5fc2-4037-a479-93b440211c73",
            owner=None,
            name="OpenVAS Default",
            comment=None,
            creation_time=datetime.datetime(2020, 3, 2, 10, 48, 37),
            modification_time=datetime.datetime(2020, 3, 2, 10, 48, 39),
            writable=True,
            in_use=True,
            permissions=permissions,
            port=0,
            scanner_type=2,
            trash=None,
            all_info_loaded=False,
        )

        scanners = [scanner_expected1, scanner_expected2]

        response = transform(root)

        self.assertEqual(response.scanners, scanners)
Beispiel #10
0
 def test_key_error(self):
     transform = ObjectTransform()
     response = transform(
         '<no_valid_response status="200" status_text="OK"/>')
     self.assertEqual(response, None)
Beispiel #11
0
    def test_get_reports(self):
        transform = ObjectTransform()

        root = get_root_from_file("test_get_reports.xml")

        debug = ResultCounter(0, 0)
        hole = ResultCounter(0, 0)
        info = ResultCounter(0, 0)
        log = ResultCounter(0, 0)
        log2 = ResultCounter(5, 5)
        warning = ResultCounter(0, 0)
        false_positiv = ResultCounter(0, 0)

        report_expected1 = Report(
            gmp=None,
            uuid="c96b26fb-22df-4a79-9d20-c579a5fa5533",
            format_id="",
            content_type="application/xml",
            owner=Owner("admin"),
            name="2020-03-03T10:05:42Z",
            comment="Test Comment",
            creation_time=datetime.datetime(2020, 3, 3, 10, 5, 42),
            modification_time=datetime.datetime(2020, 3, 3, 10, 6, 22),
            writable=False,
            in_use=False,
            gmp_version="9.0",
            scan_run_status="Done",
            timestamp=datetime.datetime(2020, 3, 3, 10, 5, 26),
            scan_start=datetime.datetime(2020, 3, 3, 10, 5, 42),
            scan_end=datetime.datetime(2020, 3, 3, 10, 6, 22),
            timezone="Coordinated Universal Time",
            timezone_abbrev="UTC",
            result_count=ResultCount(0, 0, 0, debug, hole, info, log, warning,
                                     false_positiv),
            severity=Severity(float(-99.0), float(-99.0)),
            all_info_loaded=False,
            _task=ReportTask("1e9844ab-9918-44db-b7d8-9bc32c0b1cee", False),
        )

        report_expected2 = Report(
            gmp=None,
            uuid="0f7c7734-e33c-45ef-a9e4-f624e39312cf",
            format_id="Test_ID",
            content_type="application/xml",
            owner=Owner("admin"),
            name="2020-03-03T10:38:05Z",
            comment=None,
            creation_time=datetime.datetime(2020, 3, 3, 10, 38, 5),
            modification_time=datetime.datetime(2020, 3, 3, 10, 39, 47),
            writable=False,
            in_use=True,
            gmp_version="9.0",
            scan_run_status="Done",
            timestamp=datetime.datetime(2020, 3, 3, 10, 37, 49),
            scan_start=datetime.datetime(2020, 3, 3, 10, 38, 5),
            scan_end=datetime.datetime(2020, 3, 3, 10, 39, 47),
            timezone="Coordinated Universal Time",
            timezone_abbrev="UTC",
            result_count=ResultCount(5, 5, 5, debug, hole, info, log2, warning,
                                     false_positiv),
            severity=Severity(float(0.0), float(0.0)),
            all_info_loaded=False,
            _task=ReportTask("a16aec9e-9c53-4fde-b42f-3c20311c0afc", False),
        )

        reports = [report_expected1, report_expected2]

        response = transform(root)

        self.assertEqual(response.reports, reports)
Beispiel #12
0
    def test_get_task(self):
        transform = ObjectTransform()

        root = get_root_from_file("test_get_task.xml")

        response = transform(root, None)
        permissions = []
        permissions.append(Permission("Test1"))
        permissions.append(Permission("Test2"))

        users = ["admin", "admin_Clone_4"]
        groups = Group(
            None,
            "44ff149f-8817-4419-9d5c-b6c3a8655ab2",
            None,
            "plebeians",
            None,
            None,
            None,
            None,
            None,
            None,
            None,
            None,
        )

        task_scan_config_expected = TaskScanConfig(
            "8715c877-47a0-438d-98a3-27c7a6ab2196", False, False)

        observers = Observers(users, groups)

        user_tags = UserTags(
            1, Tag("6e6f1411-c2ba-4fe6-99bf-470dc67ccade", None, None, None))

        task = Task(
            None,
            "c6415957-984c-40ba-9906-db6e3390c82d",
            Owner("admin"),
            "Discovery",
            "Test Comment",
            datetime.datetime(2020, 3, 5, 15, 35, 21),
            datetime.datetime(2020, 3, 5, 15, 35, 21),
            True,
            False,
            permissions,
            user_tags,
            False,
            "scan",
            "Test Ordering",
            # alert,
            "Done",
            -1,
            ReportCount(1, 1),
            "Test Trend",
            Schedule("Test Schedule", "over", False),
            0,
            observers,
            None,
            False,
            None,
            None,
            task_scan_config_expected,
            None,
            None,
        )

        self.assertIsInstance(response, GetTasksResponse)
        self.assertEqual(response.tasks, task)
Beispiel #13
0
    def test_get_configs(self):
        """
        This tests also Preferences,
        because they are part of the get_configs_response
        """
        transform = ObjectTransform()

        root = get_root_from_file("test_get_configs.xml")
        permissions = [Permission("get_configs"), Permission("get_configs")]

        preference_expected1 = Preference(
            nvt=Nvt("1.3.6.1.4.1.25623.1.0.100151", "PostgreSQL Detection"),
            preference_id=1,
            hr_name="Postgres Username:"******"Postgres Username:"******"entry",
            value="postgres",
            alternatives=None,
            default="postgres",
        )

        preference_expected2 = Preference(
            nvt=Nvt("1.3.6.1.4.1.25623.1.0.97001", "PCI-DSS Version 2.0"),
            preference_id=1,
            hr_name="Berichtformat/Report Format",
            name="Berichtformat/Report Format",
            preference_type="radio",
            value="Text",
            alternatives=[
                "Tabellarisch/Tabular",
                "Text und/and Tabellarisch/Tabular",
            ],
            default="Text",
        )

        preferences = [preference_expected1, preference_expected2]

        config_expected1 = ScanConfig(
            uuid="d21f6c81-2b88-4ac1-b7b4-a2a9f2ad4663",
            owner=None,
            name="Base",
            comment="Basic configuration template.",
            creation_time=datetime.datetime(2020, 3, 2, 10, 48, 37),
            modification_time=datetime.datetime(2020, 3, 2, 10, 48, 37),
            writable=False,
            in_use=False,
            permissions=permissions,
            family_count=FamilyCount(2, False),
            nvt_count=NvtCount(3, False),
            config_type=0,
            usage_type="scan",
            max_nvt_count=None,
            known_nvt_count=None,
            scanner=None,
            user_tags=None,
            tasks=None,
            preferences=None,
            trash=None,
            all_info_loaded=False,
        )

        config_expected2 = ScanConfig(
            uuid="8715c877-47a0-438d-98a3-27c7a6ab2196",
            owner=Owner("TestName"),
            name="Discovery",
            comment="Network Discovery scan configuration.",
            creation_time=datetime.datetime(2020, 3, 2, 10, 48, 37),
            modification_time=datetime.datetime(2020, 3, 2, 10, 48, 37),
            writable=False,
            in_use=True,
            permissions=permissions,
            family_count=FamilyCount(16, False),
            nvt_count=NvtCount(3023, True),
            config_type=0,
            usage_type="scan",
            max_nvt_count=239,
            known_nvt_count=3,
            scanner=None,
            user_tags=None,
            tasks=None,
            preferences=preferences,
            trash=None,
            all_info_loaded=False,
        )
        scan_configs = [config_expected1, config_expected2]
        response = transform(root)

        self.assertEqual(response.scan_configs, scan_configs)