def add_virtual_interface(self, card): """ Add the virtual interface to the host system :param self: A NetworkManager object :param card: A pyw.Card object :type self: NetworkManager :type card: pyw.Card :return name of the interface :rtype str :..note: when add the interface it is possible raising the pyric.error causing by adding the duplicated wlan interface name. """ done_flag = True number = 0 while done_flag: try: number += 1 name = 'wlan' + str(number) pyw.down(card) monitor_card = pyw.devadd(card, name, 'monitor') done_flag = False # catch if wlan1 is already exist except pyric.error: pass self._vifs_add.add(monitor_card) return name
def breakmonitor(): self.iface = pyw.devadd(m0, 'wlan0', 'managed') # restore wlan0 in managed mode pyw.devdel(self.moniface) # delete the monitor interface pyw.setmac(self.iface, self.macaddress) # restore the original mac address pyw.up(self.iface) # and bring the card up
def run(self): print("Starting scanner...") self._abort = False hopper = None try: # set up monitor self._monitor = pyw.devadd(self._iface, Scanner._MON_NAME, 'monitor') for card, dev in pyw.ifaces(self._monitor): if card.dev != self._monitor.dev: pyw.devdel(card) pyw.up(self._monitor) self._iface = None # set up channel hopping hopper = ChannelHopper(self._monitor) hopper.start() sniff(iface=Scanner._MON_NAME, store=0, prn=self._HANDLER, lfilter=Scanner._LFILTER, timeout=self._timeout, stop_filter=self._stop_filter) self.notify_observers((EV_SCAN_OK, )) except pyric.error as e: self.notify_observers((EV_SCAN_FAILED, e)) finally: if hopper: # stop channel hopping hopper.stop() if self._monitor: # destroy monitor interface self._iface = pyw.devadd(self._monitor, self._iface_name, 'managed') pyw.devdel(self._monitor) pyw.up(self._iface) self._monitor = None
def createVirtualInterface(old_iface, new_iface, mode="monitor", channel=1): """ Creates a virtual interface with the specified options and returns its pywric.Card object. (when creating new interface the old one is deleted.) Arguments : old_iface -- old interface name. new_iface -- new interface name. mode -- open the new interface in the given mode (default:monitor). channel -- start the new interface on the given channel. """ # return None if invailed wireless interface if pyw.iswireless(old_iface) == False: return None wi = pyw.getcard(old_iface) # check if the specifed mode is supported by the card if mode in pyw.devmodes(wi): # create new interfaces with the specifed prefix-string default="mon" viface = pyw.devadd(wi, new_iface, mode) # delete all other interfaces with same phy id for card, _ in pyw.ifaces(wi): # delete all interfaces if not card.dev == viface.dev: # that are not our pyw.devdel(card) # set default channel pyw.chset(viface, channel, None) # up the vitual interface pyw.up(viface) # return the newly created interface as pyw.Card() onject return viface
def test_invalidcardarg(self): self.assertRaises(error,pyw.devadd,'bad0','test0','monitor') self.assertRaises(error,pyw.devdel,'bad0') card = pyw.devadd(self.card,'test0','monitor') pyw.devdel(card) self.assertRaises(error,pyw.devdel,card)
def test_devadddel(self): card = pyw.devadd(self.card,'test0','monitor') self.assertTrue(pyw.devdel(card))
def run(self, args, cmd): script_args = argparse.Namespace() script_args.hostapd_wpe_args = to_args_str({ "iface": args.iface, "channel": args.channel, "encryption": args.encryption, "mgt": args.mgt, "password": args.password, "ssid": args.ssid, "karma": args.karma, "mac-acl": args.mac_acl }) script_args.dnsmasq_args = to_args_str({ "start-addr": args.dhcp_start_addr, "end-addr": args.dhcp_end_addr, "lease-time": args.dhcp_lease_time, }) script_args.deauth_args_lst = [] additional_mon_iface = None if args.deauth: additional_mon_iface_name = "{}mon".format(args.iface) cmd.pfeedback( "[i] Creating additional monitor mode interface {} for the continuous deauth attack..." .format(additional_mon_iface_name)) additional_mon_iface = pyw.devadd(pyw.getcard(args.iface), additional_mon_iface_name, "monitor") with db_session: try: for bss in ExtendedServiceSet[args.ssid].bssets.select( lambda bss: bss.channel == args.channel): script_args.deauth_args_lst.append( to_args_str({ "iface": additional_mon_iface_name, "bssid": bss.bssid, "channel": 0, "num-frames": 0, # "client": "FF:FF:FF:FF:FF:FF" })) except: pass pyw.ifaddrset(pyw.getcard(args.iface), args.router_ip, args.netmask) run(["sysctl", "-w", "net.ipv4.ip_forward=1"]) cmd.pfeedback( "[i] Creating NAT rules in iptables for forwarding {} -> {}...". format(args.iface, args.out_iface)) iptc.Table(iptc.Table.NAT).flush() nat_rule = iptc.Rule() nat_rule.src = str( ip_network("{}/{}".format(args.router_ip, args.netmask), strict=False)) nat_rule.out_interface = args.out_iface nat_rule.target = nat_rule.create_target("MASQUERADE") iptc.Chain(iptc.Table(iptc.Table.NAT), "POSTROUTING").append_rule(nat_rule) cmd.pfeedback("[i] Starting hostapd-wpe and dnsmasq...") super().run(script_args, cmd) if additional_mon_iface: cmd.pfeedback( "[i] Deleting the additional monitor mode interface created for the continuous deauth " "attack...") pyw.devdel(additional_mon_iface)
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 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 enable_monitor_mode(self): self._interface_mon = pyw.devadd(self.interface, 'mon0', 'monitor')
def _enable_phisical_interface(self): pyw.devadd(self._interface_mon, self.interface.dev, 'managed')