def set_interface_mac(self, interface_name, mac_address): """ Set the specified MAC address for the interface :param self: A NetworkManager object :param interface_name: Name of an interface :param mac_address: A MAC address :type self: NetworkManager :type interface_name: str :type mac_address: str :return: None :rtype: None .. note: This method will set the interface to managed mode """ card = self._name_to_object[interface_name].card self.set_interface_mode(interface_name, "managed") # card must be turned off(down) before setting mac address try: pyw.down(card) pyw.macset(card, mac_address) pyw.up(card) # make sure to catch an invalid mac address except pyric.error as error: if error[0] == 22: raise InvalidMacAddressError(mac_address) else: raise
def set_interface_mac(self, interface_name, mac_address=None): """ Set the specified MAC address for the interface :param self: A NetworkManager object :param interface_name: Name of an interface :param mac_address: A MAC address :type self: NetworkManager :type interface_name: str :type mac_address: str :return: new MAC :rtype: str .. note: This method will set the interface to managed mode """ if not mac_address: mac_address = generate_random_address() self._name_to_object[interface_name].mac_address = mac_address card = self._name_to_object[interface_name].card self.set_interface_mode(interface_name, "managed") self.down_interface(interface_name) # card must be turned off(down) before setting mac address try: pyw.macset(card, mac_address) # make sure to catch an invalid mac address except pyric.error as error: raise InvalidMacAddressError(mac_address) return mac_address
def set_interface_mac(self, interface_name, mac_address): """ Set the specified MAC address for the interface :param self: A NetworkManager object :param interface_name: Name of an interface :param mac_address: A MAC address :type self: NetworkManager :type interface_name: str :type mac_address: str :return: None :rtype: None .. note: This method will set the interface to managed mode """ card = self._name_to_object[interface_name].card self.set_interface_mode(interface_name, "managed") self.down_interface(interface_name) # card must be turned off(down) before setting mac address try: pyw.macset(card, mac_address) # make sure to catch an invalid mac address except pyric.error as error: if error[0] == 22: raise InvalidMacAddressError(mac_address) else: raise
def set_mac(self, mac): try: pyw.down(self.card) pyw.macset(self.card, mac) pyw.up(self.card) return True except Exception as e: print e, "\n[-] Unable to set mac on {}".format(self.interface) return False
def set_mac(self, mac): try: pyw.down(self.card) # If card was in monitor mode then macset wouldn't work right if pyw.modeget(self.card) == "monitor": pyw.modeset(self.card, "managed") pyw.macset(self.card, mac) pyw.up(self.card) return True except Exception as e: print e, "\n[-] Unable to set mac on {}".format(self.interface) return False
def recover_mac_address_to_original(self): """ Recover the mac addresses to original one on exit :param self: A NetworkManager object :type self: NetworkManager :return: None :rtype: None """ for k, i in self._interfaces.iteritems(): if i._prev_mac != i._current_mac: card = pyw.getcard(i.get_name()) pyw.down(card) pyw.macset(card, i._prev_mac) pyw.up(card)
def randomize_interface_mac(self, mac=None): """ Randomize the MACs for the network adapters :param self: A NetworkAdapter object :param mac: A MAC address :type self: NetworkAdapter :type mac: string :return: None :rtype: None """ mac_addr = self._generate_random_address() if mac is None else mac card = pyw.getcard(self.get_name()) pyw.down(card) pyw.macset(card, mac_addr) self._current_mac = mac_addr
def set_interface_mac(self, interface_name, mac_address): # type: (str, str) -> None """Set the specified MAC address for the interface. .. note: This method will set the interface to managed mode """ card = self._name_to_object[interface_name].card self.set_interface_mode(interface_name, "managed") self.down_interface(interface_name) # card must be turned off(down) before setting mac address try: pyw.macset(card, mac_address) # make sure to catch an invalid mac address except pyric.error as error: if error[0] == 22: raise InvalidMacAddressError(mac_address) else: raise
def set_hwaddr(self, addr): try: w = pyw.getcard(self._interface) pyw.macset(w, addr) except pyric.error as e: logger.error(e)
def set_mac_address(self, iface, new_mac_addr): ''' Sets a new MAC address on wireless interface ''' w0 = self.get_wifi_chard(iface) # get a card for interface pyw.macset(w0, new_mac_addr)
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 test_macset(self): self.assertEqual(newhw, pyw.macset(self.card, newhw)) self.assertEqual(pri["mac"], pyw.macset(self.card, pri["mac"]))
def test_macset(self): self.assertEqual(newhw,pyw.macset(self.card,newhw)) self.assertEqual(pri['mac'],pyw.macset(self.card,pri['mac']))
def set_mac(interface, mac): return pyw.macset(interface, mac)
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 change_mac_addr(self, new_mac): self._disable_interface(self.interface) pyw.macset(self.interface, new_mac) self._enable_interface(self.interface)