├── README.md └── listmap.py /README.md: -------------------------------------------------------------------------------- 1 | # ListMap 2 | Created by: Shane Young/x90skysn3k 3 | 4 | # Description 5 | Listmap was made to save time when parsing through nmap output. Listmap creates lists of IP's based on the ports you specify. Listmap can aid in creating lists of IP adresses with open ports that can be referenced by other tools. Listmap was created to save time, basically saving your fingers from typing so many 'cat' & 'cut' statements through your gnmap outputs. 6 | 7 | # Usage 8 | Command: python listmap.py -h 9 | 10 | Example: python listmap.py --file nmapoutput.gnmap --port 3390,443,80,22,21 --prefix pentest 11 | * Generate a list of all hosts (by IP address) with open ports 3390,443,80,22,21 in NMap output file nmapoutput.gnamp. Prefix the output file name with 'pentest' 12 | 13 | Example: python listmap.py --file nmapoutput.gnmap --ip 172.1.2.3,172.2.3.4 --prefix pentest 14 | * Generate a list of all open ports for the IP addresses 172.1.2.3 and 172.2.3.4, prefix the output file name with 'pentest' 15 | 16 | Example: python listmap.py --file nmapoutput.gnamp --csv 17 | * Generate a two-column CSV file in the format of IP Address | Open Ports from the NMap output file nmapoutput.gnmap 18 | -------------------------------------------------------------------------------- /listmap.py: -------------------------------------------------------------------------------- 1 | from argparse import RawTextHelpFormatter 2 | import sys, time, os 3 | import re 4 | import argparse 5 | import argcomplete 6 | import csv 7 | 8 | timestr = time.strftime("%Y%m%d-%H%M") 9 | 10 | 11 | class colors: 12 | white = "\033[1;37m" 13 | normal = "\033[0;00m" 14 | red = "\033[1;31m" 15 | blue = "\033[1;34m" 16 | green = "\033[1;32m" 17 | lightblue = "\033[0;34m" 18 | 19 | 20 | banner = colors.red + r""" 21 | _ _ 22 | (_ ) _ ( )_ 23 | | | (_) ___ | ,_) ___ ___ _ _ _ _ 24 | | | | |/',__)| | /' _ ` _ `\ /'_` )( '_`\ 25 | | | | |\__, \| |_ | ( ) ( ) |( (_| || (_) ) 26 | (___)(_)(____/`\__)(_) (_) (_)`\__,_)| ,__/' 27 | | | 28 | (_) 29 | 30 | """+'\n' \ 31 | + '\n listmap.py v1.1' \ 32 | + '\n Created by: Shane Young/@x90skysn3k' \ 33 | + '\n Contributors: Aaron Herndon/@ac3lives, Gabriel Cornyn/@caesarcipher' + colors.normal + '\n' 34 | 35 | 36 | def ip_by_port(): 37 | for port in port_list: 38 | with open(args.file, 'r') as nmap_file: 39 | iplist = [] 40 | for line in nmap_file: 41 | if ' '+port+'/open' in line: 42 | ip = re.findall( r'[0-9]+(?:\.[0-9]+){3}', line) 43 | iplist += ip 44 | 45 | output = output_name(str('-' + port), '.txt') 46 | with open(output, 'w+') as f: 47 | f.write('\n'.join(iplist)) 48 | f.write('\n') 49 | print "\nThe Port: " + colors.green + port + colors.normal + " is open on these IP's: " 50 | print iplist 51 | print "\nWritten list to: " + "[" + colors.green + "+" + colors.normal + "] " + colors.green + output + colors.normal 52 | 53 | def output_name(additional, ftype): 54 | if args.datetime: 55 | filename = args.directory + "/" + args.prefix + additional + '_' + timestr + ftype 56 | else: 57 | filename = args.directory + "/" + args.prefix + additional + ftype 58 | return filename 59 | 60 | def port_by_ip(): 61 | for ip in ip_list: 62 | with open(args.file, 'r') as nmap_file: 63 | portlist = [] 64 | for line in nmap_file: 65 | if ' '+ip+' ' in line: 66 | port = re.findall( '(\d+)\/open', line) 67 | portlist += port 68 | 69 | output = output_name('-' + ip, '.txt') 70 | with open(output, 'w+') as f: 71 | f.write('\n'.join(portlist)) 72 | f.write('\n') 73 | print "\nThe IP: " + colors.green + ip + colors.normal + " has these open ports: " 74 | print portlist 75 | print "\nWritten list to: " + "[" + colors.green + "+" + colors.normal + "] " + colors.green + output + colors.normal 76 | 77 | #Generate URLs brought to you by @ac3lives 78 | def generate_urls(): 79 | output = output_name("", ".txt") 80 | outputfile = open(output, 'w+') 81 | with open(args.file, 'r') as nmap_file: 82 | for line in nmap_file: 83 | ip = None 84 | try: 85 | ip = re.findall( r'[0-9]+(?:\.[0-9]+){3}', line)[0] 86 | except: 87 | pass 88 | openhttps = re.findall('(\d+)\/open/tcp//https///',line) 89 | openhttp = re.findall('(\d+)\/open/tcp//http///',line) 90 | for port in openhttps: 91 | outputfile.write("https://"+ip+":"+port+"\n") 92 | for port in openhttp: 93 | outputfile.write("http://"+ip+":"+port+"\n") 94 | 95 | #CSV code thanks to @ac3lives! 96 | def do_csv(): 97 | output = output_name("", ".csv") 98 | outputfile = csv.writer(open(output, 'w+'), delimiter=',') 99 | with open(args.file, 'r') as nmap_file: 100 | for line in nmap_file: 101 | ip = None 102 | try: 103 | ip = re.findall( r'[0-9]+(?:\.[0-9]+){3}', line)[0] 104 | except: 105 | pass 106 | openports = re.findall( '(\d+)\/open', line) 107 | ports = '; '.join(map(str, openports)) 108 | if ip and ports: 109 | outputlist = [ip, ports] 110 | outputfile.writerow(outputlist) 111 | 112 | print "\nWritten list to: " + "[" + colors.green + "+" + colors.normal + "] " + colors.green + output + colors.normal 113 | 114 | def parse_args(): 115 | 116 | parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description=\ 117 | 118 | banner + 119 | "Usage: python listmap.py \n") 120 | 121 | menu_group = parser.add_argument_group(colors.lightblue + 'Menu Options' + colors.normal) 122 | 123 | menu_group.add_argument('-f', '--file', help="Gnmap file to parse", required=True) 124 | 125 | # menu_group.add_argument('-t', '--top-ports', help="Parse out top interesting ports") 126 | 127 | menu_group.add_argument('-p', '--port', help="Define single port to parse out", default=None) 128 | 129 | menu_group.add_argument('-o', '--prefix', help="Specify prefix for output file i.e. company name", default="listmap") 130 | 131 | menu_group.add_argument('-i', '--ip', help="Parse out ports by ip", default=None) 132 | 133 | menu_group.add_argument('-c', '--csv', help="output ip and port to csv", action="store_true", default=False) 134 | 135 | menu_group.add_argument('--no-datetime', help="Do not place date and time stamps at the end of output file names", action="store_false", dest="datetime", default=True) 136 | 137 | menu_group.add_argument('-d', '--directory', help="Specify an output directory, default is listmap-data", default="listmap-data") 138 | 139 | menu_group.add_argument('-u', '--urls', help="Generate a list of URLs from http/https output in file. Format: http(s)://:", default=False, action="store_true") 140 | 141 | argcomplete.autocomplete(parser) 142 | 143 | args = parser.parse_args() 144 | 145 | output = None 146 | 147 | return args,output 148 | 149 | 150 | if __name__ == "__main__": 151 | print(banner) 152 | args,output = parse_args() 153 | if not os.path.exists(args.directory): 154 | os.mkdir(args.directory) 155 | 156 | if args.port: 157 | port_list = args.port.split(',') 158 | elif args.ip: 159 | ip_list = args.ip.split(',') 160 | elif not args.csv or args.urls: 161 | print colors.lightblue + "\nNo IP or Port Given!" + colors.normal 162 | 163 | if args.port: 164 | ip_by_port() 165 | elif args.ip: 166 | port_by_ip() 167 | elif args.csv: 168 | do_csv() 169 | elif args.urls: 170 | generate_urls() 171 | 172 | 173 | 174 | 175 | 176 | --------------------------------------------------------------------------------