示例#1
0
def main(args, root_or_admin):
    spoofer = None

    try:
        spoofer = get_os_spoofer()
    except NotImplementedError:
        return UNSUPPORTED_PLATFORM

    if args['list']:
        list_interfaces(args, spoofer)
    elif args['randomize'] or args['set'] or args['reset']:
        for target in args['<devices>']:
            # Fill out the details for `target`, which could be a Hardware
            # Port or a literal device.
            #print("Debuf:",target)
            result = find_interface(target)
            if result is None:
                print('- couldn\'t find the device for {target}'.format(
                    target=target
                ))
                return INVALID_TARGET

            port, device, address, current_address = result
            if args['randomize']:
                target_mac = random_mac_address(args['--local'])
            elif args['set']:
                target_mac = args['<mac>']
            elif args['reset']:
                if address is None:
                    print('- {target} missing hardware MAC'.format(
                        target=target
                    ))
                    continue
                target_mac = address

            if not MAC_ADDRESS_R.match(target_mac):
                print('- {mac} is not a valid MAC address'.format(
                    mac=target_mac
                ))
                return INVALID_MAC_ADDR

            if not root_or_admin:
                if sys.platform == 'win32':
                    print('Error: Must run this with administrative privileges to set MAC addresses')
                    return NON_ROOT_USER
                else:
                    print('Error: Must run this as root (or with sudo) to set MAC addresses')
                    return NON_ROOT_USER

            set_interface_mac(device, target_mac, port)
    elif args['normalize']:
        print(normalize_mac_address(args['<mac>']))

    else:
        print('Error: Invalid arguments - check help usage')
        return INVALID_ARGS

    del spoofer

    return SUCCESS
示例#2
0
    def changemac(self, widget):
        global tmac
        print "change mac"
        try:
            root_or_admin = os.geteuid() == 0
        except AttributeError:
            root_or_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0

        spoofer = None

        try:
            spoofer = get_os_spoofer()
        except NotImplementedError:
            return UNSUPPORTED_PLATFORM
        result = find_interface(self.entry.entry.get_text())
        if result is None:
            print('- couldn\'t find the device for {target}'.format(
                target=target))
            self.statelbl.set_text("Couldn't find device ")
            return INVALID_TARGET

        port, device, address, current_address = result
        target_mac = tmac
        if int(target_mac[1], 16) % 2:
            self.statelbl.set_text("It's Multicast Address")
            print(
                'Warning: The address you supplied is a multicast address and thus can not be used as a host address.'
            )

        if not MAC_ADDRESS_R.match(target_mac):
            print('- {mac} is not a valid MAC address'.format(mac=target_mac))
            return INVALID_MAC_ADDR
        if not root_or_admin:
            if sys.platform == 'win32':
                print(
                    'Error: Must run this with administrative privileges to set MAC addresses'
                )
                self.statelbl.set_text("You Need to run as admin")
                return NON_ROOT_USER
            else:
                print(
                    'Error: Must run this as root (or with sudo) to set MAC addresses'
                )
                self.statelbl.set_text("You Need to run as root")
                return NON_ROOT_USER
        asd = set_interface_mac(device, target_mac, port)
        time.sleep(10)
        self.statelbl.set_text("Mac Spoofed")
        self.getifinfo(widget)
        if checkcon():
            intsp = getintspeed()
            self.intsplbl.set_text("Download rate :" + intsp[0] +
                                   "Upload rate :" + intsp[1])
        else:
            self.intsplbl.set_text("No Internet Connection")
