예제 #1
0
    def createAndAddInterface(
            self,
            host_id,
            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=[]):

        # We don't use interface anymore, so return a host id to maintain
        # backwards compatibility
        # Little hack because we dont want change all the plugins for add hostnames in Host object.
        # SHRUG
        try:
            host = get_host(self.workspace, host_id=host_id)
            host.hostnames = hostname_resolution
            update_host(self.workspace, host, command_id=self.command_id)
        except:
            logger.info(
                "Error updating Host with right hostname resolution...")
        return host_id
예제 #2
0
def update_host(ws, host, key, value):
    if key == 'owned':
        value = value == 'True'
        host.owned = value
        logger.info("Changing property %s to %s in host '%s' with id %s" % (key, value, host.name, host.id))
    else:
        to_add = True
        if key.startswith('-'):
            key = key.strip('-')
            to_add = False

        field = get_field(host, key)
        if field is not None:
            if isinstance(field, str) or isinstance(field, unicode):
                setattr(host, key, value)
                logger.info("Changing property %s to %s in host '%s' with id %s" % (key, value, host.name, host.id))
            else:
                set_array(field, value, add=to_add)
                action = 'Adding %s to %s list in host %s with id %s' % (value, key, host.name, host.id)
                if not to_add:
                    action = 'Removing %s from %s list in host %s with id %s' % (
                        value, key, host.name, host.id)

                logger.info(action)
    try:
        models.update_host(ws, host, "")
    except Exception as error:
        logger.error(error)
        return False

    logger.info("Done")
    return True
예제 #3
0
def update_host(ws, host, key, value):
    if key == 'owned':
        value = value == 'True'
        host.owned = value
        logger.info("Changing property %s to %s in host '%s' with id %s" % (key, value, host.name, host.id))
    else:
        to_add = True
        if key.startswith('-'):
            key = key.strip('-')
            to_add = False

        field = get_field(host, key)
        if field is not None:
            if isinstance(field, str) or isinstance(field, unicode):
                setattr(host, key, value)
                logger.info("Changing property %s to %s in host '%s' with id %s" % (key, value, host.name, host.id))
            else:
                set_array(field, value, add=to_add)
                action = 'Adding %s to %s list in host %s with id %s' % (value, key, host.name, host.id)
                if not to_add:
                    action = 'Removing %s from %s list in host %s with id %s' % (
                        value, key, host.name, host.id)

                logger.info(action)
    try:
        models.update_host(ws, host, "")
    except Exception as error:
        logger.error(error)
        return False

    logger.info("Done")
    return True
예제 #4
0
파일: plugin.py 프로젝트: perplext/faraday
    def createAndAddInterface(
        self, host_id, 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=[]):

        # We don't use interface anymore, so return a host id to maintain
        # backwards compatibility
        # Little hack because we dont want change all the plugins for add hostnames in Host object.
        # SHRUG
        try:
            host = get_host(self.workspace, host_id=host_id)
            host.hostnames = hostname_resolution
            update_host(self.workspace, host, command_id=self.command_id)
        except:
            logger.info("Error updating Host with right hostname resolution...")
        return host_id
예제 #5
0
def save_objs(workspace_name):
    """
        This function uses a set to avoid hitting too much couchdb.
        Wifi packets usually are repeated, for example for beacons.
    :param workspace_name:
    :return:
    """
    order = ['Host', 'Interface', 'Service', 'Vulnerability']
    saved_ids = set()

    tmp = created_objs
    iterable = tmp.items()

    for type in order:
        for key, objs in iterable:
            if key == type:
                try:
                    if key == 'Host':
                        print('Total {0}: {1}'.format(key, len(objs)))
                        for obj in objs:
                            if obj.id in saved_ids:
                                models.update_host(workspace_name, obj)
                            else:
                                models.create_host(workspace_name, obj)
                            saved_ids.add(obj.id)
                    if key == 'Service':
                        print('Total {0}: {1}'.format(key, len(objs)))
                        for obj in objs:
                            if obj.id in saved_ids:
                                models.update_service(workspace_name, obj)
                            else:
                                models.create_service(workspace_name, obj)
                            saved_ids.add(obj.id)
                    if key == 'Vulnerability':
                        print('Total {0}: {1}'.format(key, len(objs)))
                        for obj in objs:
                            if obj.id in saved_ids:
                                models.update_vuln(workspace_name, obj)
                            else:
                                models.create_vuln(workspace_name, obj)
                    if key == 'Interface':
                        print('Total {0}: {1}'.format(key, len(objs)))
                        for obj in objs:
                            if obj.id in saved_ids:
                                models.update_interface(workspace_name, obj)
                            else:
                                models.create_interface(workspace_name, obj)
                            saved_ids.add(obj.id)
                except ConflictInDatabase as e:
                    print('Document already exists skipping.')
                    print(e)
                    continue
                except CantCommunicateWithServerError as e:
                    print('error')
                    print(e)
                except ResourceDoesNotExist as e:
                    print('Missing DB {0}'.format(workspace_name))
                    print(e)
                    continue
                except Exception as e:
                    print(e)