Example #1
0
    def inspired_run(self, series, apk, examined, trigger_java_dir):
        self.trigger_java_dir = trigger_java_dir
        # apk = 'F:\\Apps\\COMMUNICATION\\com.mobanyware.apk'
        self.logger.info('base name: ' + os.path.basename(apk))
        apk_name, apk_extension = os.path.splitext(apk)

        self.logger.info(apk_name)
        if '_modified' not in apk_name:
            return
            # apk_modified = apk_name + '_modified.apk'
        else:
            apk_modified = apk
            apk_name = apk_name.replace('_modified', '')

        apk_name = os.path.basename(apk_name)

        if apk_name in examined:
            self.logger.error('Already examined ' + apk_name)
            return

        cmd = 'adb devices'
        os.system(cmd)
        self.logger.info(apk_modified)

        # current_time = time.strftime(ISOTIMEFORMAT, time.localtime())
        par_dir = os.path.basename(
            os.path.abspath(os.path.join(
                apk, os.pardir)))  # the parent folder of the apk

        package = self.get_package_name(self.aapt_loc, apk_modified)

        if not package:
            self.logger.error('Not a valid pkg.')
            return

        csvpath = self.get_csv_path(self.trigger_java_dir, par_dir, apk_name)
        if not os.path.isfile(csvpath):
            self.logger.error('tgt_Act.csv does not exist:' + csvpath)
            return

        output_dir = self.out_base_dir + par_dir + '/' + apk_name + '/'
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        filehandler = Utilities.set_file_log(
            self.logger, output_dir + 'COSMOS_TRIGGER_PY.log')
        self.logger.info('apk:' + apk_modified)
        self.logger.info('pkg:' + package)
        self.logger.info('csv: ' + csvpath)

        UIExerciser.uninstall_pkg(series, package)
        UIExerciser.install_apk(series, apk_modified)

        current_time = time.strftime(ISOTIMEFORMAT, time.localtime())
        UIExerciser.run_adb_cmd(
            'shell monkey -p com.lexa.fakegps --ignore-crashes 1')
        d = Device()
        d(text='Set location').click()

        UIExerciser.run_adb_cmd('logcat -c')
        self.logger.info(
            'clear logcat')  # self.screenshot(output_dir, activity)

        # UIExerciser.run_adb_cmd('shell "nohup /data/local/tcpdump -w /sdcard/' + package + current_time  + '.pcap &"')
        # UIExerciser.run_adb_cmd('shell "nohup logcat -v threadtime -s "UiDroid_Taint" > /sdcard/' + package + current_time +'.log &"')

        # cmd = 'adb -s ' + series + ' shell "nohup /data/local/tcpdump -w /sdcard/' + package + current_time + '.pcap &"'
        self.logger.info('tcpdump begins')
        cmd = 'adb -s ' + series + ' shell /data/local/tcpdump -w /sdcard/' + package + '_' + current_time + '.pcap'
        # os.system(cmd)
        print cmd
        process = Popen(cmd, stdout=PIPE, stderr=STDOUT, shell=True)

        UIExerciser.run_adb_cmd('shell monkey -p ' + package +
                                ' --ignore-crashes 1')
        for i in range(1, 3):
            if not UIExerciser.check_dev_online(UIExerciser.series):
                if UIExerciser.emu_proc:
                    UIExerciser.close_emulator(UIExerciser.emu_proc)
                    UIExerciser.emu_proc = UIExerciser.open_emu(
                        UIExerciser.emu_loc, UIExerciser.emu_name)
                else:
                    raise Exception('Cannot start the default Activity')
            if Utilities.run_method(self.screenshot,
                                    180,
                                    args=[output_dir, '', True, package]):
                break
            else:
                self.logger.warn(
                    "Time out while dumping XML for the default activity")

        # UIExerciser.adb_kill('logcat')
        # Utilities.adb_kill('tcpdump')
        # UIExerciser.run_adb_cmd('shell am force-stop fu.hao.uidroid')
        # os.system("TASKKILL /F /PID {pid} /T".format(pid=process.pid))
        time.sleep(10)
        process.kill()  # takes more time
        out_pcap = output_dir + package + '_' + current_time + '.pcap'
        try:
            while not os.path.exists(
                    out_pcap) or os.stat(out_pcap).st_size < 2:
                time.sleep(5)
                cmd = 'pull /sdcard/' + package + '_' + current_time + '.pcap ' + out_pcap
                UIExerciser.run_adb_cmd(cmd)
                process.kill()  # takes more time
        except:
            Utilities.logger.info('wait..')
            # if not os.path.exists(out_pcap):
            # raise Exception('The pcap does not exist.')
        # UIExerciser.run_adb_cmd('shell rm /sdcard/' + package + current_time + '.pcap')

        # UIExerciser.run_adb_cmd('pull /sdcard/' + package + current_time + '.log ' + output_dir)
        # UIExerciser.run_adb_cmd('shell rm /sdcard/' + package + current_time + '.log')
        taint_logs = []
        print 'f**k'
        Utilities.run_method(TaintDroidLogHandler.collect_taint_log,
                             15,
                             args=[taint_logs])
        with open(output_dir + package + '_' + current_time + '.json',
                  'w') as outfile:
            json.dump(taint_logs, outfile)

        self.start_activities(package, csvpath, output_dir)

        self.uninstall_pkg(series, package)

        filehandler.close()
        self.logger.removeHandler(filehandler)
        Utilities.kill_by_name('adb.exe')
