Beispiel #1
0
    def testAddVulnToInterface(self):
        serv = Service('cuca')
        vuln = ModelObjectVuln('vuln')
        serv.addChild(vuln)

        self.assertIn(vuln, serv.childs.values(), 'Vuln not in childs')
        self.assertIn(vuln, serv.getVulns(), 'Vuln not accessible')
    def testAddVulnToInterface(self):
        serv = Service('cuca')
        vuln = ModelObjectVuln('vuln')
        serv.addChild(vuln)

        self.assertIn(vuln, serv.childs.values(), 'Vuln not in childs')
        self.assertIn(vuln, serv.getVulns(), 'Vuln not accessible')
Beispiel #3
0
    def test_service_creation(self):
        name = "pepito"
        os = "Windows"
        host = Host(name, os)

        name = ""
        mac = "00:00:00:00:00:00"
        ipv4_address = "0.0.0.0"
        ipv4_mask = "0.0.0.0"
        ipv4_gateway = "0.0.0.0"
        ipv4_dns = []
        ipv6_address = "0000:0000:0000:0000:0000:0000:0000:0000"
        ipv6_prefix = "00"
        ipv6_gateway = "0000:0000:0000:0000:0000:0000:0000:0000"
        ipv6_dns = []
        network_segment = ""
        hostname_resolution = []

        interface = Interface(name,
                              mac,
                              ipv4_address,
                              ipv4_mask,
                              ipv4_gateway,
                              ipv4_dns,
                              ipv6_address,
                              ipv6_prefix,
                              ipv6_gateway,
                              ipv6_dns,
                              network_segment,
                              hostname_resolution,
                              parent_id=host.getID())

        when(self._model_controller).find(
            interface.getID()).thenReturn(interface)

        name = "srv"
        protocol = "tcp"
        ports = []
        status = "running"
        version = "unknown"
        description = ""

        service_id = self.client.createService(name, protocol, ports, status,
                                               version, description,
                                               interface.getID())

        service = Service(name,
                          protocol,
                          ports,
                          status,
                          version,
                          description,
                          parent_id=interface.getID())

        self.assertNotEquals(service_id, None,
                             "service created shouldn't be None")

        self.assertEquals(service.getID(), service_id,
                          "ids should be the same")
Beispiel #4
0
 def testDelNoteFromServiceASYNC(self):
     service = Service('coco')
     note = ModelObjectNote("int_mock0")
     service.addChild(note)
     self.genericDelTest(service,
                         note,
                         controller.ModelController.delNoteFromServiceASYNC,
                         process_pending=True)
Beispiel #5
0
 def testDelVulnFromServiceASYNC(self):
     service = Service('coco')
     vuln = ModelObjectVuln("int_mock0")
     service.addChild(vuln)
     self.genericDelTest(service,
                         vuln,
                         controller.ModelController.delVulnFromServiceASYNC,
                         process_pending=True)
Beispiel #6
0
 def testDelCredentialFromServiceASYNC(self):
     service = Service('coco')
     cred = ModelObjectCred("int_mock0")
     service.addChild(cred)
     self.genericDelTest(service,
                         cred,
                         controller.ModelController.delCredFromServiceASYNC,
                         process_pending=True)
Beispiel #7
0
    def testEditServiceSyncGetsMapperDispatchedASYNC(self):
        service = Service("coquito")

        params = ('new_name', 'new_desc', 'upd', 9000, 'closed', '2.1', True)
        self.genericEdit(service, params, controller.ModelController.editServiceASYNC, process_pending=True)

        self.assertEquals(service.getName(), 'new_name', "Name not updated")
        self.assertEquals(service.getDescription(), 'new_desc', "Description not updated")
        self.assertEquals(service.getProtocol(), 'upd', "Protocol not updated")
        self.assertEquals(service.isOwned(), True, "Owned status not updated")
    def testInterfaceSetServices(self):
        inter = Interface('coco')
        services = {}
        for i in range(50, 60):
            serv = Service('cuca%s' % i, ports=[i])
            services[serv.getID()] = serv
        inter.setServices(services)

        self.assertEquals(len(inter.getChildsByType(Service.__name__)), 10, "not all services added")
        for s in services.values():
            self.assertIn(s, inter.getChildsByType(Service.__name__), "what happened with services?")
