How to use the ivre.utils.LOGGER.warning function in ivre

To help you get started, we’ve selected a few ivre examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cea-sec / ivre / ivre / tools / passivereconworker.py View on Github external
handled_ok = True
        for line in fdesc:
            try:
                proc.stdin.write(line)
            except ValueError:
                utils.LOGGER.warning("Error while handling line %r. "
                                     "Trying again", line)
                proc = create_process(progname, fname_sensor)
                procs[fname_sensor] = proc
                # Second (and last) try
                try:
                    proc.stdin.write(line)
                    utils.LOGGER.warning("  ... OK")
                except ValueError:
                    handled_ok = False
                    utils.LOGGER.warning("  ... KO")
        fdesc.close()
        if handled_ok:
            os.unlink(fname)
            utils.LOGGER.debug('  ... OK')
        else:
            utils.LOGGER.debug('  ... KO')
    # SHUTDOWN
    for sensorjob in procs:
        procs[sensorjob].stdin.close()
        procs[sensorjob].wait()
github cea-sec / ivre / ivre / xmlnmap.py View on Github external
This function is not perfect but should do the job in most
    cases.

    """
    assert script["id"] == "afp-ls"
    result = {"total": {"files": 0, "bytes": 0}, "volumes": []}
    state = 0  # volumes / listings
    cur_vol = None
    for line in script["output"].splitlines():
        if state == 0:
            if line.startswith('    PERMISSION'):
                pass
            elif line.startswith('    '):
                if cur_vol is None:
                    utils.LOGGER.warning("Skip file entry outside a "
                                         "volume [%r]", line[4:])
                else:
                    (permission, uid, gid, size, date, time,
                     fname) = line[4:].split(None, 6)
                    if size.isdigit():
                        size = int(size)
                        result["total"]["bytes"] += size
                    cur_vol["files"].append({"permission": permission,
                                             "uid": uid, "gid": gid,
                                             "size": size, "filename": fname,
                                             'time': "%s %s" % (date, time)})
                    result["total"]["files"] += 1
            elif line.startswith("  ERROR: "):
                # skip error messages, same as when running without
                # setting ls.errors=true
                pass
github cea-sec / ivre / ivre / xmlnmap.py View on Github external
def _read_ssh_key_exchange_init(cls, data):
        # cookie
        if len(data) < 16:
            utils.LOGGER.warning('SSH key exchange init message too '
                                 'short [%r] (len == %d < 16)',
                                 data, len(data))
            return
        data = data[16:]
        keys = cls._ssh_key_exchange_data[::-1]
        while data and keys:
            if len(data) < 4:
                utils.LOGGER.warning('Incomplete SSH key exchange init message'
                                     ' part [%r]', data)
                return
            length = struct.unpack('>I', data[:4])[0]
            data = data[4:]
            curdata, data = data[:length], data[length:]
            if curdata:
                yield keys.pop(), curdata.decode().split(',')
            else:
                yield keys.pop(), []
github cea-sec / ivre / ivre / parser / bro.py View on Github external
def parse_header_line(self, line):
        if not line:
            return
        if line[:1] != b"#":
            LOGGER.warning("Not a header line")
            return

        keyval = line[1:].split(self.sep, 1)
        if len(keyval) < 2:
            if line.startswith(b'#separator '):
                keyval = [b'separator', line[11:]]
            else:
                LOGGER.warning("Invalid header line")
                return

        directive = keyval[0]
        arg = keyval[1]

        if directive == b"separator":
            self.sep = decode_hex(arg[2:]) if arg.startswith(b'\\x') else arg
        elif directive == b"set_separator":
github cea-sec / ivre / ivre / db / sql / __init__.py View on Github external
self.tables.script.data])
               .select_from(join(join(self.tables.scan, self.tables.port),
                                 self.tables.script))
               .where(and_(self.tables.scan.schema_version == 13,
                           self.tables.script.name.in_(scripts))))
        for rec in self.db.execute(req):
            if rec.name in rec.data:
                migr_func = (
                    xmlnmap.change_ssh_hostkey
                    if rec.name == 'ssh-hostkey' else
                    xmlnmap.change_ls_migrate
                )
                try:
                    data = migr_func(rec.data[rec.name])
                except Exception:
                    utils.LOGGER.warning("Cannot migrate host %r", rec.id,
                                         exc_info=True)
                    failed.add(rec.id)
                else:
                    if data:
                        self.db.execute(
                            update(self.tables.script)
                            .where(and_(self.tables.script.port == rec.port,
                                        self.tables.script.name == rec.name))
                            .values(data={rec.name: data})
                        )
        self.db.execute(
            update(self.tables.scan)
            .where(and_(self.tables.scan.schema_version == 13,
                        self.tables.scan.id.notin_(failed)))
            .values(schema_version=14)
        )
github cea-sec / ivre / ivre / xmlnmap.py View on Github external
output=raw_output,
                        proto=self._curport['protocol'],
                        probe=probe,
                    )
                if match:
                    self._curport.update(match)
                return
            for attr in attrs.keys():
                self._curport['service_%s' % attr] = attrs[attr]
            for field in ['service_conf', 'service_rpcnum',
                          'service_lowver', 'service_highver']:
                if field in self._curport:
                    self._curport[field] = int(self._curport[field])
        elif name == 'script':
            if self._curscript is not None:
                utils.LOGGER.warning("self._curscript should be None at this "
                                     "point (got %r)", self._curscript)
            self._curscript = dict([attr, attrs[attr]]
                                   for attr in attrs.keys())
        elif name in ['table', 'elem']:
            if self._curscript.get('id') in IGNORE_TABLE_ELEMS:
                return
            if name == 'elem':
                # start recording characters
                if self._curdata is not None:
                    utils.LOGGER.warning("self._curdata should be None at "
                                         "this point (got %r)", self._curdata)
                self._curdata = ''
            if 'key' in attrs:
                key = attrs['key'].replace('.', '_')
                obj = {key: {}}
            else:
github cea-sec / ivre / ivre / tools / runscans.py View on Github external
while b'' in self.data:
            hostbeginindex = self.data.index(
                self.hostbegin.search(self.data).group())
            self.scaninfo.write(self.data[:hostbeginindex])
            self.scaninfo.flush()
            if self.isstarting:
                self.startinfo += self.statusline.sub(
                    b'', self.data[:hostbeginindex],
                )
                self.isstarting = False
            self.data = self.data[hostbeginindex:]
            hostrec = self.data[:self.data.index(b'') + 7]
            try:
                addr = self.addrrec.search(hostrec).groups()[0]
            except Exception:
                ivre.utils.LOGGER.warning("Exception for record %r", hostrec,
                                          exc_info=True)
            if self.status_up in hostrec:
                status = 'up'
            elif self.status_down in hostrec:
                status = 'down'
            else:
                status = 'unknown'
            outfile = self.path + status + \
                '/' + addr.decode().replace('.', '/') + '.xml'
            ivre.utils.makedirs(os.path.dirname(outfile))
            with open(outfile, 'wb') as out:
                # out.write(b'\n' % starttime)
                out.write(self.startinfo)
                out.write(hostrec)
                out.write(b'\n\n')
            self.data = self.data[self.data.index(b'') + 7:]
github cea-sec / ivre / ivre / db / sql / __init__.py View on Github external
self.tables.script.data])
               .select_from(join(join(self.tables.scan, self.tables.port),
                                 self.tables.script))
               .where(and_(self.tables.scan.schema_version == 11,
                           self.tables.script.name.in_(["fcrdns",
                                                        "rpcinfo"]))))
        for rec in self.db.execute(req):
            if rec.name in rec.data:
                migr_func = {
                    'fcrdns': xmlnmap.change_fcrdns_migrate,
                    'rpcinfo': xmlnmap.change_rpcinfo,
                }[rec.name]
                try:
                    data = migr_func(rec.data[rec.name])
                except Exception:
                    utils.LOGGER.warning("Cannot migrate host %r", rec.id,
                                         exc_info=True)
                    failed.add(rec.id)
                else:
                    if data:
                        self.db.execute(
                            update(self.tables.script)
                            .where(and_(self.tables.script.port == rec.port,
                                        self.tables.script.name == rec.name))
                            .values(data={rec.name: data})
                        )
        self.db.execute(
            update(self.tables.scan)
            .where(and_(self.tables.scan.schema_version == 11,
                        self.tables.scan.id.notin_(failed)))
            .values(schema_version=12)
        )
github cea-sec / ivre / ivre / db / maxmind.py View on Github external
def __init__(self, _):
        utils.LOGGER.warning("Cannot find Maxmind database files")