Example #2
0
    def inspired_run_lite(self, series, apk, examined, trigger_java_dir):
        self.trigger_java_dir = trigger_java_dir
        # apk = 'F:\\Apps\\COMMUNICATION\\com.mobanyware.apk'
        self.logger.info('base name: ' + os.path.basename(apk))
        apk_name, apk_extension = os.path.splitext(apk)

        self.logger.info(apk_name)
        if '_modified' not in apk_name:
            return
            # apk_modified = apk_name + '_modified.apk'
        else:
            apk_modified = apk
            apk_name = apk_name.replace('_modified', '')

        apk_name = os.path.basename(apk_name)

        if apk_name in examined:
            self.logger.error('Already examined ' + apk_name)
            return

        cmd = 'adb devices'
        os.system(cmd)
        self.logger.info(apk_modified)

        # current_time = time.strftime(ISOTIMEFORMAT, time.localtime())
        par_dir = os.path.basename(
            os.path.abspath(os.path.join(
                apk, os.pardir)))  # the parent folder of the apk

        package = self.get_package_name(self.aapt_loc, apk_modified)

        if not package:
            self.logger.error('Not a valid pkg.')
            return

        csvpath = self.get_csv_path(self.trigger_java_dir, par_dir, apk_name)
        if not os.path.isfile(csvpath):
            self.logger.error('tgt_Act.csv does not exist:' + csvpath)
            return

        output_dir = self.out_base_dir + par_dir + '/' + apk_name + '/'
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        filehandler = Utilities.set_file_log(
            self.logger, output_dir + 'COSMOS_TRIGGER_PY.log')
        self.logger.info('apk:' + apk_modified)
        self.logger.info('pkg:' + package)
        self.logger.info('csv: ' + csvpath)

        UIExerciser.uninstall_pkg(series, package)
        UIExerciser.install_apk(series, apk_modified)

        #current_time = time.strftime(ISOTIMEFORMAT, time.localtime())

        UIExerciser.run_adb_cmd('shell monkey -p ' + package +
                                ' --ignore-crashes 1')
        for i in range(1, 3):
            if not UIExerciser.check_dev_online(UIExerciser.series):
                if UIExerciser.emu_proc:
                    UIExerciser.close_emulator(UIExerciser.emu_proc)
                    UIExerciser.emu_proc = UIExerciser.open_emu(
                        UIExerciser.emu_loc, UIExerciser.emu_name)
                else:
                    raise Exception('Cannot start the default Activity')
            if Utilities.run_method(self.screenshot,
                                    180,
                                    args=[output_dir, '', True, package]):
                break
            else:
                self.logger.warn(
                    "Time out while dumping XML for the default activity")

        # UIExerciser.adb_kill('logcat')
        # Utilities.adb_kill('tcpdump')
        # UIExerciser.run_adb_cmd('shell am force-stop fu.hao.uidroid')
        # os.system("TASKKILL /F /PID {pid} /T".format(pid=process.pid))
        # if not os.path.exists(out_pcap):
        # raise Exception('The pcap does not exist.')
        # UIExerciser.run_adb_cmd('shell rm /sdcard/' + package + current_time + '.pcap')

        # UIExerciser.run_adb_cmd('pull /sdcard/' + package + current_time + '.log ' + output_dir)
        # UIExerciser.run_adb_cmd('shell rm /sdcard/' + package + current_time + '.log')

        self.start_activities(package, csvpath, output_dir, lite=True)

        self.uninstall_pkg(series, package)

        filehandler.close()
        self.logger.removeHandler(filehandler)
        Utilities.kill_by_name('adb.exe')