Beispiel #9
0
    def test_service_create_and_delete(self):
        srv = Service(name="http")
        self.smapper.save(srv)
        s_id = srv.getID()

        self.assertNotEquals(self.smapper.load(s_id), None,
                             "Service should be saved")

        self.smapper.delete(s_id)

        self.assertEquals(self.smapper.find(s_id), None,
                          "Service shouldn't exist anymore")
Beispiel #10
0
    def testInterfaceSetServices(self):
        inter = Interface('coco')
        services = {}
        for i in range(50, 60):
            serv = Service('cuca%s' % i, ports=[i])
            services[serv.getID()] = serv
        inter.setServices(services)

        self.assertEquals(len(inter.getChildsByType(Service.__name__)), 10,
                          "not all services added")
        for s in services.values():
            self.assertIn(s, inter.getChildsByType(Service.__name__),
                          "what happened with services?")
Beispiel #11
0
    def testAddVulnToServiceGetsMapperDispatchSaveSYNC(self): 
        service = Service("servi")
        vuln = ModelObjectVuln("a_vuln")

        mappersManager = self.createMapperMock()
        objectMapper = mock()
        when(mappersManager).getMapper(vuln).thenReturn(objectMapper)
        when(objectMapper).saveObject(vuln).thenReturn(True)

        model_controller = controller.ModelController(mock(), mappersManager)

        model_controller.addVulnToServiceSYNC(None, service.getID(), vuln)

        verify(mappersManager).getMapper(vuln)
        verify(objectMapper).saveObject(vuln)
Beispiel #12
0
    def testAddNoteToServiceGetsMapperDispatchSaveSYNC(self): 
        service = Service("servi")
        note = ModelObjectNote("a_note")

        mappersManager = self.createMapperMock()
        objectMapper = mock()
        when(mappersManager).getMapper(note).thenReturn(objectMapper)
        when(objectMapper).saveObject(note).thenReturn(True)

        model_controller = controller.ModelController(mock(), mappersManager)

        model_controller.addNoteToServiceSYNC(None, service.getID(), note)

        verify(mappersManager).getMapper(note)
        verify(objectMapper).saveObject(note)
Beispiel #13
0
    def test(self):
        """
        DELETE THIS BEFORE RELEASE
        used for internal testing (not correct way but we need to use it like
        this for now)
        """
                                                              
                       
                       
                                                                       
               
        global test_count
        test_count += 1
        model.api.showPopup("Creating test host %d" % test_count)
                                                                     
        from utils.error_report import exception_handler
        
        def raiser():
            sys.excepthook = exception_handler
            time.sleep(3)
            raise Exception("Exception from a secondary thread...")
                                            
                  
                                                                

        from model.hosts import Host
        from model.hosts import Interface
        from model.hosts import Service
        from model.hosts import HostApplication

        self._main_app.getLogger().log("testing..")
        self._main_app.getLogger().log("creating test host %d" % test_count)
        host = Host("TestHost-%d" % test_count, "Windows 2003")
        service = Service( "TestService-%d" % test_count, "TCP", [80,8080], "running")
        interface = Interface("eth%d" % test_count, mac = "00:00:00:00:00:00",
                 ipv4_address = "10.1.1.%d" % test_count, ipv4_mask = "255.255.0.0",
                 ipv4_gateway = "10.1.1.%d" % (test_count+1),
                 hostname_resolution = "TestHost-%d" % test_count)
        app = HostApplication( "AppTest-%d" % test_count, "running", "1.0 beta")

        
        host.addInterface(interface)
        host.addService(service)
        host.addApplication(app)
        interface.addService(service)
        app.addService(service)
        service.addInterface(interface)
        self._model_controller.addHostASYNC(host)
