示例#1
0
 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 remove_vifs_added(self):
        """
        Remove all the added virtual interfaces
        :param self: A NetworkManager object
        :type self: NetworkManager
        :return: None
        :rtype: None
        """

        for card in self._vifs_add:
            pyw.devdel(card)
示例#3
0
    def remove_vifs_added(self):
        """
        Remove all the added virtual interfaces
        :param self: A NetworkManager object
        :type self: NetworkManager
        :return: None
        :rtype: None
        """

        for card in self._vifs_add:
            pyw.devdel(card)
示例#4
0
    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
示例#5
0
    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
示例#6
0
#!/usr/bin/env python
#
# Copyright (C) 2017 Michele Segata <*****@*****.**>
# Copyright (C) 2017 Nicolo' Facchi <*****@*****.**>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#

from pyric import pyw

if __name__ == '__main__':

    # Delete all Wi-Fi interfaces
    wifi_int = pyw.winterfaces()
    for wifi_int_name in wifi_int:
        pyw.devdel(pyw.getcard(wifi_int_name))
 def del_interface(self, ifaceName):
     card = self.get_wifi_chard(ifaceName)  # get a card for interface
     pyw.devdel(card)
示例#8
0
 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)
示例#9
0
 def test_devadddel(self):
     card = pyw.devadd(self.card,'test0','monitor')
     self.assertTrue(pyw.devdel(card))
示例#10
0
    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)
示例#11
0
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")
示例#12
0
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")
示例#13
0
 def _disable_monitor_mode(self, interface):
     pyw.devdel(interface)
示例#14
0
 def _disable_phisical_interface(self):
     for card, _ in pyw.ifaces(self.interface):
         if not card.dev == self._interface_mon.dev:
             pyw.devdel(card)