コード例 #1
0
    def test_getPortsAndServicesByHostIP_InvokedWithFewFilters_ReturnsPortsAndServices(
            self):
        from app.auxiliary import Filters

        expected_query = (
            "SELECT hosts.ip, ports.portId, ports.protocol, ports.state, ports.hostId, ports.serviceId, "
            "services.name, services.product, services.version, services.extrainfo, services.fingerprint "
            "FROM portObj AS ports INNER JOIN hostObj AS hosts ON hosts.id = ports.hostId "
            "LEFT OUTER JOIN serviceObj AS services ON services.id = ports.serviceId "
            "WHERE hosts.ip = ? AND ports.protocol != 'tcp' AND ports.protocol != 'udp'"
        )
        self.mockDbAdapter.metadata.bind.execute.return_value = mockExecuteFetchAll(
            [['ip1'], ['ip2']])

        filters: Filters = Filters()
        filters.apply(up=True,
                      down=True,
                      checked=True,
                      portopen=True,
                      portfiltered=True,
                      portclosed=True,
                      tcp=False,
                      udp=False)
        results = self.repository.getPortsAndServicesByHostIP(
            "some_host_ip", filters)

        self.mockDbAdapter.metadata.bind.execute.assert_called_once_with(
            expected_query, "some_host_ip")
        self.assertEqual([['ip1'], ['ip2']], results)
コード例 #2
0
ファイル: ViewState.py プロジェクト: gnebbia/legion-1
class ViewState:
    # Indicator if any changes have happened since last save (default: False [no changes])
    dirty: bool = False
    # Indicator if 'Save As..' dialog should be used (default: True)
    firstSave = True
    # Indicator of which tabs should be displayed for each host (default: empty dictionary)
    hostTabs = dict()
    # Indicator of the numbering of the bruteforce tabs, incremented when a new tab is added (default: 1)
    bruteTabCount = 1
    # to choose what to display in each panel (default: base filters)
    filters = Filters()
    # Indicator of which host was clicked last (default: None)
    lastHostIdClicked = ''
    # Indicator of which IP Address was clicked on last (default: None)
    ip_clicked = ''
    # Indicator of which Service was clicked on last (default: None)
    service_clicked = ''
    # Indicator of which Tool was clicked on last (default: None)
    tool_clicked = ''
    # Indicator of which script was clicked on last (default: None)
    script_clicked = ''
    # Indicator of which tool host was clicked on last (default: None)
    tool_host_clicked = ''
    # these variables indicate that the corresponding table needs to be updated.
    # 'lazy' means we only update a table at the last possible minute - before the user needs to see it
    lazy_update_hosts = False
    lazy_update_services = False
    lazy_update_tools = False
    # Indicator if a context menu is showing (important to avoid disrupting the user) (default: False)
    menuVisible = False
コード例 #3
0
    def test_getHostsAndPorts_InvokedWithNoFilters_FetchesHostsAndPortsMatchingKeywords(self):
        from app.auxiliary import Filters

        filters: Filters = Filters()
        filters.apply(up=True, down=True, checked=True, portopen=True, portfiltered=True, portclosed=True,
                      tcp=True, udp=True)
        expectedQuery = expectedGetHostsAndPortsQuery()
        self.getHostsAndPortsTestCase(filters=filters,
                                      service_name="some_service_name", expectedQuery=expectedQuery)
コード例 #4
0
 def test_getHosts_InvokedWithNoFilters_ReturnsHosts(self):
     from app.auxiliary import Filters
     self.mockDbAdapter.metadata.bind.execute.return_value = mockExecuteFetchAll([['host1'], ['host2']])
     expectedQuery = "SELECT * FROM hostObj AS hosts WHERE 1=1"
     filters: Filters = Filters()
     filters.apply(up=True, down=True, checked=True, portopen=True, portfiltered=True, portclosed=True,
                   tcp=True, udp=True)
     result = self.hostRepository.getHosts(filters)
     self.assertEqual([['host1'], ['host2']], result)
     self.mockDbAdapter.metadata.bind.execute.assert_called_once_with(expectedQuery)
