Exemplo n.º 1
0
Arquivo: scan2db.py Projeto: ivre/ivre
 def callback(x: Record) -> None:
     ivre.db.db.view.store_or_merge_host(nmap_record_to_view(x))
Exemplo n.º 2
0
 def callback(x):
     return ivre.db.db.view.store_or_merge_host(nmap_record_to_view(x))
Exemplo n.º 3
0
def main():
    try:
        import argparse
        parser = argparse.ArgumentParser(
            description='Parse NMAP scan results and add them in DB.')
        parser.add_argument('scan', nargs='*', metavar='SCAN',
                            help='Scan results')

    except ImportError:
        import optparse
        parser = optparse.OptionParser(
            description='Parse NMAP scan results and add them in DB.')
        parser.parse_args_orig = parser.parse_args

        def my_parse_args():
            res = parser.parse_args_orig()
            res[0].ensure_value('scan', res[1])
            return res[0]
        parser.parse_args = my_parse_args
        parser.add_argument = parser.add_option

    parser.add_argument('-c', '--categories', default='',
                        help='Scan categories.')
    parser.add_argument('-s', '--source', default=None,
                        help='Scan source.')
    parser.add_argument('-t', '--test', action='store_true',
                        help='Test mode (JSON output).')
    parser.add_argument('--test-normal', action='store_true',
                        help='Test mode ("normal" Nmap output).')
    parser.add_argument('--ports', '--port', action='store_true',
                        help='Store only hosts with a "ports" element.')
    parser.add_argument('--open-ports', action='store_true',
                        help='Store only hosts with open ports.')
    parser.add_argument('--merge', action='store_true', help='Merge '
                        'result with previous scan result for same host '
                        'and source. Useful to use multiple partial '
                        'scan results (e.g., one with -p 80, another '
                        'with -p 21).')
    parser.add_argument('--masscan-probes', nargs='+', metavar='PROBE',
                        help='Additional Nmap probes to use when trying to '
                        'match Masscan results against Nmap service '
                        'fingerprints.')
    parser.add_argument('--force-info', action='store_true',
                        help='Force information (AS, country, city, etc.)'
                        ' renewal (only useful with JSON format)')
    parser.add_argument('-r', '--recursive', action='store_true',
                        help='Import all files from given directories.')
    parser.add_argument('--no-update-view', action='store_true',
                        help='Do not merge hosts in current view')
    args = parser.parse_args()
    database = ivre.db.db.nmap
    categories = args.categories.split(',') if args.categories else []
    callback = lambda x: ivre.db.db.view.store_or_merge_host(
        nmap_record_to_view(x)
    )
    if args.test:
        args.no_update_view = True
        database = ivre.db.DBNmap()
    if args.test_normal:
        args.no_update_view = True
        database = ivre.db.DBNmap(output_mode="normal")
    if args.recursive:
        scans = recursive_filelisting(args.scan)
    else:
        scans = args.scan
    if args.no_update_view:
        callback = None
    count = 0
    for scan in scans:
        try:
            if database.store_scan(
                    scan,
                    categories=categories, source=args.source,
                    needports=args.ports, needopenports=args.open_ports,
                    force_info=args.force_info,
                    masscan_probes=args.masscan_probes, callback=callback,
            ):
                count += 1
        except Exception:
            ivre.utils.LOGGER.warning("Exception (file %r)", scan,
                                      exc_info=True)
    print("%d results imported." % count)
Exemplo n.º 4
0
Arquivo: app.py Projeto: psyray/ivre
 def callback(x):
     db.view.start_store_hosts()
     res = db.view.store_or_merge_host(nmap_record_to_view(x))
     db.view.stop_store_hosts()
     return res
Exemplo n.º 5
0
 def callback(x):
     return ivre.db.db.view.store_or_merge_host(
         nmap_record_to_view(x)
     )