Beispiel #14
0
 def testInterfaceFromHostRemovedSYNC(self):
     service = Service('coco')
     interface = Interface("int_mock0")
     interface.addChild(service)
     self.genericDelTest(
         interface, service,
         controller.ModelController.delServiceFromInterfaceSYNC)
    def testAddNoteToServiceGetsMapperDispatchSaveASYNC(self): 
        service = Service("servi")
        note = ModelObjectNote("a_note")

        mappersManager = self.createMapperMock()
        objectMapper = mock()
        when(mappersManager).getMapper(note.class_signature).thenReturn(objectMapper)
        when(objectMapper).save(note).thenReturn(True)

        model_controller = controller.ModelController(mock(), mappersManager)

        model_controller.addNoteToServiceASYNC(None, service.getID(), note)
        model_controller.processAllPendingActions()

        verify(mappersManager).getMapper(note.class_signature)
        verify(objectMapper).save(note)
Beispiel #16
0
    def test_service_create_and_delete(self):
        srv = Service(name="http")
        self.smapper.save(srv)
        s_id = srv.getID()

        self.assertNotEquals(
            self.smapper.load(s_id),
            None,
            "Service should be saved")

        self.smapper.delete(s_id)

        self.assertEquals(
            self.smapper.find(s_id),
            None,
            "Service shouldn't exist anymore")
Beispiel #17
0
    def testAddNoteToServiceGetsMapperDispatchSaveSYNC(self):
        service = Service("servi")
        note = ModelObjectNote("a_note")

        mappersManager = self.createMapperMock()
        objectMapper = mock()
        when(mappersManager).getMapper(
            note.class_signature).thenReturn(objectMapper)
        when(objectMapper).save(note).thenReturn(True)

        model_controller = controller.ModelController(mock(), mappersManager)

        model_controller.addNoteToServiceSYNC(None, service.getID(), note)

        verify(mappersManager).getMapper(note.class_signature)
        verify(objectMapper).save(note)
Beispiel #18
0
    def testAddVulnToServiceGetsMapperDispatchSaveSYNC(self):
        service = Service("servi")
        vuln = ModelObjectVuln("a_vuln")

        mappersManager = self.createMapperMock()
        objectMapper = mock()
        when(mappersManager).getMapper(
            vuln.class_signature).thenReturn(objectMapper)
        when(objectMapper).save(vuln).thenReturn(True)

        model_controller = controller.ModelController(mock(), mappersManager)

        model_controller.addVulnToServiceSYNC(None, service.getID(), vuln)

        verify(mappersManager).getMapper(vuln.class_signature)
        verify(objectMapper).save(vuln)
Beispiel #19
0
    def testAddServiceToInterface(self):
        interface = Interface('coco')
        serv = Service('cuca')
        interface.addChild(serv)

        self.assertIn(serv, interface.childs.values(), 'Service not in childs')
        self.assertIn(serv, interface.getAllServices(),
                      'Service not accessible')
    def test_service_creation(self):
        name = "pepito"
        os = "Windows"
        host = Host(name, os)

        name = ""
        mac = "00:00:00:00:00:00"
        ipv4_address = "0.0.0.0"
        ipv4_mask = "0.0.0.0"
        ipv4_gateway = "0.0.0.0"
        ipv4_dns = []
        ipv6_address = "0000:0000:0000:0000:0000:0000:0000:0000"
        ipv6_prefix = "00"
        ipv6_gateway = "0000:0000:0000:0000:0000:0000:0000:0000"
        ipv6_dns = []
        network_segment = ""
        hostname_resolution = []

        interface = Interface(
            name, mac, ipv4_address, ipv4_mask, ipv4_gateway, ipv4_dns,
            ipv6_address, ipv6_prefix, ipv6_gateway, ipv6_dns, network_segment,
            hostname_resolution, parent_id=host.getID())

        when(self._model_controller).find(
            interface.getID()).thenReturn(interface)

        name = "srv"
        protocol = "tcp"
        ports = []
        status = "running"
        version = "unknown"
        description = ""

        service_id = self.client.createService(
            name, protocol, ports, status, version, description,
            interface.getID())

        service = Service(name, protocol, ports, status, version, description,
                          parent_id=interface.getID())

        self.assertNotEquals(
            service_id, None, "service created shouldn't be None")

        self.assertEquals(
            service.getID(), service_id, "ids should be the same")
