Exemplo n.º 1
0
    def __init__(self, exploit_apk_path, issues, apk_name, manifest_path, sdk_path):
        """
        Creates the APKBuilder.

        :param str exploit_apk_path: path to where the exploit apk should be built
        :param list issues: List of `Issue` found from the scanner
        :param str apk_name: name of the examined APK
        """
        self.exploit_apk_path = os.path.join(exploit_apk_path, "{apk_name}_exploit_apk".format(apk_name=apk_name))

        # need to remove directory if it exists otherwise shutil.copytree will error from helper
        if os.path.isdir(self.exploit_apk_path):
            shutil.rmtree(self.exploit_apk_path)

        # copy template exploit APK to exploit location
        try:
            copy_directory_to_location(directory_to_copy=EXPLOIT_APK_TEMPLATE_PATH, destination=self.exploit_apk_path)
        except Exception:
            log.exception("Failed to copy %s to %s", EXPLOIT_APK_TEMPLATE_PATH, self.exploit_apk_path)
            raise SystemExit("Failed to copy %s to %s", EXPLOIT_APK_TEMPLATE_PATH, self.exploit_apk_path)

        values_path = os.path.join(self.exploit_apk_path, "app", "src", "main", "res", "values")
        self.strings_xml_path = os.path.join(values_path, "strings.xml")
        self.extra_keys_xml_path = os.path.join(values_path, "extraKeys.xml")
        self.intent_ids_xml_path = os.path.join(values_path, "intentID.xml")

        self.properties_file_path = os.path.join(self.exploit_apk_path, "local.properties")
        self.sdk_path = sdk_path

        self.issues = issues
        try:
            self.package_name = get_package_from_manifest(manifest_path)
        except IOError:
            log.exception("Failed to read manifest file at %s", manifest_path)
            raise SystemExit("Failed to read manifest file at %s", manifest_path)
Exemplo n.º 2
0
    def update_manifest(cls, path_to_manifest):
        """Users of this class should call this method instead of changing class attributes directly"""
        cls.manifest_path = path_to_manifest
        try:
            cls.manifest_xml = minidom.parse(path_to_manifest)
        except Exception:
            # path_to_manifest is None or has bad XML
            cls.manifest_xml = None
            log.debug("Failed to update manifest for file %s", path_to_manifest)
            return

        try:
            cls.min_sdk = get_min_sdk(cls.manifest_path)
            cls.target_sdk = get_target_sdk(cls.manifest_path)
        except AttributeError:
            # manifest path is not set, assume min_sdk and target_sdk
            cls.min_sdk = cls.target_sdk = 1

        try:
            cls.package_name = get_package_from_manifest(cls.manifest_path)
        except IOError:
            cls.package_name = "PACKAGE_NOT_FOUND"