Beispiel #1
0
    def get_scanned():

        formatted_nodes = []

        nodes = \
            [NodeService.get_displayed_node_by_id(node['_id'], True) for node in mongo.db.node.find({}, {'_id': 1})] \
            + [NodeService.get_displayed_node_by_id(monkey['_id'], True) for monkey in
               mongo.db.monkey.find({}, {'_id': 1})]
        for node in nodes:
            formatted_nodes.append({
                'label':
                node['label'],
                'ip_addresses':
                node['ip_addresses'],
                'accessible_from_nodes': (x['hostname'] for x in (
                    NodeService.get_displayed_node_by_id(edge['from'], True)
                    for edge in EdgeService.get_displayed_edges_by_to(
                        node['id'], True))),
                'services':
                node['services']
            })

        logger.info('Scanned nodes generated for reporting')

        return formatted_nodes
Beispiel #2
0
    def get_displayed_node_by_id(node_id, for_report=False):
        if ObjectId(node_id) == NodeService.get_monkey_island_pseudo_id():
            return NodeService.get_monkey_island_node()

        edges = EdgeService.get_displayed_edges_by_to(node_id, for_report)
        accessible_from_nodes = []
        exploits = []

        new_node = {"id": node_id}

        node = NodeService.get_node_by_id(node_id)
        if node is None:
            monkey = NodeService.get_monkey_by_id(node_id)
            if monkey is None:
                return new_node

            # node is infected
            new_node = NodeService.monkey_to_net_node(monkey, for_report)
            for key in monkey:
                if key not in [
                        '_id', 'modifytime', 'parent', 'dead', 'description'
                ]:
                    new_node[key] = monkey[key]

        else:
            # node is uninfected
            new_node = NodeService.node_to_net_node(node, for_report)
            new_node["ip_addresses"] = node["ip_addresses"]
            new_node["domain_name"] = node["domain_name"]

        for edge in edges:
            accessible_from_nodes.append(
                NodeService.get_monkey_label(
                    NodeService.get_monkey_by_id(edge["from"])))
            for exploit in edge["exploits"]:
                exploit["origin"] = NodeService.get_monkey_label(
                    NodeService.get_monkey_by_id(edge["from"]))
                exploits.append(exploit)

        exploits.sort(cmp=NodeService._cmp_exploits_by_timestamp)

        new_node["exploits"] = exploits
        new_node["accessible_from_nodes"] = accessible_from_nodes
        if len(edges) > 0:
            new_node["services"] = edges[-1]["services"]
        else:
            new_node["services"] = []

        new_node['has_log'] = cc.services.log.LogService.log_exists(
            ObjectId(node_id))
        return new_node
    def get_scanned():
        nodes = \
            [NodeService.get_displayed_node_by_id(node['_id'], True) for node in mongo.db.node.find({}, {'_id': 1})] \
            + [NodeService.get_displayed_node_by_id(monkey['_id'], True) for monkey in
               mongo.db.monkey.find({}, {'_id': 1})]
        nodes = [
            {
                'label': node['label'],
                'ip_addresses': node['ip_addresses'],
                'accessible_from_nodes':
                    (x['hostname'] for x in
                     (NodeService.get_displayed_node_by_id(edge['from'], True)
                      for edge in EdgeService.get_displayed_edges_by_to(node['id'], True))),
                'services': node['services']
            }
            for node in nodes]

        return nodes
Beispiel #4
0
    def get_displayed_node_by_id(node_id, for_report=False):
        if ObjectId(node_id) == NodeService.get_monkey_island_pseudo_id():
            return NodeService.get_monkey_island_node()

        edges = EdgeService.get_displayed_edges_by_to(node_id, for_report)
        accessible_from_nodes = []
        exploits = []

        new_node = {"id": node_id}

        node = NodeService.get_node_by_id(node_id)
        if node is None:
            monkey = NodeService.get_monkey_by_id(node_id)
            if monkey is None:
                return new_node

            # node is infected
            new_node = NodeService.monkey_to_net_node(monkey, for_report)
            for key in monkey:
                if key not in ['_id', 'modifytime', 'parent', 'dead', 'description']:
                    new_node[key] = monkey[key]

        else:
            # node is uninfected
            new_node = NodeService.node_to_net_node(node, for_report)
            new_node["ip_addresses"] = node["ip_addresses"]

        for edge in edges:
            accessible_from_nodes.append(NodeService.get_monkey_label(NodeService.get_monkey_by_id(edge["from"])))
            for exploit in edge["exploits"]:
                exploit["origin"] = NodeService.get_monkey_label(NodeService.get_monkey_by_id(edge["from"]))
                exploits.append(exploit)

        exploits.sort(cmp=NodeService._cmp_exploits_by_timestamp)

        new_node["exploits"] = exploits
        new_node["accessible_from_nodes"] = accessible_from_nodes
        if len(edges) > 0:
            new_node["services"] = edges[-1]["services"]
        else:
            new_node["services"] = []

        new_node['has_log'] = cc.services.log.LogService.log_exists(ObjectId(node_id))
        return new_node
Beispiel #5
0
    def get_scanned():
        nodes = \
            [NodeService.get_displayed_node_by_id(node['_id'], True) for node in mongo.db.node.find({}, {'_id': 1})] \
            + [NodeService.get_displayed_node_by_id(monkey['_id'], True) for monkey in
               mongo.db.monkey.find({}, {'_id': 1})]
        nodes = [{
            'label':
            node['label'],
            'ip_addresses':
            node['ip_addresses'],
            'accessible_from_nodes': (x['hostname'] for x in (
                NodeService.get_displayed_node_by_id(edge['from'], True)
                for edge in EdgeService.get_displayed_edges_by_to(
                    node['id'], True))),
            'services':
            node['services']
        } for node in nodes]

        return nodes