Beispiel #21
0
    def testServiceWithMultipleChildTypes(self):
        serv = Service('cuca')
        vuln = ModelObjectVuln('vuln')
        note = ModelObjectNote('nota')
        serv.addChild(note)
        serv.addChild(vuln)

        self.assertEquals(len(serv.getVulns()), 1, "Vulns added is not 1")
        self.assertIn(vuln, serv.getVulns(), "Vuln not accessible")
        self.assertEquals(len(serv.getNotes()), 1, "Notes added is not 1")
        self.assertIn(note, serv.getNotes(), "Note not accessible")
Beispiel #22
0
    def test(self):
        """
        DELETE THIS BEFORE RELEASE
        used for internal testing (not correct way but we need to use it like
        this for now)
        """

        global test_count
        test_count += 1
        model.api.showPopup("Creating test host %d" % test_count)

        from utils.error_report import exception_handler

        def raiser():
            sys.excepthook = exception_handler
            time.sleep(3)
            raise Exception("Exception from a secondary thread...")

        from model.hosts import Host
        from model.hosts import Interface
        from model.hosts import Service
        from model.hosts import HostApplication

        self._main_app.getLogger().log("testing..")
        self._main_app.getLogger().log("creating test host %d" % test_count)
        host = Host("TestHost-%d" % test_count, "Windows 2003")
        service = Service("TestService-%d" % test_count, "TCP", [80, 8080],
                          "running")
        interface = Interface("eth%d" % test_count,
                              mac="00:00:00:00:00:00",
                              ipv4_address="10.1.1.%d" % test_count,
                              ipv4_mask="255.255.0.0",
                              ipv4_gateway="10.1.1.%d" % (test_count + 1),
                              hostname_resolution="TestHost-%d" % test_count)
        app = HostApplication("AppTest-%d" % test_count, "running", "1.0 beta")

        host.addInterface(interface)
        host.addService(service)
        host.addApplication(app)
        interface.addService(service)
        app.addService(service)
        service.addInterface(interface)
        self._model_controller.addHostASYNC(host)
Beispiel #23
0
    def testInterfaceWithMultipleChildTypes(self):
        inter = Interface('coco')
        serv = Service('cuca')
        vuln = ModelObjectVuln('vuln')
        inter.addChild(serv)
        inter.addChild(vuln)

        self.assertEquals(len(inter.getVulns()), 1, "Vulns added is not 1")
        self.assertIn(vuln, inter.getVulns(), "Vuln not accessible")
        self.assertEquals(len(inter.getAllServices()), 1,
                          "Services added is not 1")
Beispiel #24
0
    def testServiceWithMultipleChildTypes(self):
        serv = Service('cuca')
        vuln = ModelObjectVuln('vuln')
        note = ModelObjectNote('nota')
        serv.addChild(note) 
        serv.addChild(vuln)

        self.assertEquals(len(serv.getVulns()), 1, "Vulns added is not 1")
        self.assertIn(vuln, serv.getVulns(), "Vuln not accessible")
        self.assertEquals(len(serv.getNotes()), 1, "Notes added is not 1") 
        self.assertIn(note, serv.getNotes(), "Note not accessible")
Beispiel #25
0
    def testAddCredToServiceGetsMapperDispatchSaveSYNC(self):
        service = Service("pepito")
        cred = ModelObjectCred("usr", "pass")

        mappersManager = self.createMapperMock()
        objectMapper = mock()
        when(mappersManager).getMapper(
            cred.class_signature).thenReturn(objectMapper)
        when(objectMapper).save(cred).thenReturn(True)

        model_controller = controller.ModelController(mock(), mappersManager)

        model_controller.addCredToServiceSYNC(None, cred.getID(), cred)

        verify(mappersManager).getMapper(cred.class_signature)
        verify(objectMapper).save(cred)
