def __load_modules(mods, is_user): prefix = "" if not is_user: prefix = "plugins." for loader, mod_name, ispkg in mods: if mod_name not in sys.modules: # Ensure that module isn't already loaded loaded_mod = __import__(prefix + mod_name, fromlist=[mod_name ]) # import the module # get the name of the Plugin class class_name = "" # iterate through all loaded module for name, cls in loaded_mod.__dict__.items(): # check if class has the the right attribute set if hasattr(cls, '_is_plugin'): class_name = name try: loaded_class = getattr(loaded_mod, class_name) container = PluginContainer(loaded_class, self) cmds = getattr(loaded_class, "cmds") for c in cmds: if c in self._plugin_containers: raise PluginError( 'Found duplicate usage of command name %s' % c) self._plugin_containers[c] = container except AttributeError as e: self.pmsg( "WARNING: Failed to load Plugin %s. Skipping this Plugin." % class_name) self.pmsg("Message was: %s" % e.message)
def _load_plugins(self, system_plugin_path, user_plugin_path=None): """ Load all plugins found in the specified path. :param path_list: a list of path where the plugins are located. """ sys_container = PluginContainer(self.SystemPlugin, self) sys_cmds = getattr(self.SystemPlugin, "cmds") for c in sys_cmds: if c in self._plugin_containers: raise PluginError('Found duplicate usage of command name %s' % c) self._system_plugin_containers[c] = sys_container def __load_modules(mods, is_user): prefix = "" if not is_user: prefix = "plugins." for loader, mod_name, ispkg in mods: if mod_name not in sys.modules: # Ensure that module isn't already loaded loaded_mod = __import__(prefix + mod_name, fromlist=[mod_name ]) # import the module # get the name of the Plugin class class_name = "" # iterate through all loaded module for name, cls in loaded_mod.__dict__.items(): # check if class has the the right attribute set if hasattr(cls, '_is_plugin'): class_name = name try: loaded_class = getattr(loaded_mod, class_name) container = PluginContainer(loaded_class, self) cmds = getattr(loaded_class, "cmds") for c in cmds: if c in self._plugin_containers: raise PluginError( 'Found duplicate usage of command name %s' % c) self._plugin_containers[c] = container except AttributeError as e: self.pmsg( "WARNING: Failed to load Plugin %s. Skipping this Plugin." % class_name) self.pmsg("Message was: %s" % e.message) # list modules in the Plugin path system_mods = pkgutil.iter_modules(path=[system_plugin_path]) __load_modules(system_mods, False) if user_plugin_path is not None: sys.path.append(user_plugin_path) framework_mods = pkgutil.iter_modules(path=[user_plugin_path]) __load_modules(framework_mods, True)
def tmsi(self, args): verbose = args.verbose destfile = None mode = args.mode timeslot = args.timeslot burstfile = None if args.bursts is None: raise PluginError("Provide a burst file.") if args.dest_file is not None: destfile = self._data_access_provider.getfilepath(args.dest_file) if args.bursts is not None: burstfile = self._data_access_provider.getfilepath(args.bursts) flowgraph = TmsiCapture(timeslot=timeslot, chan_mode=mode, burst_file=burstfile, cfile=None, fc=None, samp_rate=None, ppm=None) flowgraph.start() flowgraph.wait() tmsis = dict() imsis = dict() with open("tmsicount.txt") as file: content = file.readlines() for line in content: segments = line.strip().split("-") if segments[0] != "0": key = segments[0] if tmsis.has_key(key): tmsis[key] += 1 else: tmsis[key] = 1 else: key = segments[2] if imsis.has_key(key): imsis[key] += 1 else: imsis[key] = 1 self.printmsg("Captured {} TMSI, {} IMSI\n".format(len(tmsis), len(imsis))) if verbose or destfile is not None: sorted_tmsis = sorted(tmsis, key=tmsis.__getitem__, reverse=True) sorted_imsis = sorted(imsis, key=imsis.__getitem__, reverse=True) if destfile is not None: with open(destfile, "w") as file: for key in sorted_tmsis: file.write("{}:{}\n".format(key, tmsis[key])) for key in sorted_imsis: file.write("{}:{}\n".format(key, imsis[key])) if verbose: for key in sorted_tmsis: self.printmsg("{} ({} times)".format(key, tmsis[key])) for key in sorted_imsis: self.printmsg("{} ({} times)".format(key, imsis[key])) os.remove("tmsicount.txt")
def scan_rtlsdr(self, args): if args.speed < 0 or args.speed > 5: raise PluginError("Invalid speed") path = self._config_provider.get("gr-gsm", "apps_path") grgsm_scanner = imp.load_source("", os.path.join(path, "grgsm_scanner")) band = args.band sample_rate = args.samp_rate ppm = args.ppm gain = args.gain speed = args.speed if ppm is None: ppm = self._config_provider.getint("rtl_sdr", "ppm") if sample_rate is None: sample_rate = self._config_provider.getint("rtl_sdr", "sample_rate") if gain is None: gain = self._config_provider.getint("rtl_sdr", "gain") if band == 'DCS1800' or band == 'PCS1900': shmmni = self.get_shmmni() if shmmni < 32000: msg = "Unsufficient shared memory segments.\n" msg += "For scanning DCS1800 or PCS1900 you need to increase the value, i.e. using the following command:\n\n" msg += "sudo sysctl kernel.shmmni=32000" self.printmsg(msg) return channels_num = int(sample_rate / 0.2e6) for arfcn_range in arfcn.get_arfcn_ranges(args.band): try: first_arfcn = arfcn_range[0] last_arfcn = arfcn_range[1] last_center_arfcn = last_arfcn - int((channels_num / 2) - 1) current_freq = arfcn.arfcn2downlink( first_arfcn + int(channels_num / 2) - 1, band) last_freq = arfcn.arfcn2downlink(last_center_arfcn, band) stop_freq = last_freq + 0.2e6 * channels_num while current_freq < stop_freq: # silence rtl_sdr output: with Silencer(): # instantiate scanner and processor scanner = grgsm_scanner.wideband_scanner( rec_len=6 - speed, sample_rate=sample_rate, carrier_frequency=current_freq, ppm=ppm, args="") # start recording scanner.start() scanner.wait() scanner.stop() freq_offsets = numpy.fft.ifftshift( numpy.array( range(int(-numpy.floor(channels_num / 2)), int(numpy.floor( (channels_num + 1) / 2)))) * 2e5) detected_c0_channels = scanner.gsm_extract_system_info.get_chans( ) found_list = [] if detected_c0_channels: chans = numpy.array( scanner.gsm_extract_system_info.get_chans()) found_freqs = current_freq + freq_offsets[(chans)] cell_ids = numpy.array( scanner.gsm_extract_system_info.get_cell_id()) lacs = numpy.array( scanner.gsm_extract_system_info.get_lac()) mccs = numpy.array( scanner.gsm_extract_system_info.get_mcc()) mncs = numpy.array( scanner.gsm_extract_system_info.get_mnc()) ccch_confs = numpy.array( scanner.gsm_extract_system_info.get_ccch_conf( )) powers = numpy.array( scanner.gsm_extract_system_info.get_pwrs()) for i in range(0, len(chans)): cell_arfcn_list = scanner.gsm_extract_system_info.get_cell_arfcns( chans[i]) neighbour_list = scanner.gsm_extract_system_info.get_neighbours( chans[i]) info = grgsm_scanner.channel_info( arfcn.downlink2arfcn(found_freqs[i], band), found_freqs[i], cell_ids[i], lacs[i], mccs[i], mncs[i], ccch_confs[i], powers[i], neighbour_list, cell_arfcn_list) found_list.append(info) scanner = None for info in sorted(found_list): self.printmsg(info.__str__()) if args.verbose: self.printmsg(info.get_verbose_info()) current_freq += channels_num * 0.2e6 except KeyboardInterrupt: self.printmsg("Stopping.")