def install_mobsf_ca(self, action): """Install or Remove MobSF Root CA.""" ca_construct = '{}.0' pem = open(get_ca_dir(), 'rb').read() ca_file = crypto.load_certificate(crypto.FILETYPE_PEM, pem) ca_file_hash = hex(ca_file.subject_name_hash()).lstrip('0x') ca_file = os.path.join('/system/etc/security/cacerts/', ca_construct.format(ca_file_hash)) if action == 'install': logger.info('Installing MobSF RootCA') self.adb_command(['push', get_ca_dir(), ca_file]) self.adb_command(['chmod', '644', ca_file], True) elif action == 'remove': logger.info('Removing MobSF RootCA') self.adb_command(['rm', ca_file], True)
def mobsf_ca(request): """Install and Remove MobSF Proxy RootCA.""" try: if request.method == 'POST': data = {} act = request.POST['action'] rootca = get_ca_dir() if act == 'install': logger.info('Installing MobSF RootCA') adb_command( ['push', rootca, '/data/local/tmp/' + settings.ROOT_CA]) ca_file = '/system/etc/security/cacerts/' + settings.ROOT_CA adb_command([ 'su', '-c', 'cp', '/data/local/tmp/' + settings.ROOT_CA, ca_file ], True) adb_command(['su', '-c', 'chmod', '644', ca_file], True) adb_command(['rm', '/data/local/tmp/' + settings.ROOT_CA], True) data = {'ca': 'installed'} elif act == 'remove': logger.info('Removing MobSF RootCA') adb_command(['su', '-c', 'rm', ca_file], True) data = {'ca': 'removed'} return HttpResponse(json.dumps(data), content_type='application/json') else: return print_n_send_error_response(request, 'Only POST allowed', True) except Exception: logger.exception('MobSF RootCA Handler') return print_n_send_error_response(request, 'Error in RootCA Handler', True)
def mobsf_ca(request): """Install and Remove MobSF Proxy RootCA""" try: if request.method == 'POST': data = {} act = request.POST['action'] rootca = get_ca_dir() adb = getADB() if act == "install": logger.info("Installing MobSF RootCA") adb_command( ["push", rootca, "/data/local/tmp/" + settings.ROOT_CA]) if settings.ANDROID_DYNAMIC_ANALYZER == "MobSF_AVD": # For some reason, avd emulator does not have cp binary adb_command([ "/data/local/tmp/busybox", "cp", "/data/local/tmp/" + settings.ROOT_CA, "/system/etc/security/cacerts/" + settings.ROOT_CA ], True) adb_command([ "chmod", "644", "/system/etc/security/cacerts/" + settings.ROOT_CA ], True) else: adb_command([ "su", "-c", "cp", "/data/local/tmp/" + settings.ROOT_CA, "/system/etc/security/cacerts/" + settings.ROOT_CA ], True) adb_command([ "su", "-c", "chmod", "644", "/system/etc/security/cacerts/" + settings.ROOT_CA ], True) adb_command(["rm", "/data/local/tmp/" + settings.ROOT_CA], True) data = {'ca': 'installed'} elif act == "remove": logger.info("Removing MobSF RootCA") if settings.ANDROID_DYNAMIC_ANALYZER == "MobSF_AVD": adb_command([ "rm", "/system/etc/security/cacerts/" + settings.ROOT_CA ], True) else: adb_command([ "su", "-c", "rm", "/system/etc/security/cacerts/" + settings.ROOT_CA ], True) data = {'ca': 'removed'} return HttpResponse(json.dumps(data), content_type='application/json') else: return print_n_send_error_response(request, "Only POST allowed", True) except: PrintException("MobSF RootCA Handler") return print_n_send_error_response(request, "Error in RootCA Handler", True)
def install_mobsf_ca(self, action): """Install or Remove MobSF Root CA.""" ca_file = os.path.join('/system/etc/security/cacerts/', settings.ROOT_CA) if action == 'install': logger.info('Installing MobSF RootCA') self.adb_command(['push', get_ca_dir(), ca_file]) self.adb_command(['chmod', '644', ca_file], True) elif action == 'remove': logger.info('Removing MobSF RootCA') self.adb_command(['rm', ca_file], True)
def mobsf_ca(request): """Install and Remove MobSF Proxy RootCA""" try: if request.method == 'POST': data = {} act = request.POST['action'] rootca = get_ca_dir() adb = getADB() if act == "install": print("\n[INFO] Installing MobSF RootCA") adb_command( ["push", rootca, "/data/local/tmp/" + settings.ROOT_CA]) if settings.ANDROID_DYNAMIC_ANALYZER == "MobSF_AVD": # For some reason, avd emulator does not have cp binary adb_command(["/data/local/tmp/busybox", "cp", "/data/local/tmp/" + settings.ROOT_CA, "/system/etc/security/cacerts/" + settings.ROOT_CA], True) adb_command(["chmod", "644", "/system/etc/security/cacerts/" + settings.ROOT_CA], True) else: adb_command(["su", "-c", "cp", "/data/local/tmp/" + settings.ROOT_CA, "/system/etc/security/cacerts/" + settings.ROOT_CA], True) adb_command(["su", "-c", "chmod", "644", "/system/etc/security/cacerts/" + settings.ROOT_CA], True) adb_command( ["rm", "/data/local/tmp/" + settings.ROOT_CA], True) data = {'ca': 'installed'} elif act == "remove": print("\n[INFO] Removing MobSF RootCA") if settings.ANDROID_DYNAMIC_ANALYZER == "MobSF_AVD": adb_command( ["rm", "/system/etc/security/cacerts/" + settings.ROOT_CA], True) else: adb_command(["su", "-c", "rm", "/system/etc/security/cacerts/" + settings.ROOT_CA], True) data = {'ca': 'removed'} return HttpResponse(json.dumps(data), content_type='application/json') else: return HttpResponseRedirect('/error/') except: PrintException("[ERROR] MobSF RootCA Handler") return HttpResponseRedirect('/error/')
def mobsf_ca(request): """Install and Remove MobSF Proxy RootCA""" try: if request.method == 'POST': data = {} act = request.POST['action'] rootca = get_ca_dir() toolsdir = os.path.join( settings.BASE_DIR, 'DynamicAnalyzer/tools/') # TOOLS DIR adb = getADB(toolsdir) if act == "install": print("\n[INFO] Installing RootCA") subprocess.call([adb, "-s", get_identifier(), "push", rootca, "/data/local/tmp/" + settings.ROOT_CA]) if settings.ANDROID_DYNAMIC_ANALYZER == "MobSF_AVD": # For some reason, avd emulator does not have cp binary subprocess.call([adb, "-s", get_identifier(), "shell", "/data/local/tmp/busybox", "cp", "/data/local/tmp/" + settings.ROOT_CA, "/system/etc/security/cacerts/" + settings.ROOT_CA]) subprocess.call([adb, "-s", get_identifier(), "shell", "chmod", "644", "/system/etc/security/cacerts/" + settings.ROOT_CA]) else: subprocess.call([adb, "-s", get_identifier(), "shell", "su", "-c", "cp", "/data/local/tmp/" + settings.ROOT_CA, "/system/etc/security/cacerts/" + settings.ROOT_CA]) subprocess.call([adb, "-s", get_identifier(), "shell", "su", "-c", "chmod", "644", "/system/etc/security/cacerts/" + settings.ROOT_CA]) subprocess.call([adb, "-s", get_identifier(), "shell", "rm", "/data/local/tmp/" + settings.ROOT_CA]) data = {'ca': 'installed'} elif act == "remove": print("\n[INFO] Removing RootCA") if settings.ANDROID_DYNAMIC_ANALYZER == "MobSF_AVD": subprocess.call([adb, "-s", get_identifier(), "shell", "rm", "/system/etc/security/cacerts/" + settings.ROOT_CA]) else: subprocess.call([adb, "-s", get_identifier(), "shell", "su", "-c", "rm", "/system/etc/security/cacerts/" + settings.ROOT_CA]) data = {'ca': 'removed'} return HttpResponse(json.dumps(data), content_type='application/json') else: return HttpResponseRedirect('/error/') except: PrintException("[ERROR] RootCA Handler") return HttpResponseRedirect('/error/')