def testSessionLoad(self):
        s = session.Session()
        with open("examples/android/TestsAndroguard/bin/TestActivity.apk",
                  "rb") as fd:
            s.add("examples/android/TestsAndroguard/bin/TestActivity.apk",
                  fd.read())
            session.Save(s, "test_session")

        self.assertIn(
            '2f24538b3064f1f88d3eb29ee7fbd2146779a4c9144aefa766d18965be8775c7',
            s.analyzed_dex.keys())
        self.assertIn(
            '3bb32dd50129690bce850124ea120aa334e708eaa7987cf2329fd1ea0467a0eb',
            s.analyzed_apk.keys())
        x = s.analyzed_apk[
            '3bb32dd50129690bce850124ea120aa334e708eaa7987cf2329fd1ea0467a0eb'][
                0]
        self.assertIsInstance(x, APK)

        nsession = session.Load("test_session")
        self.assertIn(
            '2f24538b3064f1f88d3eb29ee7fbd2146779a4c9144aefa766d18965be8775c7',
            nsession.analyzed_dex.keys())
        self.assertIn(
            '3bb32dd50129690bce850124ea120aa334e708eaa7987cf2329fd1ea0467a0eb',
            nsession.analyzed_apk.keys())
        y = nsession.analyzed_apk[
            '3bb32dd50129690bce850124ea120aa334e708eaa7987cf2329fd1ea0467a0eb'][
                0]
        self.assertIsInstance(y, APK)
예제 #2
0
 def loadAPK(self, flag):
     sess = misc.get_default_session()
     if flag == True:
         sess = session.Load("androguard_session.ag")
         a, d, dx = misc.AnalyzeAPK(self.apk_path, session=sess)
         self.a = a
         self.d = d
         self.dx = dx
         return
     a, d, dx = misc.AnalyzeAPK(self.apk_path, session=sess)
     self.a = a
     self.d = d
     self.dx = dx
예제 #3
0
    def run(self):
        if self.incoming_file:
            try:
                file_path, file_type = self.incoming_file
                if file_type in ["APK", "DEX", "DEY"]:
                    # session.add returns sha256 or None
                    ret = self.parent.session.add(file_path, open(file_path, 'rb').read())
                    self.file_loaded.emit(ret != None)
                elif file_type == "SESSION":
                    self.parent.session = session.Load(file_path)
                    self.file_loaded.emit(True)
                else:
                    self.file_loaded.emit(False)
            except Exception as e:
                log.exception("Error loading the file into the Session!")
                self.file_loaded.emit(False)

            self.incoming_file = ()
        else:
            self.file_loaded.emit(False)
예제 #4
0
    def run(self):
        if self.incoming_file:
            try:
                file_path, file_type = self.incoming_file
                if file_type in ["APK", "DEX", "DEY"]:
                    ret = self.parent.session.add(file_path,
                                                  open(file_path, 'rb').read())
                    self.file_loaded.emit(ret)
                elif file_type == "SESSION":
                    self.parent.session = session.Load(file_path)
                    self.file_loaded.emit(True)
                else:
                    self.file_loaded.emit(False)
            except Exception as e:
                androconf.debug(e)
                androconf.debug(traceback.format_exc())
                self.file_loaded.emit(False)

            self.incoming_file = []
        else:
            self.file_loaded.emit(False)
예제 #5
0
def r2ProjectName(projectName, sessionName, fileName, sess): 
    project = Path(os.environ['HOME'] + "/.local/share/radare2/projects/" + projectName)
    sessionFile = str(project) +"/" + sessionName
    sessionFile = Path(sessionFile)

    if project.is_dir():
        print("Project exists! -- " + str(project) + "\n")
        if sessionFile.is_file():
            print("Loading session file at " + str(sessionFile) + ", please wait... \n")
            sess = session.Load(str(sessionFile))
            return sess
        else:
                print("No session file found, creating one! Please wait...")
                apk, d, dx = misc.AnalyzeAPK(fileName.decode('utf-8'), session=sess)
                session.Save(sess, str(sessionFile))
                print("Session file created at : " + str(sessionFile) + "\n")

                return sess        
    else:
        print("Radare2 Project does not exist, please save a Radare2 project first")
        exit()
