def stop_collection(self): res = main_utils.run_shell_cmd("ps").split('\n') for item in res: if item.find('diag_revealer') != -1: pid = item.split()[1] cmd = "kill "+pid main_utils.run_shell_cmd(cmd)
def __init_libs(self): """ Initialize libs required by MobileInsight. It creates sym links to libs, and chmod of critical execs """ libs_path = os.path.join(main_utils.get_files_dir(), "data") cmd = "" libs_mapping = { "libwireshark.so": [ "libwireshark.so.6", "libwireshark.so.6.0.1"], "libwiretap.so": [ "libwiretap.so.5", "libwiretap.so.5.0.1"], "libwsutil.so": [ "libwsutil.so.6", "libwsutil.so.6.0.0"]} for lib in libs_mapping: for sym_lib in libs_mapping[lib]: # if not os.path.isfile(os.path.join(libs_path,sym_lib)): if True: # TODO: chown to restore ownership for the symlinks cmd = cmd + " ln -s " + \ os.path.join(libs_path, lib) + " " + os.path.join(libs_path, sym_lib) + "; " exes = ["diag_revealer", "diag_revealer_mtk", "android_pie_ws_dissector", "android_ws_dissector"] for exe in exes: cmd = cmd + " chmod 755 " + os.path.join(libs_path, exe) + "; " cmd = cmd + "chmod -R 755 " + libs_path main_utils.run_shell_cmd(cmd)
def __check_security_policy(self): """ Update SELinux policy. For Nexus 6/6P, the SELinux policy may forbids the log collection. """ cmd = "setenforce 0; " cmd = cmd + "supolicy --live \"allow init logd dir getattr\";" # # Depreciated supolicies. Still keep them for backup purpose cmd = cmd + "supolicy --live \"allow init init process execmem\";" cmd = cmd + \ "supolicy --live \"allow atfwd diag_device chr_file {read write open ioctl}\";" cmd = cmd + "supolicy --live \"allow init properties_device file execute\";" cmd = cmd + \ "supolicy --live \"allow system_server diag_device chr_file {read write}\";" # # Suspicious supolicies: MI works without them, but it seems that they SHOULD be enabled... # # mi2log permission denied (logcat | grep denied), but no impact on log collection/analysis cmd = cmd + \ "supolicy --live \"allow untrusted_app app_data_file file {rename}\";" # # Suspicious: why still works after disabling this command? Won't FIFO fail? cmd = cmd + \ "supolicy --live \"allow init app_data_file fifo_file {write open getattr}\";" cmd = cmd + \ "supolicy --live \"allow init diag_device chr_file {getattr write ioctl}\"; " # Nexus 6 only cmd = cmd + \ "supolicy --live \"allow untrusted_app diag_device chr_file {write open getattr}\";" cmd = cmd + \ "supolicy --live \"allow system_server diag_device chr_file {read write}\";" cmd = cmd + \ "supolicy --live \"allow netmgrd diag_device chr_file {read write}\";" cmd = cmd + \ "supolicy --live \"allow rild diag_device chr_file {read write}\";" cmd = cmd + \ "supolicy --live \"allow rild debuggerd app_data_file {read open getattr}\";" cmd = cmd + \ "supolicy --live \"allow wcnss_service mnt_user_file dir {search}\";" cmd = cmd + \ "supolicy --live \"allow wcnss_service fuse dir {read open search}\";" cmd = cmd + \ "supolicy --live \"allow wcnss_service mnt_user_file lnk_file {read}\";" cmd = cmd + \ "supolicy --live \"allow wcnss_service fuse file {read append getattr}\";" main_utils.run_shell_cmd(cmd)
def _save_log(self): orig_basename = os.path.basename(self.__original_filename) orig_dirname = os.path.dirname(self.__original_filename) self.__log_timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S') milog_basename = "diag_log_%s_%s_%s.mi2log" % ( self.__log_timestamp, self.__phone_info, main_utils.get_operator_info()) milog_absname = os.path.join(self.__logdir, milog_basename) main_utils.run_shell_cmd("cp %s %s" % (self.__original_filename, milog_absname)) # shutil.copyfile(self.__original_filename, milog_absname) # chmodcmd = "rm -f " + self.__original_filename # p = subprocess.Popen("su ", executable = main_utils.ANDROID_SHELL, shell = True, \ # stdin = subprocess.PIPE, stdout = subprocess.PIPE) # p.communicate(chmodcmd + '\n') # p.wait() os.remove(self.__original_filename)
def _on_answer(self, instance, answer): if answer == "yes": phone_info = main_utils.get_phone_info() log_name = "crash_report_" \ + phone_info + '_' \ + datetime.datetime.now().strftime('%Y%m%d_%H%M%S') \ + '.txt' log_name = os.path.join( main_utils.get_mobileinsight_crash_log_path(), log_name) main_utils.run_shell_cmd( 'logcat -d | grep -E "python|diag" >' + log_name, True) self.__upload_crash_log(log_name) self.popup.dismiss() sys.exit(1)
def __check_diag_mode(self): """ Check if diagnostic mode is enabled. Note that this function is chipset-specific: Qualcomm and MTK have different detection approaches """ chipset_type = main_utils.get_chipset_type() if chipset_type == main_utils.ChipsetType.QUALCOMM: diag_port = "/dev/diag" if not os.path.exists(diag_port): return False else: main_utils.run_shell_cmd("chmod 777 /dev/diag") return True elif chipset_type == main_utils.ChipsetType.MTK: cmd = "ps | grep emdlogger1" res = main_utils.run_shell_cmd(cmd) if not res: return False else: return True
def create_folder(): cmd = "" mobileinsight_path = main_utils.get_mobileinsight_path() if not mobileinsight_path: return False try: legacy_mobileinsight_path = main_utils.get_legacy_mobileinsight_path() cmd = cmd + "mv " + legacy_mobileinsight_path + " " + mobileinsight_path + "; " cmd = cmd + "mv " + legacy_mobileinsight_path + "/apps/ " + mobileinsight_path + "/plugins/; " except: pass if not os.path.exists(mobileinsight_path): cmd = cmd + "mkdir " + mobileinsight_path + "; " cmd = cmd + "chmod -R 755 " + mobileinsight_path + "; " log_path = main_utils.get_mobileinsight_log_path() if not os.path.exists(log_path): cmd = cmd + "mkdir " + log_path + "; " cmd = cmd + "chmod -R 755 " + log_path + "; " analysis_path = main_utils.get_mobileinsight_analysis_path() if not os.path.exists(analysis_path): cmd = cmd + "mkdir " + analysis_path + "; " cmd = cmd + "chmod -R 755 " + analysis_path + "; " cfg_path = main_utils.get_mobileinsight_cfg_path() if not os.path.exists(analysis_path): cmd = cmd + "mkdir " + cfg_path + "; " cmd = cmd + "chmod -R 755 " + cfg_path + "; " db_path = main_utils.get_mobileinsight_db_path() if not os.path.exists(db_path): cmd = cmd + "mkdir " + db_path + "; " cmd = cmd + "chmod -R 755 " + db_path + "; " plugin_path = main_utils.get_mobileinsight_plugin_path() if not os.path.exists(plugin_path): cmd = cmd + "mkdir " + plugin_path + "; " cmd = cmd + "chmod -R 755 " + plugin_path + "; " log_decoded_path = main_utils.get_mobileinsight_log_decoded_path() if not os.path.exists(log_decoded_path): cmd = cmd + "mkdir " + log_decoded_path + "; " cmd = cmd + "chmod -R 755 " + log_decoded_path + "; " log_uploaded_path = main_utils.get_mobileinsight_log_uploaded_path() if not os.path.exists(log_uploaded_path): cmd = cmd + "mkdir " + log_uploaded_path + "; " cmd = cmd + "chmod -R 755 " + log_uploaded_path + "; " crash_log_path = main_utils.get_mobileinsight_crash_log_path() if not os.path.exists(crash_log_path): cmd = cmd + "mkdir " + crash_log_path + "; " cmd = cmd + "chmod -R 755 " + crash_log_path + "; " # cmd = cmd + "chmod -R 755 "+mobileinsight_path+"; " main_utils.run_shell_cmd(cmd) return True