示例#3
0
    def get_interface_mac(self, device):
        """
        Returns currently-set MAC address of given interface. This is
        distinct from the interface's hardware MAC address.
        """

        try:
            result = subprocess.check_output(['ifconfig', device],
                                             stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError:
            return None

        address = MAC_ADDRESS_R.search(result.upper())
        if address:
            address = address.group(0)

        return address
示例#4
0
    def get_interface_mac(self, device):
        """
        Returns currently-set MAC address of given interface. This is
        distinct from the interface's hardware MAC address.
        """

        try:
            result = subprocess.check_output([
                'ifconfig',
                device
            ], stderr=subprocess.STDOUT, universal_newlines=True)
        except subprocess.CalledProcessError:
            return None

        address = MAC_ADDRESS_R.search(result.upper())
        if address:
            address = address.group(0)

        return address
示例#5
0
def normalize_mac_address(mac):
    """
    Takes a MAC address in various formats:

        - 00:00:00:00:00:00,
        - 00.00.00.00.00.00,
        - 0000.0000.0000

    ... and returns it in the format 00:00:00:00:00:00.
    """
    m = CISCO_MAC_ADDRESS_R.match(mac)
    if m:
        new_mac = ''.join([g.zfill(4) for g in m.groups()])
        return ':'.join(_chunk(new_mac, 2)).upper()

    m = MAC_ADDRESS_R.match(mac)
    if m:
        return ':'.join([g.zfill(2) for g in m.groups()]).upper()

    return None
示例#6
0
    def find_interfaces(self, targets=None):
        """
        Returns the list of interfaces found on this machine as reported
        by the `networksetup` command.
        """
        targets = [t.lower() for t in targets] if targets else []
        # Parse the output of `networksetup -listallhardwareports` which gives
        # us 3 fields per port:
        # - the port name,
        # - the device associated with this port, if any,
        # - The MAC address, if any, otherwise 'N/A'
        details = re.findall(
            r'^(?:Hardware Port|Device|Ethernet Address): (.+)$',
            subprocess.check_output((
                'networksetup',
                '-listallhardwareports'
            ), universal_newlines=True), re.MULTILINE
        )
        # Split the results into chunks of 3 (for our three fields) and yield
        # those that match `targets`.
        for i in range(0, len(details), 3):
            port, device, address = details[i:i + 3]

            address = MAC_ADDRESS_R.match(address.upper())
            if address:
                address = address.group(0)

            current_address = self.get_interface_mac(device)

            if not targets:
                # Not trying to match anything in particular,
                # return everything.
                yield port, device, address, current_address
                continue

            for target in targets:
                if target in (port.lower(), device.lower()):
                    yield port, device, address, current_address
                    break
示例#7
0
def main(args, root_or_admin):
    spoofer = None

    try:
        spoofer = get_os_spoofer()
    except NotImplementedError:
        return UNSUPPORTED_PLATFORM

    if args['list']:
        list_interfaces(args, spoofer)
    elif args['randomize'] or args['set'] or args['reset']:
        for target in args['<devices>']:
            # Fill out the details for `target`, which could be a Hardware
            # Port or a literal device.
            #print("Debuf:",target)
            result = find_interface(target)
            if result is None:
                print('- couldn\'t find the device for {target}'.format(
                    target=target))
                return INVALID_TARGET

            port, device, address, current_address = result
            if args['randomize']:
                target_mac = random_mac_address(args['--local'])
            elif args['set']:
                target_mac = args['<mac>']
                if int(target_mac[1], 16) % 2:
                    print(
                        'Warning: The address you supplied is a multicast address and thus can not be used as a host address.'
                    )
            elif args['reset']:
                if address is None:
                    print('- {target} missing hardware MAC'.format(
                        target=target))
                    continue
                target_mac = address

            if not MAC_ADDRESS_R.match(target_mac):
                print('- {mac} is not a valid MAC address'.format(
                    mac=target_mac))
                return INVALID_MAC_ADDR

            if not root_or_admin:
                if sys.platform == 'win32':
                    print(
                        'Error: Must run this with administrative privileges to set MAC addresses'
                    )
                    return NON_ROOT_USER
                else:
                    print(
                        'Error: Must run this as root (or with sudo) to set MAC addresses'
                    )
                    return NON_ROOT_USER

            set_interface_mac(device, target_mac, port)
    elif args['normalize']:
        print(normalize_mac_address(args['<mac>']))

    else:
        print('Error: Invalid arguments - check help usage')
        return INVALID_ARGS

    del spoofer

    return SUCCESS
示例#8
0
def main(args, root_or_admin):
    spoofer = None

    try:
        spoofer = get_os_spoofer()
    except NotImplementedError:
        return UNSUPPORTED_PLATFORM

    if args['list']:
        list_interfaces(args, spoofer)
    elif args['randomize'] or args['set'] or args['reset']:
        for target in args['<devices>']:
            # Fill out the details for `target`, which could be a Hardware
            # Port or a literal device.
            #print("Debuf:",target)
            result = find_interface(target)
            if result is None:
                print('- couldn\'t find the device for {target}'.format(
                    target=target))
                return INVALID_TARGET

            port, device, address, current_address = result
            if args['randomize']:
                target_mac = random_mac_address(args['--local'])
            elif args['set']:
                target_mac = args['<mac>']
                if int(target_mac[1], 16) % 2:
                    print(
                        'Warning: The address you supplied is a multicast address and thus can not be used as a host address.'
                    )
            elif args['reset']:
                if address is None:
                    print('- {target} missing hardware MAC'.format(
                        target=target))
                    continue
                target_mac = address

            if not MAC_ADDRESS_R.match(target_mac):
                print('- {mac} is not a valid MAC address'.format(
                    mac=target_mac))
                return INVALID_MAC_ADDR

            if not root_or_admin:
                if sys.platform == 'win32':
                    print(
                        'Error: Must run this with administrative privileges to set MAC addresses'
                    )
                    return NON_ROOT_USER
                else:
                    print(
                        'Error: Must run this as root (or with sudo) to set MAC addresses'
                    )
                    return NON_ROOT_USER

            # Expand acceptable input MAC is displayed with atleast the
            # following (-: )
            p = re.compile('[^0-9A-Z]')
            target_mac = p.sub(':', target_mac.upper())
            (prt, dev, addr, cur_addr) = spoofer.find_interface(device)
            etime = time.strftime('%X')

            if target_mac != cur_addr:
                set_interface_mac(device, target_mac, prt)
                print etime + " " + port + " [" + device + "] set to " + target_mac
            else:
                if args['--force']:
                    set_interface_mac(device, target_mac, prt)
                    print etime + " " + prt + " [" + device + "] forced to " + target_mac
                elif '--maintain' not in args:
                    print(
                        'Error: Already the current MAC addresses, use --force to force the address again'
                    )
                    # return EXISTING_MAC_ADDR
            if args['--maintain']:
                sys.stdout.write("\r" + etime + " " + prt + " [" + device +
                                 "] " + cur_addr)
                sys.stdout.flush()

    elif args['normalize']:
        print(normalize_mac_address(args['<mac>']))

    else:
        print('Error: Invalid arguments - check help usage')
        return INVALID_ARGS

    del spoofer

    return SUCCESS