示例#1
0
    def loadClass(self, source, klass, relative_to=None):
        """
        Load a Class from a local apk file (source) on the running Dalvik VM.
        """

        if relative_to == None:
            relative_to = os.path.join(os.path.dirname(__file__), "..")
        elif relative_to.find(".py") >= 0 or relative_to.find(".pyc") >= 0:
            relative_to = os.path.dirname(relative_to)

        if not Module.cached_klass(".".join([source, klass])):
            loader = utils.ClassLoader(
                source,
                self.__get_cache_path(),
                self.__get_constructor(),
                self.klass('java.lang.ClassLoader').getSystemClassLoader(),
                relative_to=relative_to)
            loader.android_path = lambda: Configuration.library("android.jar")
            loader.dx_path = lambda: Configuration.executable(
                "dx.bat") if platform.system(
                ) == "Windows" else Configuration.executable("dx")
            """
              javac not found
              """
            loader.javac_path = lambda: Configuration.executable("javac")

            Module.cache_klass(".".join([source, klass]),
                               loader.loadClass(klass))

        return Module.get_cached_klass(".".join([source, klass]))
示例#2
0
    def make_jks_trust_store(self):
        """
        Prepare a JKS TrustStore, for the CA.
        """

        keytool = Configuration.executable('keytool')
        argv = [
            keytool, "-import", "-trustcacerts", "-noprompt", "-alias",
            "drozerCA", "-file",
            self.ca_certificate_path(), "-keystore",
            self.__jks_path('drozer-ca'), "-storetype", "JKS", "-storepass",
            "drozer"
        ]

        if keytool != None:
            if os.spawnve(os.P_WAIT, argv[0], argv, os.environ) == 0:
                return self.__bks_path('drozer-ca')
        else:
            argv[0] = "keytool"

            print "Could not compile the JKS trust store, because keytool could not be located on your system."
            print "Run:"
            print " ".join(argv)

            return False
示例#3
0
    def make_bks_key_store(self, cn, p12_path, export_password, store_password,
                           key_password):
        """
        Prepare a BouncyCastle KeyStore from a PKCS12 bundle.
        """

        keytool = Configuration.executable('keytool')
        argv = [
            keytool, "-importkeystore", "-deststorepass", store_password,
            "-destkeypass", key_password, "-destkeystore",
            self.__bks_path(cn), "-deststoretype", "BKS", "-provider",
            "org.bouncycastle.jce.provider.BouncyCastleProvider",
            "-providerpath",
            os.path.abspath(
                os.path.join(os.path.dirname(__file__),
                             "bcprov-ext-jdk15on-1.46.jar")), "-srckeystore",
            p12_path, "-srcstoretype", "PKCS12", "-srcstorepass",
            export_password, "-alias", "drozer"
        ]

        if keytool != None:
            if os.spawnve(os.P_WAIT, argv[0], argv, os.environ) == 0:
                return self.__bks_path(cn)
        else:
            argv[0] = "keytool"

            print "Could not compile the BKS keystore, because keytool could not be located on your system."
            print "Run:"
            print " ".join(argv)

            return False
示例#4
0
    def make_bks_trust_store(self):
        """
        Prepare a BouncyCastle TrustStore, for the CA.
        """

        keytool = Configuration.executable('keytool')
        argv = [
            keytool, "-import", "-trustcacerts", "-noprompt", "-alias",
            "drozerCA", "-file",
            self.ca_certificate_path(), "-keystore",
            self.__bks_path('drozer-ca'), "-storetype", "BKS", "-storepass",
            "drozer", "-provider",
            "org.bouncycastle.jce.provider.BouncyCastleProvider",
            "-providerpath",
            os.path.abspath(
                os.path.join(os.path.dirname(__file__),
                             "bcprov-ext-jdk15on-1.46.jar"))
        ]

        if keytool != None:
            if os.spawnve(os.P_WAIT, argv[0], argv, os.environ) == 0:
                return self.__bks_path('drozer-ca')
        else:
            argv[0] = "keytool"

            print "Could not compile the BKS trust store, because keytool could not be located on your system."
            print "Run:"
            print " ".join(argv)

            return False
示例#5
0
文件: provider.py 项目: 0xr0ot/drozer
 def make_jks_trust_store(self):
     """
     Prepare a JKS TrustStore, for the CA.
     """
     
     keytool = Configuration.executable('keytool')
     argv = [keytool,
             "-import",
             "-trustcacerts",
             "-noprompt",
             "-alias", "drozerCA",
             "-file",  self.ca_certificate_path(),
             "-keystore", self.__jks_path('drozer-ca'),
             "-storetype", "JKS",
             "-storepass", "drozer"]
     
     if keytool != None:
         if os.spawnve(os.P_WAIT, argv[0], argv, os.environ) == 0:
             return self.__bks_path('drozer-ca')
     else:
         argv[0] = "keytool"
         
         print "Could not compile the JKS trust store, because keytool could not be located on your system."
         print "Run:"
         print " ".join(argv) 
         
         return False