Beispiel #26
0
    def testAddServiceGetsMapperDispatchSaveSYNC(self):
        interface = Interface("int_mock0")
        service = Service("servi")

        mappersManager = self.createMapperMock()
        objectMapper = mock()
        when(mappersManager).getMapper(
            service.class_signature).thenReturn(objectMapper)
        when(objectMapper).save(service).thenReturn(True)

        model_controller = controller.ModelController(mock(), mappersManager)

        model_controller.addServiceToInterfaceSYNC(None, interface.getID(),
                                                   service)

        verify(mappersManager).getMapper(service.class_signature)
        verify(objectMapper).save(service)
Beispiel #27
0
    def testEditServiceSyncGetsMapperDispatchedSYNC(self):
        service = Service("coquito")

        params = ('new_name', 'new_desc', 'upd', 9000, 'closed', '2.1', True)
        self.genericEdit(service, params,
                         controller.ModelController.editServiceSYNC)

        self.assertEquals(service.getName(), 'new_name', "Name not updated")
        self.assertEquals(service.getDescription(), 'new_desc',
                          "Description not updated")
        self.assertEquals(service.getProtocol(), 'upd', "Protocol not updated")
        self.assertEquals(service.isOwned(), True, "Owned status not updated")
Beispiel #28
0
 def testDelVulnFromServiceASYNC(self):
     service = Service('coco')
     vuln = ModelObjectVuln("int_mock0") 
     service.addChild(vuln.getID(), vuln)
     self.genericDelTest(service, vuln, 
             controller.ModelController.delVulnFromServiceASYNC, process_pending=True)
Beispiel #29
0
 def test_service_serialization(self):
     srv = Service(name="http")
     srv.setDescription("Some description")
     srv.setOwned(True)
     srv.setProtocol("tcp")
     srv.setPorts(80)
     srv.setStatus("open")
     srv.setVersion("Apache 2.4")
     sserialized = self.smapper.serialize(srv)
     # if serialization fails, returns None
     self.assertNotEqual(
         sserialized,
         None,
         "Serialized service shouldn't be None")
     # we check the service attributes
     self.assertEquals(
         sserialized.get("_id"),
         srv.getID(),
         "Serialized ID is not the same as Service ID")
     self.assertEquals(
         sserialized.get("name"),
         srv.getName(),
         "Serialized name is not the same as Service name")
     self.assertEquals(
         sserialized.get("protocol"),
         srv.getProtocol(),
         "Serialized protocol is not the same as Service protocol")
     self.assertEquals(
         sserialized.get("status"),
         srv.getStatus(),
         "Serialized status is not the same as Service status")
     self.assertEquals(
         sserialized.get("ports"),
         srv.getPorts(),
         "Serialized ports is not the same as Service ports")
     self.assertEquals(
         sserialized.get("description"),
         srv.getDescription(),
         "Serialized description is not the same as Interface description")
     self.assertEquals(
         sserialized.get("owned"),
         srv.isOwned(),
         "Serialized owned flag is not the same as Interface owned flag")
Beispiel #30
0
def create_service(self, host, interface, service_name="coquito"):
    service = Service(service_name)
    self.model_controller.addServiceToInterfaceSYNC(host.getID(),
                                                    interface.getID(), service)
    return service
Beispiel #31
0
    def test_service_creation(self):
        srv = Service(name="http")
        srv.setDescription("Some description")
        srv.setOwned(True)
        srv.setProtocol("tcp")
        srv.setPorts(80)
        srv.setStatus("open")
        srv.setVersion("Apache 2.4")

        self.smapper.save(srv)
        s = self.smapper.find(srv.getID())
        self.assertEquals(
            s,
            srv,
            "Service retrieved should be the same as persisted")
        self.assertEquals(
            s.getID(),
            srv.getID(),
            "Service retrieved's Id should be the same as persisted's Id")
 def testDelVulnFromServiceSYNC(self):
     service = Service('coco')
     vuln = ModelObjectVuln("int_mock0") 
     service.addChild(vuln)
     self.genericDelTest(service, vuln, 
             controller.ModelController.delVulnFromServiceSYNC)
