Пример #1
0
    def __init__(self, config={}):
        """
            Sets up main file.

            :TODO:
                - Make parameter_file default value configurable, or shorter.
                - Extra-capabilities stuff is still confusing
        """
        self.config = config
        self._target = Target()
        self._mon_iface = None
        self.target_dir = tempfile.mkdtemp()
        self.resources_dir = os.path.join(os.path.dirname(unicode(__file__, sys.getfilesystemencoding())), "resources")
        if 'parameter_file' not in self.config:
            self.config['parameter_file'] = os.path.join(self.resources_dir,
                                                         "parameters.json")
        self.parameters = json.load(open(self.config['parameter_file']))
        self.aircrack = AircrackSession(self.parameters)
        self.extra_capabilities = dict([(extra, getattr(getattr(capabilities, extra), 'main')(self)) for extra in capabilities.__all__])
        self.reaver_targets = []
        for cap_name in capabilities.__all__:
            # This is so we can have external capabilities to manage attacks in hackability stuff.
            # Right now, to use reaver =P
            setattr(self, cap_name, lambda x, _name=cap_name:
                    self.extra_capabilities[_name].hack(x))
Пример #2
0
class AiroscriptSession(Airoscript):
    """
        Basic airoscriptng session object.
        This is the basic airoscriptng object.
        Handles network interfaces.
        Main interaction with outer world will be here.

    """
    def __init__(self, config={}):
        """
            Sets up main file.

            :TODO:
                - Make parameter_file default value configurable, or shorter.
                - Extra-capabilities stuff is still confusing
        """
        self.config = config
        self._target = Target()
        self._mon_iface = None
        self.target_dir = tempfile.mkdtemp()
        self.resources_dir = os.path.join(os.path.dirname(unicode(__file__, sys.getfilesystemencoding())), "resources")
        if 'parameter_file' not in self.config:
            self.config['parameter_file'] = os.path.join(self.resources_dir,
                                                         "parameters.json")
        self.parameters = json.load(open(self.config['parameter_file']))
        self.aircrack = AircrackSession(self.parameters)
        self.extra_capabilities = dict([(extra, getattr(getattr(capabilities, extra), 'main')(self)) for extra in capabilities.__all__])
        self.reaver_targets = []
        for cap_name in capabilities.__all__:
            # This is so we can have external capabilities to manage attacks in hackability stuff.
            # Right now, to use reaver =P
            setattr(self, cap_name, lambda x, _name=cap_name:
                    self.extra_capabilities[_name].hack(x))

    def list_wifi(self):
        """
            Returns a list of all the available wireless networks
        """
        # If the driver is not using the new stack, screw them.
        return [iface for iface in netifaces.interfaces() if "wlan" in iface]

    def setup_wifi(self, iface):
        """
            Starts monitor mode interface and checks it's ok.

            :TODO:
                - Injection test.
        """
        self.config['wifi'] = iface
        os.environ['MON_PREFIX'] = self.config["name"]
        self.should_be_mon_iface = self.config["name"] + "0"
        ifaddr = netifaces.ifaddresses(self.config['wifi'])
        self.mac_addr = ifaddr[netifaces.AF_LINK][0]['addr']

        if self.should_be_mon_iface not in netifaces.interfaces():
            self.aircrack.airmon(OrderedDict([('command', "start"),
                ('wireless', self.config["wifi"])]), self.set_mon_iface)
        else:
            self._mon_iface = self.should_be_mon_iface
        return self._mon_iface

    def get_mac_addr(self):
        """
            Return mac address of the interface
        """
        return self.mac_addr

    @property
    def mon_iface(self):
        """
            Return current monitor interface name
        """
        return self._mon_iface

    @mon_iface.setter
    def mon_iface(self, mon_iface):
        """
            Sets monitor interface (setter)
        """
        self._mon_iface = mon_iface

    def set_mon_iface(self, result):
        """
            Sets monitor interface.
            Checks that final monitor interface is really what it should be.
        """
        mon_result = result.communicate()
        for line in mon_result[0].splitlines():
            mon_regex = '(.*)\((.*)monitor mode enabled on (.*)\)(.*)'
            monitor_test = re.match(mon_regex, line)
            if monitor_test:
                self._mon_iface = monitor_test.group(3)
                if not self.mon_iface == self.should_be_mon_iface:
                    debug("Monitor interface is {} and should be {}".format(
                        self.mon_iface, self.should_be_mon_iface))
        return True

    def del_mon_iface(self):
        """
            Deletes own monitor interface from system (cleanup)
        """
        return self.aircrack.launch("iw", [self.mon_iface, "del"])

    @property
    def target(self):
        """
            Returns currently selected target (getter)
        """
        return self.get_target

    def get_target(self):
        """
            Returns currently selected target, clean to send it via xmlrpc
        """
        return clean_to_xmlrpc(self._target, ['properties', 'parent'])

    @target.setter
    def target(self, target):
        """
            target setter
        """
        return self.set_target(target)

    def set_target(self, target):
        """
            This way we only have to do something like
            self.target = current_targets[10] and it'll automatically
            make an object from it.
        """
        if not isinstance(target, Target):
            if isinstance(target, list):
                target = dict(target)
            self._target = Target(self)
            self._target.from_dict(target)
        else:
            self._target = target

    @property
    def current_targets(self):
        """
            Returns current targets (getter)
        """
        return self.get_current_targets()

    def get_current_targets(self):
        """
            Parses airodump-ng's output file, creating a Target object
            for each AP found, with its currently detected clients.
        """
        aps = []
        clients = []

        scan_file = "{}/{}-01.csv".format(self.target_dir, self.config["name"])
        with open(scan_file) as f:
            dictcsv = [a for a in csv.DictReader(f, skipinitialspace=True)]

        if "reaver" in self.extra_capabilities:
            self.reaver_targets = self.extra_capabilities['reaver'].scan(
                scan_file)

        currently_processing_aps = True
        for element in dictcsv:
            element = element[None]
            if currently_processing_aps:
                if element[0] == "Station MAC":
                    currently_processing_aps = False
                    clients.append(element)
                else:
                    aps.append(element)
            else:
                clients.append(element)

        if len(aps) == 0:
            return False

        ap_headers = aps.pop(0)
        client_headers = [a.lstrip(" ") for a in clients.pop(0)]
        clients = [dict(zip(client_headers, client)) for client in clients]
        a = [Target(self).from_dict(dict(zip(ap_headers, ap)), clients) for ap in aps]
        return sorted(a, key=lambda x: x['hackability']['value'], reverse=True)

    def listMethods(self):
        """
            Hack to return public methods of this object via XMLRPC

            :TODO:
                - Make this work
        """
        return list_public_methods(self)

    def _methodHelp(self, method):
        """
            Hack to return public methods' help of this object via XMLRPC

            :TODO:
                - Make this work
        """

        f = getattr(self, method)
        return inspect.getdoc(f)