コード例 #5
0
    def test_getHostsAndPorts_InvokedWithFewFilters_FetchesHostsAndPortsWithFiltersApplied(self):
        from app.auxiliary import Filters

        filters: Filters = Filters()
        filters.apply(up=True, down=False, checked=True, portopen=True, portfiltered=True, portclosed=True,
                      tcp=True, udp=False)
        expectedQuery = expectedGetHostsAndPortsQuery(
            with_filter=" AND hosts.status != 'down' AND ports.protocol != 'udp'")
        self.getHostsAndPortsTestCase(filters=filters,
                                      service_name="some_service_name", expectedQuery=expectedQuery)
コード例 #6
0
    def test_getServiceNames_InvokedWithNoFilters_FetchesAllServiceNames(self):
        from app.auxiliary import Filters

        expectedQuery = ("SELECT DISTINCT service.name FROM serviceObj as service "
                         "INNER JOIN portObj as ports "
                         "INNER JOIN hostObj AS hosts "
                         "ON hosts.id = ports.hostId AND service.id=ports.serviceId WHERE 1=1 "
                         "ORDER BY service.name ASC")
        filters: Filters = Filters()
        filters.apply(up=True, down=True, checked=True, portopen=True, portfiltered=True, portclosed=True,
                      tcp=True, udp=True)
        self.getServiceNamesTestCase(filters=filters, expectedQuery=expectedQuery)
コード例 #7
0
    def test_applyFilters_InvokedWithNoFilters_ReturnsEmptyString(self):
        from app.auxiliary import Filters
        from db.filters import applyFilters

        filters: Filters = Filters()
        filters.apply(up=True,
                      down=True,
                      checked=True,
                      portopen=True,
                      portfiltered=True,
                      portclosed=True,
                      tcp=True,
                      udp=True)
        result = applyFilters(filters)
        self.assertEqual("", result)
コード例 #8
0
    def test_applyFilters_InvokedWithHostCheckedFilter_ReturnsQueryFilterWithHostsChecked(
            self):
        from app.auxiliary import Filters
        from db.filters import applyFilters

        filters: Filters = Filters()
        filters.apply(up=True,
                      down=True,
                      checked=False,
                      portopen=True,
                      portfiltered=True,
                      portclosed=True,
                      tcp=True,
                      udp=True)
        result = applyFilters(filters)
        self.assertEqual(" AND hosts.checked != 'True'", result)
コード例 #9
0
    def test_applyFilters_InvokedWithUdpProtocolFilter_ReturnsQueryFilterWithUdp(
            self):
        from app.auxiliary import Filters
        from db.filters import applyFilters

        filters: Filters = Filters()
        filters.apply(up=True,
                      down=True,
                      checked=True,
                      portopen=True,
                      portfiltered=True,
                      portclosed=True,
                      tcp=True,
                      udp=False)
        result = applyFilters(filters)
        self.assertEqual(" AND ports.protocol != 'udp'", result)
コード例 #10
0
    def test_applyFilters_InvokedWithPortOpenFilter_ReturnsQueryFilterWithPortOpen(
            self):
        from app.auxiliary import Filters
        from db.filters import applyFilters

        filters: Filters = Filters()
        filters.apply(up=True,
                      down=True,
                      checked=True,
                      portopen=False,
                      portfiltered=True,
                      portclosed=True,
                      tcp=True,
                      udp=True)
        result = applyFilters(filters)
        self.assertEqual(
            " AND ports.state != 'open' AND ports.state != 'open|filtered'",
            result)
コード例 #11
0
    def test_applyFilters_InvokedWithKeywordsFilter_ReturnsQueryFilterWithKeywords(
            self):
        from app.auxiliary import Filters
        from db.filters import applyFilters

        filters: Filters = Filters()
        keyword = "some-keyword"
        filters.apply(up=True,
                      down=True,
                      checked=True,
                      portopen=True,
                      portfiltered=True,
                      portclosed=True,
                      tcp=True,
                      udp=True,
                      keywords=[keyword])
        result = applyFilters(filters)
        self.assertEqual(
            " AND (hosts.ip LIKE '%some-keyword%' OR hosts.osMatch LIKE '%some-keyword%'"
            " OR hosts.hostname LIKE '%some-keyword%')", result)