Example #3
0
    def flowintent_first_page(self, series, apk, examined):
        current_time = time.strftime(ISOTIMEFORMAT, time.localtime())
        self.logger.info('base name: ' + os.path.basename(apk))
        apk_name, apk_extension = os.path.splitext(apk)

        self.logger.info(apk_name)

        apk_name = os.path.basename(apk_name)

        if apk_name in examined:
            self.logger.error('Already examined ' + apk_name)
            return

        cmd = 'adb devices'
        os.system(cmd)
        self.logger.info(apk)

        # current_time = time.strftime(ISOTIMEFORMAT, time.localtime())
        par_dir = os.path.basename(
            os.path.abspath(os.path.join(
                apk, os.pardir)))  # the parent folder of the apk

        package = self.get_package_name(self.aapt_loc, apk)

        if not package:
            self.logger.error('Not a valid pkg.')
            return

        #self.start_taintdroid(series)

        output_dir = self.out_base_dir + par_dir + '/' + apk_name + '/'
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        filehandler = Utilities.set_file_log(
            self.logger, output_dir + 'UIExerciser_FlowIntent_FP_PY.log')
        self.logger.info('apk:' + apk)
        self.logger.info('pkg:' + package)

        UIExerciser.uninstall_pkg(series, package)
        UIExerciser.install_apk(series, apk)

        #self.run_adb_cmd('shell am start -n fu.hao.uidroid/.TaintDroidNotifyController')
        self.run_adb_cmd('shell "su 0 date -s `date +%Y%m%d.%H%M%S`"')
        UIExerciser.run_adb_cmd(
            'shell monkey -p com.lexa.fakegps --ignore-crashes 1')
        d = Device()
        d(text='Set location').click()

        UIExerciser.run_adb_cmd('logcat -c')
        self.logger.info(
            'clear logcat')  # self.screenshot(output_dir, activity)

        #UIExerciser.run_adb_cmd('shell "nohup /data/local/tcpdump -w /sdcard/' + package + current_time  + '.pcap &"')
        #UIExerciser.run_adb_cmd('shell "nohup logcat -v threadtime -s "UiDroid_Taint" > /sdcard/' + package + current_time +'.log &"')

        #cmd = 'adb -s ' + series + ' shell "nohup /data/local/tcpdump -w /sdcard/' + package + current_time + '.pcap &"'
        self.logger.info('tcpdump begins')
        cmd = 'adb -s ' + series + ' shell /data/local/tcpdump -w /sdcard/' + package + '_' + current_time + '.pcap'
        # os.system(cmd)
        print cmd
        process = Popen(cmd, stdout=PIPE, stderr=STDOUT, shell=True)

        UIExerciser.run_adb_cmd('shell monkey -p ' + package + '_' +
                                ' --ignore-crashes 1')
        for i in range(1, 3):
            if not UIExerciser.check_dev_online(UIExerciser.series):
                if UIExerciser.emu_proc:
                    UIExerciser.close_emulator(UIExerciser.emu_proc)
                    UIExerciser.emu_proc = UIExerciser.open_emu(
                        UIExerciser.emu_loc, UIExerciser.emu_name)
                else:
                    raise Exception('Cannot start the default Activity')
            if Utilities.run_method(self.screenshot,
                                    180,
                                    args=[output_dir, '', True, package]):
                break
            else:
                self.logger.warn(
                    "Time out while dumping XML for the default activity")

        #UIExerciser.adb_kill('logcat')
        #Utilities.adb_kill('tcpdump')
        #UIExerciser.run_adb_cmd('shell am force-stop fu.hao.uidroid')
        #os.system("TASKKILL /F /PID {pid} /T".format(pid=process.pid))
        time.sleep(60)
        process.kill()  # takes more time
        out_pcap = output_dir + package + current_time + '.pcap'
        while not os.path.exists(out_pcap) or os.stat(out_pcap).st_size < 2:
            time.sleep(5)
            cmd = 'pull /sdcard/' + package + '_' + current_time + '.pcap ' + out_pcap
            UIExerciser.run_adb_cmd(cmd)
            #if not os.path.exists(out_pcap):
            #raise Exception('The pcap does not exist.')
            UIExerciser.run_adb_cmd('shell rm /sdcard/' + package +
                                    current_time + '.pcap')

        #UIExerciser.run_adb_cmd('pull /sdcard/' + package + current_time + '.log ' + output_dir)
        #UIExerciser.run_adb_cmd('shell rm /sdcard/' + package + current_time + '.log')
        taint_logs = []
        Utilities.run_method(TaintDroidLogHandler.collect_taint_log,
                             15,
                             args=[taint_logs])
        with open(output_dir + package + '_' + current_time + '.json',
                  'w') as outfile:
            json.dump(taint_logs, outfile)

        self.uninstall_pkg(series, package)
        self.logger.info('End')

        filehandler.close()
        self.logger.removeHandler(filehandler)
        Utilities.kill_by_name('adb.exe')