예제 #1
0
    def testEditCredSyncGetsMapperDispatchedASYNC(self):
        cred = ModelObjectCred("coquito")

        params = ('new_user', 'new_pass') 
        self.genericEdit(cred, params, controller.ModelController.editCredASYNC, process_pending=True) 
        self.assertEquals(cred.getUsername(), 'new_user', "Username not updated")
        self.assertEquals(cred.getPassword(), 'new_pass', "Password not updated")
예제 #2
0
    def testEditCredSyncGetsMapperDispatchedSYNC(self):
        cred = ModelObjectCred("coquito")

        params = ('new_user', 'new_pass')
        self.genericEdit(cred, params, controller.ModelController.editCredSYNC)
        self.assertEquals(cred.getUsername(), 'new_user',
                          "Username not updated")
        self.assertEquals(cred.getPassword(), 'new_pass',
                          "Password not updated")
예제 #3
0
    def testAddCredToServiceGetsMapperDispatchSaveSYNC(self): 
        service = Service("pepito")
        cred = ModelObjectCred("usr", "pass")

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

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

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

        verify(mappersManager).getMapper(cred)
        verify(objectMapper).saveObject(cred)
    def testAddCredGetsMapperDispatchSaveSYNC(self): 
        host = Host("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.addCredSYNC(cred.getID(), cred)

        verify(mappersManager).getMapper(cred.class_signature)
        verify(objectMapper).save(cred)
    def testAddCredToServiceGetsMapperDispatchSaveASYNC(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.addCredToServiceASYNC(None, cred.getID(), cred)
        model_controller.processAllPendingActions()

        verify(mappersManager).getMapper(cred.class_signature)
        verify(objectMapper).save(cred)
예제 #6
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)
예제 #7
0
파일: hosts.py 프로젝트: 0x24bin/BurpSuite
    def fromDict(self, dict):
        self.id = dict["id"]
        self.name = dict["name"]
        owned = True if dict["owned"].upper() == "TRUE" else False
        self.setOwned(owned)
        parent_id = dict["parent"]
        self.owner = dict["owner"]
        self._protocol = dict["protocol"]
        self._status = dict["status"]
        self._version = dict["version"]

        self.description = dict["description"]

        for port in dict["ports"]:
            self.addPort(int(port))

                                              
                                                          
        for interface in dict["interfaces"]:
            inter = Interface()
            inter.id = interface
            self.addInterface(inter) 
         
        for application in dict["applications"]:
            app = HostApplication("")
            app.id = application
            self.addApplication(app)
            
        for cred in dict["creds"]:
            c = ModelObjectCred("")
            self.setParent(self)
            c.fromDict(cred)
            self.addCred(c)
            
        for note in dict["notes"]:
            n = ModelObjectNote("")
            self.setParent(self)
            n.fromDict(note)
            self.addNote(n)

        for vuln in dict["vulnerabilities"]:
            v = ModelObjectVuln("")
            self.setParent(self)
            v.fromDict(vuln)
            self.addVuln(v)

        return True
예제 #8
0
 def testDelCredentialFromServiceASYNC(self):
     service = Service('coco')
     cred = ModelObjectCred("int_mock0")
     service.addChild(cred)
     self.genericDelTest(service,
                         cred,
                         controller.ModelController.delCredFromServiceASYNC,
                         process_pending=True)
예제 #9
0
파일: hosts.py 프로젝트: andy737/faraday
    def fromDict(self, dict):
        self.id = dict["id"]
        self.name = dict["name"]
        owned = True if dict["owned"].upper() == "TRUE" else False
        self.setOwned(owned)
        parent_id = dict["parent"]
        self.owner = dict["owner"]
        self._protocol = dict["protocol"]
        self._status = dict["status"]
        self._version = dict["version"]

        self.description = dict["description"]

        for port in dict["ports"]:
            self.addPort(int(port))

        for interface in dict["interfaces"]:
            inter = Interface()
            inter.id = interface
            self.addInterface(inter)

        for application in dict["applications"]:
            app = HostApplication("")
            app.id = application
            self.addApplication(app)

        for cred in dict["creds"]:
            c = ModelObjectCred("")
            self.setParent(self)
            c.fromDict(cred)
            self.addCred(c)

        for note in dict["notes"]:
            n = ModelObjectNote("")
            self.setParent(self)
            n.fromDict(note)
            self.addNote(n)

        for vuln in dict["vulnerabilities"]:
            v = ModelObjectVuln("")
            self.setParent(self)
            v.fromDict(vuln)
            self.addVuln(v)

        return True
예제 #10
0
 def testHostWithCredentials(self):
     host = Host('coco')
     cred = ModelObjectCred('coco', 'coco123')
     host.addChild(cred)
     self.assertEquals(len(host.getCreds()), 1, "Creds added is not 1")
     self.assertIn(cred, host.getCreds(), "Cred not accessible")
예제 #11
0
 def testDelCredentialFromModelObjectSYNC(self):
     service = Service('coco')
     cred = ModelObjectCred("int_mock0") 
     service.addChild(cred.getID(), cred)
     self.genericDelTest(service, cred, 
             controller.ModelController.delCredSYNC)
예제 #12
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)
예제 #13
0
    def test_load_workspace_on_fs(self):
        """ This test case creates a host within the Model Controller context
        adds an interface to it then adds a VulnWeb"""
        """
        We are going to test this structure:
        host -> interface1 -> service1 -> vuln_web
                                       -> vuln
                                       -> note
                           -> service2 -> vuln
                                       -> vuln
             -> vuln
             -> note
             -> note

             -> interface2 -> service3 -> note
                                       -> credential
                                       -> vuln
                           -> vuln
        """

        workspace = self.wm.createWorkspace(new_random_workspace_name(),
                                            workspaceClass=WorkspaceOnFS)
        #self._couchdb_workspaces.append(workspace.name)
        self.wm.setActiveWorkspace(workspace)
        WorkspacePersister.stopThreads()

        host = create_host(self)
        interface = create_interface(self, host, ip="127.0.0.1")
        interface2 = create_interface(self, host, ip="127.0.0.2")
        service = create_service(self, host, interface, ports=1)
        service2 = create_service(self, host, interface, ports=2)
        service3 = create_service(self, host, interface2, ports=3)

        vulnweb = ModelObjectVulnWeb(name='VulnWebTest',
                                     desc='TestDescription',
                                     severity='high')

        self.model_controller.addVulnToServiceSYNC(host.getID(),
                                                   service.getID(), vulnweb)

        vuln = ModelObjectVuln(name='VulnTest',
                               desc='TestDescription',
                               severity='high')
        vuln2 = ModelObjectVuln(name='VulnTest2',
                                desc='TestDescription',
                                severity='high')
        vuln3 = ModelObjectVuln(name='VulnTest3',
                                desc='TestDescription',
                                severity='high')
        vuln4 = ModelObjectVuln(name='VulnTest4',
                                desc='TestDescription',
                                severity='high')
        vuln5 = ModelObjectVuln(name='VulnTest5',
                                desc='TestDescription',
                                severity='high')
        vuln6 = ModelObjectVuln(name='VulnTest6',
                                desc='TestDescription',
                                severity='high')

        self.model_controller.addVulnToServiceSYNC(host.getID(),
                                                   service.getID(), vuln)
        self.model_controller.addVulnToServiceSYNC(host.getID(),
                                                   service2.getID(), vuln2)
        self.model_controller.addVulnToServiceSYNC(host.getID(),
                                                   service2.getID(), vuln3)
        self.model_controller.addVulnToHostSYNC(host.getID(), vuln4)
        self.model_controller.addVulnToServiceSYNC(host.getID(),
                                                   service3.getID(), vuln5)
        self.model_controller.addVulnToInterfaceSYNC(host.getID(),
                                                     interface2.getID(), vuln6)

        note = ModelObjectNote(name='NoteTest', text='TestDescription')
        note2 = ModelObjectNote(name='NoteTest2', text='TestDescription')
        note3 = ModelObjectNote(name='NoteTest3', text='TestDescription')
        note4 = ModelObjectNote(name='NoteTest4', text='TestDescription')

        self.model_controller.addNoteToServiceSYNC(host.getID(),
                                                   service.getID(), note)
        self.model_controller.addNoteToHostSYNC(host.getID(), note2)
        self.model_controller.addNoteToHostSYNC(host.getID(), note3)
        self.model_controller.addNoteToServiceSYNC(host.getID(),
                                                   service3.getID(), note4)

        cred = ModelObjectCred(username='******', password='******')

        self.model_controller.addCredToServiceSYNC(host.getID(),
                                                   service3.getID(), cred)

        # First, we test if the structure was correctly created

        # one host with two interfaces, one vuln and two notes

        self.assertEquals(len(self.model_controller.getAllHosts()), 1,
                          "Host not created")
        added_host = self.model_controller.getHost(host.getID())

        self.assertEquals(len(added_host.getAllInterfaces()), 2,
                          "Interfaces not added to Host")
        self.assertEquals(len(added_host.getVulns()), 1, "Vuln not created")
        self.assertEquals(len(added_host.getNotes()), 2, "Notes not created")

        # one interface with two services, and another one
        # with a service and a vuln

        added_interface1 = added_host.getInterface(interface.getID())
        added_interface2 = added_host.getInterface(interface2.getID())

        self.assertEquals(len(added_interface1.getAllServices()), 2,
                          "Services not created")

        self.assertEquals(len(added_interface2.getAllServices()), 1,
                          "Service not created")

        self.assertEquals(len(added_interface2.getVulns()), 1,
                          "Vulns not created")

        # one service with a note, a vuln and a vuln web
        added_service1 = added_interface1.getService(service.getID())
        self.assertEquals(len(added_service1.getNotes()), 1,
                          "Note not created")
        self.assertEquals(len(added_service1.getVulns()), 2,
                          "Vulns not created")
        added_vuln_web = added_service1.getVuln(vulnweb.getID())
        self.assertEquals(added_vuln_web.class_signature, "VulnerabilityWeb",
                          "Not a vuln web")

        # one service with two vulns
        added_service2 = added_interface1.getService(service2.getID())
        self.assertEquals(len(added_service2.getVulns()), 2,
                          "Services not created")

        # one service with a note, a vuln and a credential

        added_service3 = added_interface2.getService(service3.getID())
        self.assertEquals(len(added_service3.getVulns()), 1,
                          "Vuln not created")
        self.assertEquals(len(added_service3.getNotes()), 1,
                          "Note not created")
        self.assertEquals(len(added_service3.getCreds()), 1,
                          "Cred not created")

        # So, now we reload the worskpace and check everything again
        print workspace.name

        workspace.load()

        # one host with two interfaces, one vuln and two notes

        self.assertEquals(len(self.model_controller.getAllHosts()), 1,
                          "Host not created")
        added_host = self.model_controller.getHost(host.getID())

        self.assertEquals(len(added_host.getAllInterfaces()), 2,
                          "Interfaces not added to Host")
        self.assertEquals(len(added_host.getVulns()), 1, "Vuln not created")
        self.assertEquals(len(added_host.getNotes()), 2, "Notes not created")

        # one interface with two services, and another one
        # with a service and a vuln

        added_interface1 = added_host.getInterface(interface.getID())
        added_interface2 = added_host.getInterface(interface2.getID())

        self.assertEquals(len(added_interface1.getAllServices()), 2,
                          "Services not created")

        self.assertEquals(len(added_interface2.getAllServices()), 1,
                          "Service not created")

        self.assertEquals(len(added_interface2.getVulns()), 1,
                          "Vulns not created")

        # one service with a note, a vuln and a vuln web
        added_service1 = added_interface1.getService(service.getID())
        self.assertEquals(len(added_service1.getNotes()), 1,
                          "Note not created")
        self.assertEquals(len(added_service1.getVulns()), 2,
                          "Vulns not created")
        added_vuln_web = added_service1.getVuln(vulnweb.getID())
        self.assertEquals(added_vuln_web.class_signature, "VulnerabilityWeb",
                          "Not a vuln web")

        # one service with two vulns
        added_service2 = added_interface1.getService(service2.getID())
        self.assertEquals(len(added_service2.getVulns()), 2,
                          "Services not created")

        # one service with a note, a vuln and a credential

        added_service3 = added_interface2.getService(service3.getID())
        self.assertEquals(len(added_service3.getVulns()), 1,
                          "Vuln not created")
        self.assertEquals(len(added_service3.getNotes()), 1,
                          "Note not created")
        self.assertEquals(len(added_service3.getCreds()), 1,
                          "Cred not created")
예제 #14
0
 def testDelCredentialFromModelObjectSYNC(self):
     service = Service('coco')
     cred = ModelObjectCred("int_mock0")
     service.addChild(cred)
     self.genericDelTest(service, cred,
                         controller.ModelController.delCredSYNC)