Beispiel #1
0
    def connected(self):
        """
        Checks if the device is connected

        :return: True if the device is connected and False if not
        """
        from scrounger.utils.android import devices
        return self._device_id in devices()
Beispiel #2
0
    def __init__(self, device_id):
        """
        Creates an object that will be a wrapper to interact with the android
        device. It also checks if the device trusts the host.
        """
        from scrounger.utils.android import devices
        from scrounger.utils.general import UnauthorizedDevice

        self._device_id = device_id

        devices_list = devices()
        if self._device_id not in devices_list or\
            devices_list[self._device_id] == "unauthorized":
            raise UnauthorizedDevice(
                "The device {} does not trust this host.".format(
                    self._device_id))
    def run(self):
        result = {
            "title": "Application Does Not Detect Emulators",
            "details": "",
            "severity": "Medium",
            "report": True
        }

        # preparing variable to run
        emulator_detection = {}
        ignore = [filepath.strip() for filepath in self.ignore.split(";")]

        Log.info("Identifying smali directories")
        dirs = smali_dirs(self.decompiled_apk)

        Log.info("Analysing smali code for emulator detection mechanisms")
        for directory in dirs:
            smali = "{}/{}".format(self.decompiled_apk, directory)
            emulator_detection.update(pretty_grep(self.regex, smali))

        if emulator_detection:
            result = {
                "title":
                "Application Detects Emulators",
                "details":
                "{}\n\n{}".format(
                    result["details"],
                    pretty_grep_to_str(emulator_detection, self.decompiled_apk,
                                       ignore)),
                "severity":
                "Medium",
                "report":
                True
            }

        # dynamic testing
        Log.info("Checking requirements for dynamic testing")

        if hasattr(self, "apk") and hasattr(self, "avd") and \
        hasattr(self, "identifier") and self.identifier and \
        self.apk and self.avd:
            # get available devices before starting the emulator
            available_devices = devices()

            # start emulator
            Log.info("Starting the emulator")
            emulator_process = process("emulator -avd {}".format(self.avd))

            # wait for emulator to start
            sleep(60)

            # diff devices -> get emulator
            emulator_id = list(set(devices()) - set(available_devices))

            if len(emulator_id) != 1:
                Log.warn("Could not find the emulator in the device list")
                emulator_process.kill()
                return {
                    "{}_result".format(self.name()): result,
                    "print": "Coud not start emulator or find defined avd"
                }

            device = AndroidDevice(emulator_id)

            Log.info("Installing the apk in the device")
            device.install(self.apk)
            if device.installed(self.identifier):

                while not device.unlocked():
                    Log.info("Please unlock the emulator")
                    sleep(5)

                Log.info("Starting the application")
                device.start(identifier)
                sleep(15)

                if self.identifier not in device.processes():
                    result.update({"report": False})

            emulator_process.kill()

        return {"{}_result".format(self.name()): result}