示例#6
0
文件: provider.py 项目: 0xr0ot/drozer
 def make_bks_trust_store(self):
     """
     Prepare a BouncyCastle TrustStore, for the CA.
     """
     
     keytool = Configuration.executable('keytool')
     argv = [keytool,
             "-import",
             "-trustcacerts",
             "-noprompt",
             "-alias", "drozerCA",
             "-file",  self.ca_certificate_path(),
             "-keystore", self.__bks_path('drozer-ca'),
             "-storetype", "BKS",
             "-storepass", "drozer",
             "-provider", "org.bouncycastle.jce.provider.BouncyCastleProvider",
             "-providerpath", os.path.abspath(os.path.join(os.path.dirname(__file__), "bcprov-ext-jdk15on-1.46.jar"))]
     
     if keytool != None:
         if os.spawnve(os.P_WAIT, argv[0], argv, os.environ) == 0:
             return self.__bks_path('drozer-ca')
     else:
         argv[0] = "keytool"
         
         print "Could not compile the BKS trust store, because keytool could not be located on your system."
         print "Run:"
         print " ".join(argv) 
         
         return False
示例#7
0
文件: provider.py 项目: 0xr0ot/drozer
 def make_bks_key_store(self, cn, p12_path, export_password, store_password, key_password):
     """
     Prepare a BouncyCastle KeyStore from a PKCS12 bundle.
     """
     
     keytool = Configuration.executable('keytool') 
     argv = [keytool,
             "-importkeystore",
             "-deststorepass", store_password,
             "-destkeypass", key_password,
             "-destkeystore", self.__bks_path(cn),
             "-deststoretype", "BKS", 
             "-provider", "org.bouncycastle.jce.provider.BouncyCastleProvider",
             "-providerpath", os.path.abspath(os.path.join(os.path.dirname(__file__), "bcprov-ext-jdk15on-1.46.jar")),
             "-srckeystore", p12_path,
             "-srcstoretype", "PKCS12",
             "-srcstorepass", export_password,
             "-alias", "drozer"]
     
     if keytool != None:
         if os.spawnve(os.P_WAIT, argv[0], argv, os.environ) == 0:
             return self.__bks_path(cn)
     else:
         argv[0] = "keytool"
         
         print "Could not compile the BKS keystore, because keytool could not be located on your system."
         print "Run:"
         print " ".join(argv) 
         
         return False
示例#8
0
 def loadClass(self, source, klass, relative_to=None):
     """
     Load a Class from a local apk file (source) on the running Dalvik VM.
     """
     
     if relative_to == None:
         relative_to = os.path.join(os.path.dirname(__file__), "..")
     elif relative_to.find(".py") >= 0 or relative_to.find(".pyc") >= 0:
         relative_to = os.path.dirname(relative_to)
     
     if not Module.cached_klass(".".join([source, klass])):
         loader = utils.ClassLoader(source, self.__get_cache_path(), self.__get_constructor(), self.klass('java.lang.ClassLoader').getSystemClassLoader(), relative_to=relative_to)
         loader.android_path = Configuration.library("android.jar")
         loader.dx_path = Configuration.executable("dx")
         loader.javac_path = Configuration.executable("javac")
         
         Module.cache_klass(".".join([source, klass]), loader.loadClass(klass))
         
     return Module.get_cached_klass(".".join([source, klass]))
示例#9
0
class Packager(command_wrapper.Wrapper):
    
    __aapt = Configuration.library("aapt")
    __aapt_osx = Configuration.library("aapt-osx")
    __aapt_exe = Configuration.library("aapt.exe")
    __apk_tool = Configuration.library("apktool.jar")
    __certificate = Configuration.library("certificate.pem")
    __key = Configuration.library("key.pk8")
    __java = Configuration.executable("java")
    ff = Configuration.path()
    __sign_apk = Configuration.library("signapk.jar")
    
    __endpoint = "endpoint.txt"
    __manifest = "AndroidManifest.xml"
    
    def __init__(self):
        self.__wd = self._get_wd()
        
    def apk_path(self, signed=True):
        if signed:
            return os.path.join(self.__wd, "agent.apk")
        else:
            return os.path.join(self.__wd, "agent-unsigned.apk")
    
    def endpoint_path(self):
        return os.path.join(self.__wd, "agent", "res", "raw", self.__endpoint)
    
    def manifest_path(self):
        return os.path.join(self.__wd, "agent", self.__manifest)
    
    def package(self):
        platform_name = platform.system()

        if platform_name == "Darwin":
            aapt = self.__aapt_osx
        elif platform_name == "Windows":
            aapt = self.__aapt_exe
        else:
            aapt = self.__aapt
        
        if self._execute([self.__java, "-jar", self.__apk_tool, "-q", "build", "-a", aapt, self.source_dir(), self.apk_path(False)]) != 0:
            raise RuntimeError("could not repack the agent sources")
        if self._execute([self.__java, "-jar", self.__sign_apk, self.__certificate, self.__key, self.apk_path(False), self.apk_path(True)]) != 0:
            raise RuntimeError("could not sign the agent package")
        
        return os.path.join(self.__wd, "agent.apk")
    
    def source_dir(self):
        return os.path.join(self.__wd, "agent")
    
    def unpack(self, name):
        if self._execute([self.__java, "-jar", self.__apk_tool, "-q", "decode", Configuration.library(name + ".apk"), self.source_dir()]) != 0:
            raise RuntimeError("could not unpack " + name)