Beispiel #33
0
 def testDelCredentialFromModelObjectSYNC(self):
     service = Service('coco')
     cred = ModelObjectCred("int_mock0") 
     service.addChild(cred.getID(), cred)
     self.genericDelTest(service, cred, 
             controller.ModelController.delCredSYNC)
Beispiel #34
0
 def test_service_serialization(self):
     srv = Service(name="http")
     srv.setDescription("Some description")
     srv.setOwned(True)
     srv.setProtocol("tcp")
     srv.setPorts(80)
     srv.setStatus("open")
     srv.setVersion("Apache 2.4")
     sserialized = self.smapper.serialize(srv)
     # if serialization fails, returns None
     self.assertNotEqual(sserialized, None,
                         "Serialized service shouldn't be None")
     # we check the service attributes
     self.assertEquals(sserialized.get("_id"), srv.getID(),
                       "Serialized ID is not the same as Service ID")
     self.assertEquals(sserialized.get("name"), srv.getName(),
                       "Serialized name is not the same as Service name")
     self.assertEquals(
         sserialized.get("protocol"), srv.getProtocol(),
         "Serialized protocol is not the same as Service protocol")
     self.assertEquals(
         sserialized.get("status"), srv.getStatus(),
         "Serialized status is not the same as Service status")
     self.assertEquals(sserialized.get("ports"), srv.getPorts(),
                       "Serialized ports is not the same as Service ports")
     self.assertEquals(
         sserialized.get("description"), srv.getDescription(),
         "Serialized description is not the same as Interface description")
     self.assertEquals(
         sserialized.get("owned"), srv.isOwned(),
         "Serialized owned flag is not the same as Interface owned flag")
Beispiel #35
0
 def testInterfaceFromHostRemovedASYNC(self):
     service = Service('coco')
     interface = Interface("int_mock0") 
     interface.addChild(service.getID(), service)
     self.genericDelTest(interface, service,
             controller.ModelController.delServiceFromInterfaceASYNC, process_pending=True)
 def testDelNoteFromServiceSYNC(self):
     service = Service('coco')
     note = ModelObjectNote("int_mock0") 
     service.addChild(note)
     self.genericDelTest(service, note, 
             controller.ModelController.delNoteFromServiceSYNC)
Beispiel #37
0
    def test_service_creation(self):
        srv = Service(name="http")
        srv.setDescription("Some description")
        srv.setOwned(True)
        srv.setProtocol("tcp")
        srv.setPorts(80)
        srv.setStatus("open")
        srv.setVersion("Apache 2.4")

        self.smapper.save(srv)
        s = self.smapper.find(srv.getID())
        self.assertEquals(s, srv,
                          "Service retrieved should be the same as persisted")
        self.assertEquals(
            s.getID(), srv.getID(),
            "Service retrieved's Id should be the same as persisted's Id")
Beispiel #38
0
 def testDelNoteFromServiceASYNC(self):
     service = Service('coco')
     note = ModelObjectNote("int_mock0") 
     service.addChild(note.getID(), note)
     self.genericDelTest(service, note, 
             controller.ModelController.delNoteFromServiceASYNC, process_pending=True)
Beispiel #39
0
 def testDelCredentialFromServiceASYNC(self):
     service = Service('coco')
     cred = ModelObjectCred("int_mock0") 
     service.addChild(cred.getID(), cred)
     self.genericDelTest(service, cred, 
             controller.ModelController.delCredFromServiceASYNC, process_pending=True)
Beispiel #40
0
 def testDelCredentialFromModelObjectSYNC(self):
     service = Service('coco')
     cred = ModelObjectCred("int_mock0")
     service.addChild(cred)
     self.genericDelTest(service, cred,
                         controller.ModelController.delCredSYNC)