def is_wifi_present(): wlan = pyw.winterfaces() if len(wlan) >= 1: interface = wlan[0] if pyw.isinterface(interface): card = pyw.getcard(interface) info = pyw.ifinfo(card) if pyw.isup(card) is not True: print("Turn On wifi Actual estate:", pyw.isup(card)) wifi_info = {'wifi': interface, 'card': pyw.isup(card), 'mac': pyw.macget(card), 'driver': info.get('driver'), 'chip': info.get('chipset'), 'man': info.get('manufacturer'), 'con': to_json(get_all_info())} print(texto.safe_substitute(wifi_info)) else: wifi_info = {'wifi': interface, 'card': pyw.isup(card), 'mac': pyw.macget(card), 'driver': info.get('driver'), 'chip': info.get('chipset'), 'man': info.get('manufacturer'), 'con': to_json(get_all_info())} print(texto.safe_substitute(wifi_info)) else: print('wifi no encobtrado')
def start(self, args): """ Start the network manager :param self: A NetworkManager object :type self: NetworkManager :param args: An argparse.Namespace object :type args: argparse.Namespace :return: None :rtype: None """ # populate our dictionary with all the available interfaces on the system for interface in pyw.interfaces(): try: card = pyw.getcard(interface) mac_address = pyw.macget(card) adapter = NetworkAdapter(interface, card, mac_address) self._name_to_object[interface] = adapter interface_property_detector(adapter) # ignore devices that are not supported(93) and no such device(19) except pyric.error as error: if error.args[0] in (93, 19): pass elif interface == args.internetinterface: return False else: raise error
def __init__(self, name): """ Setup the class with all the given arguments. :param self: A NetworkAdapter object :param name: Name of the interface :type self: NetworkAdapter :type name: str :return: None :rtype: None .. note: the availability of monitor mode and AP mode is set to False by default """ # Setup the fields self._name = name self._support_ap_mode = False self._support_monitor_mode = False self.being_used = False self._prev_mac = None self._current_mac = None # Set monitor and AP mode if card supports it card = pyw.getcard(name) modes = pyw.devmodes(card) mac = pyw.macget(card) if "monitor" in modes: self._support_monitor_mode = True if "AP" in modes: self._support_ap_mode = True #set the current and prev mac to the origianl mac self._prev_mac = mac self._current_mac = mac
def set_mac_and_unmanage(self, interface, mac, retry = False, virtInterfaces = 0): card = self.get_netcard(interface) # Runs at least once, if retry is flagged # it will try to reset the interface and repeat the process while(True): if card is not None: if not card.set_mac(mac): return False if not self.unmanaged_check(interface) or virtInterfaces > 0: if not self.network_manager_ignore(interface, mac, virtInterfaces): return False os.system("service network-manager restart") # Restarting NetworkManager service if pyw.macget(card.card) == mac: return True if not retry: break print "[-] Unable to set mac and unmanage, resetting interface and retrying." retry = False try: card = NetworkCard(interface) if card.get_mode() != 'managed': card.set_mode('managed') except: return False return False
def set_mac_and_unmanage(self, interface, mac, retry=False): card = self.get_netcard(interface) # Runs at least once, if retry is flagged # it will try to reset the interface and repeat the process while (1): if card != None: if not card.set_mac(mac): return False if not self.network_manager_ignore(interface, mac): return False os.system("service NetworkManager restart" ) # Restarting NetworkManager service if pyw.macget(card.card) == mac: return True if not retry: break print "[-] Unable to set mac and unmanage, resetting interface and retrying." retry = False card = NetworkCard(interface) if card.get_mode() != 'managed': card.set_mode('managed') return False
def getInfo(card_name): """ Returns the dict containing info regarding the wireless card. Dict : {name, channel, ipv4, mac, status} Arguments : card_name -- name of the wireless card """ c = pyw.getcard(card_name) channel = Wireless.getChannel(card_name) status = "" if pyw.isup(c): status = "up" else: status = "down" # one of this function disables during root so autload whichever available. ipv4 = None if "inetget" in dir(pyw): ipv4 = pyw.inetget(c)[0] elif "ifaddrget" in dir(pyw): ipv4 = pyw.ifaddrget(c)[0] mac = pyw.macget(c) return { "name": str(card_name), "channel": str(channel), "ipv4": str(ipv4), "mac": str(mac), "status": str(status) }
def __init__(self, interface): self.interface = interface self.card = pyw.getcard(interface) self.modes = pyw.devmodes(self.card) self.original_mac = pyw.macget(self.card) # Important capabilities self._ap_mode_support = "AP" in self.modes self._monitor_mode_support = "monitor" in self.modes
def __init__(self, interface): self.interface = interface self.card = pyw.getcard(interface) self.modes = pyw.devmodes(self.card) self.original_mac = pyw.macget(self.card) # Important capabilities self._ap_mode_support = "AP" in self.modes self._monitor_mode_support = "monitor" in self.modes self._number_of_supported_aps = None self._is_managed = False
def rename_interface(orig_interface_name): """ Changes the name of the interface to its mac address :param orig_interface_name: The interface that you want to rename """ if pyw.isinterface(orig_interface_name): wifi_card = pyw.getcard(orig_interface_name) pyw.down(wifi_card) new_name = pyw.macget(wifi_card).replace(':', '') print(f"\trenaming {orig_interface_name} to {new_name}") subprocess.run(['ip link set ' + orig_interface_name + ' name ' + new_name], shell=True) wifi_card = pyw.getcard(new_name) pyw.up(wifi_card) else: print("Error: Interface " + str(orig_interface_name) + " does not exist. Cannot rename")
def __init__(self, interface): self.interface = interface self.card = None self.modes = None self.original_mac = None self._ap_mode_support = None self._monitor_mode_support = None try: self.card = pyw.getcard(interface) self.modes = pyw.devmodes(self.card) self.original_mac = pyw.macget(self.card) # Important capabilities self._ap_mode_support = "AP" in self.modes self._monitor_mode_support = "monitor" in self.modes except: pass self._number_of_supported_aps = None self._is_managed = False
def __init__(self, batch_size, sending_interval, wireless_interface, data_store): """ Initialize an aDTN instance and its respective key manager and message store, as well as a sending message pool from which the next sending batch gets generated. Define aDTNInnerPacket to be the payload of aDTNPacket. Define aDTNPacket to be the payload of Ethernet frames of type 0xcafe. Set up a scheduler to handle message sending. Define a thread to handle received messages. The wireless interface should be previously set to ad-hoc mode and its ESSID should be the same in other devices running aDTN. :param batch_size: number of packets to transmit at each sending operation :param sending_interval: number of seconds between two sending operations :param wireless_interface: wireless interface to send and receive packets """ self._batch_size = batch_size self._sending_freq = sending_interval self._wireless_interface = wireless_interface self._km = KeyManager() self.data_store = DataStore(data_store) self._sending_pool = [] self._scheduler = sched.scheduler(time, sleep) self._sending = None self._sniffing = None self._thread_send = None self._thread_receive = None self._sent_pkt_counter = None self._received_pkt_counter = None self._decrypted_pkt_counter = None self._start_time = None self._mac_address = macget(getcard(wireless_interface)) self._sending_socket = L2Socket(iface=self._wireless_interface) bind_layers(aDTNPacket, aDTNInnerPacket) bind_layers(Ether, aDTNPacket, type=ETHERTYPE) log_debug("MAC address in use: {}".format(self._mac_address)) self._stats_file_name = '{}_{}.stats'.format(batch_size, sending_interval)
def start(self): """ Start the network manager :param self: A NetworkManager object :type self: NetworkManager :return: None :rtype: None """ # populate our dictionary with all the available interfaces on the system for interface in pyw.interfaces(): try: card = pyw.getcard(interface) mac_address = pyw.macget(card) adapter = NetworkAdapter(interface, card, mac_address) self._name_to_object[interface] = adapter interface_property_detector(adapter) # ignore devices that are not supported(93) and no such device(19) except pyric.error as error: if error[0] == 93 or error[0] == 19: pass else: raise error
def macaddress(self): return pyw.macget(self._card)
def test_macget(self): self.assertEquals(pri["mac"], pyw.macget(self.card))
def _get_ssid_from_mac(self, mac_address): for iface in pyw.winterfaces(): if pyw.macget(pyw.getcard(iface)) == mac_address: return NetUtils().get_ssid_from_interface(iface)
def test_macget(self): self.assertEqual(pri['mac'],pyw.macget(self.card))
def get_mac(self): return pyw.macget(self.card)
def execute(dev): print('Setting up...') # ensure dev is a wireless interfaces ifaces = pyw.interfaces() wifaces = pyw.winterfaces() if dev not in ifaces: print("Device {0} is not valid, use one of {1}".format(dev, ifaces)) return elif dev not in wifaces: print("Device {0} is not wireless, use one of {1}".format( dev, wifaces)) # get a Card & info for dev print("Regulatory Domain currently: ", pyw.regget()) dinfo = pyw.devinfo(dev) card = dinfo['card'] pinfo = pyw.phyinfo(card) driver = hw.ifdriver(card.dev) chipset = hw.ifchipset(driver) # bring the card down and change the mac pyw.down(card) pyw.macset(card, '00:03:93:57:54:46') # print details msg = "Using {0} currently in mode: {1}\n".format(card, dinfo['mode']) msg += "\tDriver: {0} Chipset: {1}\n".format(driver, chipset) if dinfo['mode'] == 'managed': msg += "\tcurrently on channel {0} width {1}\n".format( rf2ch(dinfo['RF']), dinfo['CHW']) msg += "\tSupports modes {0}\n".format(pinfo['modes']) msg += "\tSupports commands {0}".format(pinfo['commands']) msg += "\thw addr {0}".format(pyw.macget(card)) print(msg) # prepare a virtual interface named pent0 in monitor mode # delete all ifaces on the phy to avoid interference # bring the card up when down print('Preparing pent0 for monitor mode') pdev = 'pent0' pcard = pyw.devadd(card, pdev, 'monitor') for iface in pyw.ifaces(card): if iface[0].dev != pcard.dev: print("deleting {0} in mode {1}".format(iface[0], iface[1])) pyw.devdel(iface[0]) pyw.up(pcard) print("Using", pcard) print("Setting channel to 6 NOHT") pyw.chset(pcard, 6, None) msg = "Virtual interface {0} in monitor mode on ch 6".format(pcard) print(msg + ", using hwaddr: {0}".format(pyw.macget(pcard))) # DO stuff here try: print('Now ready to do stuff') print( 'For example, run wireshark to verify card is seeing all packets') print('Hit Ctrl-C to quit and restore') while True: time.sleep(1) except KeyboardInterrupt: pass # restore original print('Restoring', card, 'mode =', dinfo['mode'], 'mac =', dinfo['mac']) card = pyw.devadd(pcard, card.dev, dinfo['mode']) print('Deleting', pcard) pyw.devdel(pcard) pyw.macset(card, dinfo['mac']) pyw.up(card) print("card ", card, " restored")
def getHwAddr(self, ifaceName): w0 = self.get_wifi_chard(ifaceName) # get a card for interface mac = pyw.macget(w0) return mac
def get_mac(self): try: return pyw.macget(self.card) except: return None
def get_mac(card): return pyw.macget(card)
def get_hwaddr(self): try: w = pyw.getcard(self._interface) return pyw.macget(w) except pyric.error as e: logger.error(e)
def execute(dev): print('Setting up...') # ensure dev is a wireless interfaces ifaces = pyw.interfaces() wifaces = pyw.winterfaces() if dev not in ifaces: print("Device {0} is not valid, use one of {1}".format(dev,ifaces)) return elif dev not in wifaces: print("Device {0} is not wireless, use one of {1}".format(dev,wifaces)) # get a Card & info for dev print("Regulatory Domain currently: ", pyw.regget()) dinfo = pyw.devinfo(dev) card = dinfo['card'] pinfo = pyw.phyinfo(card) driver = hw.ifdriver(card.dev) chipset = hw.ifchipset(driver) # bring the card down and change the mac pyw.down(card) pyw.macset(card,'00:03:93:57:54:46') # print details msg = "Using {0} currently in mode: {1}\n".format(card,dinfo['mode']) msg += "\tDriver: {0} Chipset: {1}\n".format(driver,chipset) if dinfo['mode'] == 'managed': msg += "\tcurrently on channel {0} width {1}\n".format(rf2ch(dinfo['RF']), dinfo['CHW']) msg += "\tSupports modes {0}\n".format(pinfo['modes']) msg += "\tSupports commands {0}".format(pinfo['commands']) msg += "\thw addr {0}".format(pyw.macget(card)) print(msg) # prepare a virtual interface named pent0 in monitor mode # delete all ifaces on the phy to avoid interference # bring the card up when down print('Preparing pent0 for monitor mode') pdev = 'pent0' pcard = pyw.devadd(card, pdev, 'monitor') for iface in pyw.ifaces(card): if iface[0].dev != pcard.dev: print("deleting {0} in mode {1}".format(iface[0],iface[1])) pyw.devdel(iface[0]) pyw.up(pcard) print("Using", pcard) print("Setting channel to 6 NOHT") pyw.chset(pcard,6,None) msg = "Virtual interface {0} in monitor mode on ch 6".format(pcard) print(msg + ", using hwaddr: {0}".format(pyw.macget(pcard))) # DO stuff here try: print('Now ready to do stuff') print('For example, run wireshark to verify card is seeing all packets') print('Hit Ctrl-C to quit and restore') while True: time.sleep(1) except KeyboardInterrupt: pass # restore original print('Restoring', card, 'mode =', dinfo['mode'], 'mac =', dinfo['mac']) card = pyw.devadd(pcard,card.dev,dinfo['mode']) print('Deleting', pcard) pyw.devdel(pcard) pyw.macset(card,dinfo['mac']) pyw.up(card) print("card ", card, " restored")
def __init__(self, args): self.mPackets = 0 self.clients = [] self.APs = [] self.firstPass = True self.mIgnoreList = [ 'ff:ff:ff:ff:ff:ff', '00:00:00:00:00:00', '33:33:00:', '33:33:ff:', '01:80:c2:00:00:00', '01:00:5e:', '01:00:0c'] + \ [pyw.macget(pyw.getcard(x)) for x in pyw.winterfaces()] + \ [x for x in args['skip'] if re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", x.lower())] # Args self.mInterface = args["interface"] self.mFrequency = args["frequency"] self.mChannels = args["channel"] self.mKill = args["kill"] self.mDirected = args["directed"] self.mTargets = [x for x in args['targets'] if re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", x.lower())] self.mMaximum = int(args["maximum"]) self.mPackets = int(args["pkts"]) self.mTimeout = float(args["timeout"]) self.mChannel = pyw.chget(pyw.getcard(self.mInterface)) self.mDetailed = args['details'] self.mLoglevel = args['loglevel'] self.mSSID = args['ssid'] LogLevels={'info': logging.INFO, 'error': logging.ERROR, 'debug': logging.DEBUG, 'critical': logging.CRITICAL} logging.basicConfig( level=LogLevels[self.mLoglevel], format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s', datefmt='%Y/%m/%d %H:%M:%S') if self.mFrequency == "2": self.mChannels = [int(x) for x in self.mChannels if int(x) in range(1, 12)] if self.mChannels == []: self.mChannels = list(range(1, 12)) elif self.mFrequency == "5": self.mChannels = [int(x) for x in self.mChannels if int(x) in five_hertz] if self.mChannels == []: self.mChannels = five_hertz else: self.mChannels = [int(x) for x in self.mChannels if int(x) in range(1, 12) or int(x) in five_hertz] if self.mChannels == []: self.mChannels = list(range(1, 12)) + five_hertz if pyw.modeget(self.mInterface) != 'monitor': logging.debug('Enabling monitor mode on interface '+self.mInterface) start_mon_mode(self.mInterface) if self.mKill: os.system('pkill NetworkManager') conf.iface = self.mInterface return