def setUp(self):
     super(SessionsTestCase, self).setUp()
     self.sessions = {
         i: {
             generateString(4): generateString(4)
         }
         for i in range(3)
     }
     self.mock_client.getActiveSessions.return_value = self.sessions
    def test_use_invalid_exploit(self):
        self._client.msfClient.modules.use.side_effect = MsfRpcError('')
        exploitName = generateString(6)

        self.assertNotIn(exploitName, self.exploits)
        with self.assertRaises(NameError):
            self._client.useExploit(exploitName)
    def test_get_an_invalid_payload_option(self, stub_payload):
        self.__initPayloadOptionsKeys(stub_payload)
        optionSelected = generateString(6)

        options = self._client.getPayloadOptions(optionSelected)

        self.assertEquals(len(options), 0)
    def test_get_an_invalid_exploit_option(self, stub_exploit):
        self.__initExploitOptionsKeys(stub_exploit)
        optionSelected = generateString(5)

        options = self._client.getExploitOptions(optionSelected)

        self.assertEquals(len(options), 0)
    def test_set_valid_payload_option(self, stub_payload):
        self.__initPayloadtOptions(stub_payload)
        self.assertEquals(stub_payload._options, self.payload_options)
        key = random.choice(self.payload_options.keys())

        self._client.setPayloadOptions(**{key: generateString(4)})

        self.assertNotEquals(stub_payload._options, self.payload_options)
    def test_use_invalid_payload(self, mock_client):
        self._client.msfClient.modules.use.side_effect = MsfRpcError('')
        payload = generateString(6)

        self.assertNotIn(payload, self.payloads)
        with self.assertRaises(NameError):
            self._client.useExploit(payload)
            mock_client.modules.use.assert_called_with('payload', payload)
    def test_set_valid_exploit_option(self, stub_exploit):
        self.__initExploitOptions(stub_exploit)
        self.assertEquals(stub_exploit._options, self.exploit_options)
        key = random.choice(self.exploit_options.keys())

        self._client.setExploitOptions(**{key: generateString(4)})

        self.assertNotEquals(stub_exploit._options, self.exploit_options)
    def test_download_report(self):
        self.mock_client.listReportFormats.return_value = self.formats
        self.mock_client.listReports.return_value = self.reports
        reportIndex = random.randint(0, len(self.reports) - 1)
        formatIndex = random.randint(0, len(self.formats) - 1)
        path = generateString(5)

        self.runner.invoke(
            OpenvasCommands.reports, ['--download'], '\n'.join(
                (str(formatIndex), str(reportIndex), path)))

        self.mock_client.downloadReport.assert_called_with(
            reportIndex, formatIndex, path)
    def test_list_tasks_with_a_task_done(self):
        tasks = [{
            'id': generateId(),
            'name': 'Scan of IP' + generateIP(),
            'progress': '-1',
            'status': generateString(5)
        } for _ in range(2)]
        resultExpected = '\n\n'.join([
            "{0}.\nScan ID: {1}\nScan progress: {2}".format(
                task['name'], task['id'], task['progress']) for task in tasks
        ]) + '\n\n'
        self.mock_client.listTasks.return_value = tasks

        result = self.runner.invoke(OpenvasCommands.tasks)

        self.assertEqual(resultExpected, result.output)
    def test_list_tasks(self):
        tasks = [{
            'id': generateId(),
            'name': 'Scan of IP' + generateIP(),
            'progress': 'Running: {}%'.format(random.randrange(0, 100)),
            'status': generateString(5)
        } for _ in range(2)]
        resultExpected = '\n\n'.join([
            "{0}.\nScan ID: {1}\nScan progress: {2}".format(
                task['name'], task['id'], task['progress']) for task in tasks
        ]) + '\n\n'
        self.mock_client.listTasks.return_value = tasks

        result = self.runner.invoke(OpenvasCommands.tasks)

        self.assertEqual(resultExpected, result.output, result.exception
                         or result.exit_code)
Exemple #11
0
 def test_add_script(self):
     script = generateString(5)
     self.scanManager.addScript(script)
     self.assertIn(script, self.scanManager.scripts)
Exemple #12
0
 def test_add_script(self):
     script = generateString(5)
     result = self.runner.invoke(NmapCommands.add_script, [script])
     self.assertEqual(result.output, 'Script added: {}\n'.format(script))
 def setUp(self):
     super(ScansTestCase, self).setUp()
     self.configs = {generateString(5): generateId() for _ in range(4)}
 def setUp(self):
     super(ReportsTestCase, self).setUp()
     self.formats = [generateString(10) for _ in range(5)]
     self.reports = [generateString(10) for _ in range(5)]
 def setUp(self, mock_client):
     super(ExploitsTestCase, self).setUp()
     self.exploits = [generateString(10) for _ in range(5)]
     self.exploit_options = {generateString(5): generateString(4) for _ in range(4)}
     self._client.msfClient = mock_client
     self._client.msfClient.modules.exploits = self.exploits
 def setUp(self, mock_client):
     super(PayloadsTestCase, self).setUp()
     self.payloads = [generateString(10) for _ in range(4)]
     self.payload_options = {generateString(5): generateString(4) for _ in range(3)}
     self._client.msfClient = mock_client