예제 #6
0
parser = argparse.ArgumentParser('find string in a apk')
parser.add_argument('apk')
parser.add_argument('--only-login',
                    help='display only logins',
                    action='store_true')
parser.add_argument('--show-file',
                    help='Add filename before url',
                    action='store_true')
parser.add_argument('--session', help='session file')
args = parser.parse_args()

sess = misc.get_default_session()

if args.session and os.path.exists(args.session):
    print('load session from {} ...'.format(args.session), file=sys.stderr)
    sess = session.Load(args.session)

a: APK
d: DalvikVMFormat
dx: Analysis

print('[*] Analyse {} ...'.format(args.apk), file=sys.stderr)
a, d, dx = AnalyzeAPK(args.apk, session=sess)

find_http = []

login_hints = ['login', 'auth', 'token', 'cred', 'session']

exclude_domains = ['googleapis.com', 'crashlytics.com']

예제 #7
0
def main(projectName, className, methodName):

    if methodName and (not className):
        print('Must provide class name "-c" in order to decompile specific method "-m"')
        exit()

    #Increase recursion limit to save session file
    sys.setrecursionlimit(100000)
    r2 = r2pipe.open()

    fileName = r2.cmd("i~file[1]")
    fileName = fileName.split("/")[2]
    if fileName.split("."):
        sessionName = fileName.split(".")[0]
        sessionName = sessionName+".session"
        sessionFile = Path(sessionName)

    currentClassMethod = r2.cmd("afi.")

    if "_" in currentClassMethod:
        currentClassMethod = str(currentClassMethod).replace("_", "/")

    currentClass = str(currentClassMethod).split(".")[1]
    print("Current class: " + currentClass)

    currentMethod = str(currentClassMethod).split(".")[3]

    apkMethod = currentMethod.split("/")[0]

    if apkMethod == "method":

        currentMethod = str(currentClassMethod).split(".")[4]
        apkMethod = currentMethod.split("(")[0]

    print("    Current Method: " +  apkMethod + "\n")

    sess = misc.get_default_session()

    #Check if project name is passed
    if projectName != None:
        projectSession = r2ProjectName(projectName, sessionName, fileName, sess)

        if className and methodName:
            decompileMethod(className, methodName, projectSession)
            exit()
        if className:
            decompileClass(className, projectSession)
            exit() 

        dalv = next(projectSession.get_objects_dex())[1]
        dx = next(projectSession.get_objects_dex())[2]
        print("Decompiling method " + apkMethod + " in the class" + currentClass)

        dad = decompiler.DecompilerDAD(dalv, dx)

        classNames = dalv.get_classes_names()
        autoDecompile(dalv, dx, dad, classNames, currentClass, apkMethod)
        exit()

    # Check if session file exists    
    if sessionFile.is_file(): 
            
        print("Loading session file, please wait... \n")
        sess = session.Load(sessionName)

        if className and methodName:
            decompileMethod(className, methodName, sess)
            exit()
        if className:
            decompileClass(className, sess)
            exit() 
        

        dalv = next(sess.get_objects_dex())[1]
        dx = next(sess.get_objects_dex())[2]
        dad = decompiler.DecompilerDAD(dalv, dx)

        classNames = dalv.get_classes_names()
        autoDecompile(dalv,dx,dad,classNames, currentClass, apkMethod)

    # Create sesssion file
    else:
        print("No session file found, creating one! Please wait...")
        fileName = fileName.replace("\\n\\x00","")
        fileName = fileName.split("\'")[0]
        apk, d, dx = misc.AnalyzeAPK(fileName, session=sess)
        session.Save(sess, sessionName)

        print("Session file created: " + sessionName)
        print("    Will load session file for future calls... \n")

        if className and methodName:
            decompileMethod(className, methodName, sess)
            exit()

        if className:
            decompileClass(className, sess)
            exit() 

        dalv = next(sess.get_objects_dex())[1]
        dx = next(sess.get_objects_dex())[2]
        dad = decompiler.DecompilerDAD(dalv, dx)

        classNames = dalv.get_classes_names()
        autoDecompile(dalv,dx,dad,classNames,currentClass, apkMethod)