コード例 #1
0
ファイル: ranges.py プロジェクト: taufderl/jackal
def main():
    rs = RangeSearch()
    arg = argparse.ArgumentParser(parents=[rs.argparser],
                                  conflict_handler='resolve')
    arg.add_argument('-c',
                     '--count',
                     help="Only show the number of results",
                     action="store_true")
    arg.add_argument('-a',
                     '--add',
                     help="Add a new range",
                     action="store_true")
    arguments = arg.parse_args()
    if arguments.add:
        print_notification("Adding new range")
        range_str = input("What range do you want to add? ")
        r = rs.id_to_object(range_str)
        print_success("Added a new range:")
        print_json(r.to_dict(include_meta=True))
    elif arguments.count:
        print_line("Number of ranges: {}".format(rs.argument_count()))
    else:
        response = rs.get_ranges()
        for hit in response:
            print_json(hit.to_dict(include_meta=True))
コード例 #2
0
ファイル: ranges.py プロジェクト: taufderl/jackal
def overview():
    """
        Creates a overview of the hosts per range.
    """
    range_search = RangeSearch()
    ranges = range_search.get_ranges()
    if ranges:
        formatted_ranges = []
        tags_lookup = {}
        for r in ranges:
            formatted_ranges.append({'mask': r.range})
            tags_lookup[r.range] = r.tags
        search = Host.search()
        search = search.filter('term', status='up')
        search.aggs.bucket('hosts',
                           'ip_range',
                           field='address',
                           ranges=formatted_ranges)
        response = search.execute()
        print_line("{0:<18} {1:<6} {2}".format("Range", "Count", "Tags"))
        print_line("-" * 60)
        for entry in response.aggregations.hosts.buckets:
            print_line("{0:<18} {1:<6} {2}".format(entry.key, entry.doc_count,
                                                   tags_lookup[entry.key]))
    else:
        print_error("No ranges defined.")
コード例 #3
0
ファイル: nmap.py プロジェクト: taufderl/jackal
def nmap_discover():
    """
        This function retrieves ranges from jackal
        Uses two functions of nmap to find hosts:
            ping:   icmp / arp pinging of targets
            lookup: reverse dns lookup
    """
    rs = RangeSearch()
    rs_parser = rs.argparser
    arg = argparse.ArgumentParser(parents=[rs_parser],
                                  conflict_handler='resolve')
    arg.add_argument('type', metavar='type', \
        help='The type of nmap scan to do, choose from ping or lookup', \
        type=str, choices=['ping', 'lookup'])
    arguments, nmap_args = arg.parse_known_args()

    tag = None
    if arguments.type == 'ping':
        tag = 'nmap_ping'
        nmap_args.append('-sn')
        nmap_args.append('-n')
        check_function = include_up_hosts
    elif arguments.type == 'lookup':
        tag = 'nmap_lookup'
        nmap_args.append('-sL')
        check_function = include_hostnames

    ranges = rs.get_ranges(tags=['!{}'.format(tag)])
    ranges = [r for r in ranges]
    ips = []
    for r in ranges:
        ips.append(r.range)

    print_notification("Running nmap with args: {} on {} range(s)".format(
        nmap_args, len(ips)))
    result = nmap(nmap_args, ips)
    stats = import_nmap(result, tag, check_function)
    stats['scanned_ranges'] = len(ips)

    Logger().log(
        'nmap_discover', "Nmap discover with args: {} on {} range(s)".format(
            nmap_args, len(ips)), stats)

    for r in ranges:
        r.add_tag(tag)
        r.save()
コード例 #4
0
def main():
    ranges = RangeSearch()
    arguments = ranges.argparser.parse_args()
    if arguments.tags or ranges.is_pipe:
        ranges = ranges.get_ranges()
    else:
        ranges = ranges.search(tags=['!netdiscover'])

    results = 0
    for r in ranges:
        discover = NetDiscover(r)
        results += discover.execute()
        discover.save()

    Logger().log('netdiscover',
                 "Netdiscover on {} ranges".format(len(ranges)),
                 stats={
                     'scanned_ranges': len(ranges),
                     'hosts': results
                 })