def main(argv=None): '''Command line options.''' program_name = os.path.basename(sys.argv[0]) program_version = "v0.1" program_version_string = '%%prog %s' % (program_version) program_license = "Copyright 2017 Rosalia d'Alessandro\ Licensed under the Apache License 2.0\ http://www.apache.org/licenses/LICENSE-2.0" if argv is None: argv = sys.argv[1:] lstn = None try: # setup option parser parser = OptionParser(version=program_version_string, description=program_license) parser.add_option("-v", "--verbose", dest="verbose", action="count", help="Set verbosity level [default: %default]") parser.add_option("-c", "--config", dest="config_file", help="Configuration file [default: %default]") parser.add_option("-r", "--remote_net", dest="remote_net", help="Remote network e.g. 10.0.0.0/24, 10.0.0.1/32") parser.add_option("-l", "--listening", dest="listening_mode", action="count", help="Start also a GTP_C listener") parser.add_option("-o", "--output", dest="output_file", help="Output file") # parser.add_option("-n", "--num_msg", dest = "num_msg", # help = "Num of messages") # set defaults parser.set_defaults(listening_mode=True, verbose=False, config_file="../config/TeidAllocationDiscover.cnf", output_file="") # process options (opts, args) = parser.parse_args(argv) is_verbose = opts.verbose listening_mode = opts.listening_mode msg_freq = DEFAULT_SLEEPTIME remote_net = opts.remote_net sleep_time = DEFAULT_SLEEPTIME if listening_mode and remote_net == None: print "remote network (e.g. 10.0.0.0/24, 10.0.0.1/32) is required" return # MAIN BODY # if opts.config_file is None or opts.config_file == "": print "Error: missed config file" return # # if opts.num_msg is None or opts.num_msg == "" or int(opts.num_msg) == 0 : # print "Error: missed num of messages to send" # return config = parseConfigs(opts.config_file) msgs = config.get_unpacked_messages() lstn = MessageHandler(messages=msgs, peer=remote_net, isVerbose=is_verbose, listening_mode=listening_mode, msgs_freq=msg_freq, wait_time=sleep_time) if lstn: lstn.daemon = True lstn.start() lstn.join() lstn.stop() print "Sent %d GTPV2 messages" % len(msgs) fd = None if not listening_mode: return if opts.output_file != "": fd = open(opts.output_file, 'w') printed = False for key, value in message_queue.items(): for k, v in value.items(): for i in v: if i['reply'] == 1: if not printed: print "%s implements a GTP v2 stack" % key printed = True print "%s : < local teid %s, remote teid %s>" % ( GTPmessageTypeStr[k], format(i['local_teid'], '#08X'), i['remote_teid']) if fd: fd.write("%s implements a GTP v2 stack" % key) fd.write("for %d msg type created teid %s" % (k, i['remote_teid'])) except Exception, e: indent = len(program_name) * " " sys.stderr.write(program_name + ": " + repr(e) + "\n") sys.stderr.write(indent + " for help use --help") print "Exception %s" % str(e) if lstn: lstn.stop() return 2
def main(argv=None): '''Command line options.''' program_name = os.path.basename(sys.argv[0]) program_version = "v0.1" program_version_string = '%%prog %s' % (program_version) program_license = "Copyright 2017 Rosalia d'Alessandro\ Licensed under the Apache License 2.0\ nhttp://www.apache.org/licenses/LICENSE-2.0" if argv is None: argv = sys.argv[1:] lstn = None try: # setup option parser parser = OptionParser(version=program_version_string, description=program_license) parser.add_option("-v", "--verbose", dest="verbose", action="count", help="set verbosity level [default: %default]") parser.add_option("-c", "--config", dest="config_file", help="the configuration file") parser.add_option("-r", "--remote_net", dest="remote_net", help="remote network e.g. 10.0.0.0/24, 10.0.0.1/32") parser.add_option("-l", "--listening", dest="listening_mode", action="count", help="start also a GTP_C listener") # set defaults parser.set_defaults(listening_mode=False, config_file="../config/UserDoS.cnf", verbose=False) # process options (opts, args) = parser.parse_args(argv) is_verbose = False listening_mode = opts.listening_mode msg_freq = DEFAULT_SLEEPTIME remote_net = opts.remote_net sleep_time = DEFAULT_SLEEPTIME if listening_mode and remote_net == None: print("remote network (e.g. 10.0.0.0/24, 10.0.0.1/32) is required") return # MAIN BODY # if opts.config_file == "": print("Error: missed config file") return config = parseConfigs(opts.config_file) msgs = config.get_unpacked_messages() lstn = MessageHandler(messages=msgs, peer=remote_net, isVerbose=is_verbose, listening_mode=listening_mode, msgs_freq=msg_freq, wait_time=sleep_time) if lstn: lstn.daemon = True lstn.start() lstn.join() lstn.stop() print(("Sent %d GTPV2 messages" % len(message_queue))) except Exception as e: indent = len(program_name) * " " sys.stderr.write(program_name + ": " + repr(e) + "\n") sys.stderr.write(indent + " for help use --help") print(("Exception %s" % str(e))) if lstn: lstn.stop() return 2
def main(config_file, target, listening=True, verbose=2, output_file=""): lstn = None try: listening_mode = listening is_verbose = verbose msg_freq = DEFAULT_SLEEPTIME remote_net = target sleep_time = DEFAULT_SLEEPTIME if listening_mode and remote_net == None: print "\033[33m[!]\033[0m remote network (e.g. 10.0.0.0/24, 10.0.0.1/32) is required" return # MAIN BODY # if sys.argv[0] == "": print "\033[31m[-]Error:\033[0m missed config file" return # # if opts.num_msg is None or opts.num_msg == "" or int(opts.num_msg) == 0 : # print "Error: missed num of messages to send" # return config = parseConfigs(config_file) msgs = config.get_unpacked_messages() lstn = MessageHandler(messages=msgs, peer=remote_net, isVerbose=is_verbose, listening_mode=listening_mode, msgs_freq=msg_freq, wait_time=sleep_time) if lstn: lstn.daemon = True lstn.start() lstn.join() lstn.stop() print "\033[34m[*]\033[0m Sent %d GTPV2 messages" % (len(msgs)) fd = None if not listening_mode: return if output_file != "": fd = open(output_file, 'w') printed = False for key, value in message_queue.items(): for k, v in value.items(): for i in v: if i['reply'] == 1: if not printed: print "\033[32m[+]\033[0m %s implements a GTP v2 stack" % key printed = True print "\033[32m[+]\033[0m%s : < local teid %s, remote teid %s>" % ( GTPmessageTypeStr[k], format(i['local_teid'], '#08X'), i['remote_teid']) if fd: fd.write("%s implements a GTP v2 stack" % key) fd.write("for %d msg type created teid %s" % (k, i['remote_teid'])) except Exception, e: print "\033[31m[-]Error:\033[0m %s" % str(e) if lstn: lstn.stop() return 2
def main(config_file, target, listening=True, verbose = 2, output_file='results.csv'): lstn = None try: listening_mode = listening is_verbose = verbose msg_freq = DEFAULT_SLEEPTIME remote_net = target sleep_time = DEFAULT_SLEEPTIME if listening_mode and remote_net == None: print("remote network (e.g. 10.0.0.0/24, 10.0.0.1/32) is required") return # MAIN BODY # if config_file == "" : print("\033[31m[-]Error:\033[0m missed config file") return config = parseConfigs(config_file) msgs = config.get_unpacked_messages() lstn = MessageHandler(messages = msgs, peer = remote_net, isVerbose = is_verbose, listening_mode = listening_mode, msgs_freq = msg_freq, wait_time = sleep_time) if lstn : lstn.daemon = True lstn.start() lstn.join() lstn.stop() print(("Sent %d GTPV2 messages"%len(message_queue))) if not listening_mode : return #Remote TEID represents the new TEID used by the PGW. printed = False for key, value in list(message_queue.items()): for k,v in list(value.items()): for i in v : if i['reply'] == 1: if not printed : print(("\033[32m[+]\033[0m %s implements a GTP v2 stack"%key)) printed = True print(("%s : < local teid %s, remote teid %s>"%( GTPmessageTypeStr[k], format(i['local_teid'], '#08X'), i['remote_teid']))) except Exception as e: print(("\033[31m[-]Error:\033[0m %s"%str(e))) if lstn : lstn.stop() return 2
def main(config_file, target, listening=True, verbose = 2): lstn = None try: listening_mode = listening is_verbose = verbose msg_freq = DEFAULT_SLEEPTIME remote_net = target sleep_time = DEFAULT_SLEEPTIME if listening_mode and remote_net == None: print "\033[33m[!]\033[0m remote network (e.g. 10.0.0.0/24, 10.0.0.1/32) is required" return # MAIN BODY # if sys.argv[0] == "" : print "\033[31m[-]Error:\033[0m missed config file" return config = parseConfigs(config_file) msgs = config.get_unpacked_messages() port = config.get_gtp_port() lstn = MessageHandler(messages = msgs, peer = remote_net, isVerbose = is_verbose, listening_mode = listening_mode, msgs_freq = msg_freq, wait_time = sleep_time, port = port) if lstn : lstn.daemon = True lstn.start() lstn.join() lstn.stop() print "\033[34m[*]\033[0m Sent %d GTPV2 messages"%(len(message_queue)) if not listening_mode : return gtp_nodes = [] for key, value in message_queue.items(): for k,v in value.items(): for i in v : if i['reply'] == 1: gtp_nodes.append(key) print "\033[32m[+]\033[0m %s implements a GTP v2 stack"%key break num_gtp_nodes = len(gtp_nodes) if num_gtp_nodes > 0 : print "\033[32m[+]\033[0m Found in total %d targets implemeting a GTP v2 stack "%num_gtp_nodes print "\033[32m[+]\033[0m List of discovered GTPv2 nodes" for n in gtp_nodes : print n,"\n" else : print "\033[31m[-]\033[0m Not found targets implemeting a GTP v2 stack" except Exception, e: print "\033[31m[-]Error:\033[0m %s"%str(e) if lstn : lstn.stop() return 2
def main(argv=None): '''Command line options.''' program_name = os.path.basename(sys.argv[0]) program_version = "v0.1" program_version_string = '%%prog %s' % (program_version) program_license = "Copyright 2017 Rosalia d'Alessandro\ Licensed under the Apache License 2.0\ nhttp://www.apache.org/licenses/LICENSE-2.0" if argv is None: argv = sys.argv[1:] lstn = None try: # setup option parser parser = OptionParser(version=program_version_string, description=program_license) parser.add_option("-v", "--verbose", dest="verbose", action="count", help="set verbosity level [default: %default]") parser.add_option("-c", "--config", dest="config_file", help="the configuration file") parser.add_option("-r", "--remote_net", dest="remote_net", help="remote network e.g. 10.0.0.0/24, 10.0.0.1/32") parser.add_option("-l", "--listening", dest = "listening_mode", action = "count", help = "start also a GTP_C listener") # set defaults parser.set_defaults(listening_mode=False, config_file="../config/GTPEchoNodesDiscovery.cnf", verbose = 0) # process options (opts, args) = parser.parse_args(argv) is_verbose = opts.verbose listening_mode = opts.listening_mode msg_freq = DEFAULT_SLEEPTIME remote_net = opts.remote_net sleep_time = DEFAULT_SLEEPTIME if listening_mode and remote_net == None: print "remote network (e.g. 10.0.0.0/24, 10.0.0.1/32) is required" return # MAIN BODY # if opts.config_file == "" : print "Error: missed config file" return config = parseConfigs(opts.config_file) msgs = config.get_unpacked_messages() port = config.get_gtp_port() lstn = MessageHandler(messages = msgs, peer = remote_net, isVerbose = is_verbose, listening_mode = listening_mode, msgs_freq = msg_freq, wait_time = sleep_time, port = port) if lstn : lstn.daemon = True lstn.start() lstn.join() lstn.stop() print "Sent %d GTPV2 messages"%(len(message_queue)) if not listening_mode : return gtp_nodes = [] for key, value in message_queue.items(): for k,v in value.items(): for i in v : if i['reply'] == 1: gtp_nodes.append(key) break num_gtp_nodes = len(gtp_nodes) if num_gtp_nodes > 0 : print "Found in total %d targets implemeting a GTPv2 stack"%num_gtp_nodes print "List of discovered GTPv2 nodes" for n in gtp_nodes : print n,"\n" else : print "Not found targets implementing a GTPv2 stack" except Exception, e: indent = len(program_name) * " " sys.stderr.write(program_name + ": " + repr(e) + "\n") sys.stderr.write(indent + " for help use --help") print "Exception %s"%str(e) if lstn : lstn.stop() return 2