def delete_scan(request): """ Delete Scan from DB and remove the scan related files """ try: if request.method == 'POST': md5_hash = request.POST['md5'] data = {'deleted': 'no'} if re.match('[0-9a-f]{32}', md5_hash): # Delete DB Entries RecentScansDB.objects.filter(MD5=md5_hash).delete() ScopeURLSandTests.objects.filter(MD5=md5_hash).delete() StaticAnalyzerAndroid.objects.filter(MD5=md5_hash).delete() StaticAnalyzerIPA.objects.filter(MD5=md5_hash).delete() StaticAnalyzerIOSZIP.objects.filter(MD5=md5_hash).delete() StaticAnalyzerWindows.objects.filter(MD5=md5_hash).delete() # Delete Upload Dir Contents app_upload_dir = os.path.join(settings.UPLD_DIR, md5_hash) if isDirExists(app_upload_dir): shutil.rmtree(app_upload_dir) # Delete Download Dir Contents dw_dir = settings.DWD_DIR for item in os.listdir(dw_dir): item_path = os.path.join(dw_dir, item) # Delete all related files if isFileExists(item_path) and item.startswith(md5_hash + "-"): os.remove(item_path) # Delete related directories if isDirExists(item_path) and item.startswith(md5_hash + "-"): shutil.rmtree(item_path) data = {'deleted': 'yes'} return HttpResponse(json.dumps(data), content_type='application/json') except: PrintException("Error Deleting Scan") return HttpResponseRedirect('/error/')
def delete_scan(request, api=False): """ Delete Scan from DB and remove the scan related files """ try: if request.method == 'POST': if api: md5_hash = request.POST['hash'] else: md5_hash = request.POST['md5'] data = {'deleted': 'no'} if re.match('[0-9a-f]{32}', md5_hash): # Delete DB Entries scan = RecentScansDB.objects.filter(MD5=md5_hash) if scan.exists(): RecentScansDB.objects.filter(MD5=md5_hash).delete() StaticAnalyzerAndroid.objects.filter(MD5=md5_hash).delete() StaticAnalyzerIPA.objects.filter(MD5=md5_hash).delete() StaticAnalyzerIOSZIP.objects.filter(MD5=md5_hash).delete() StaticAnalyzerWindows.objects.filter(MD5=md5_hash).delete() # Delete Upload Dir Contents app_upload_dir = os.path.join(settings.UPLD_DIR, md5_hash) if isDirExists(app_upload_dir): shutil.rmtree(app_upload_dir) # Delete Download Dir Contents dw_dir = settings.DWD_DIR for item in os.listdir(dw_dir): item_path = os.path.join(dw_dir, item) # Delete all related files if isFileExists(item_path) and item.startswith( md5_hash + "-"): os.remove(item_path) # Delete related directories if isDirExists(item_path) and item.startswith( md5_hash + "-"): shutil.rmtree(item_path) data = {'deleted': 'yes'} if api: return data else: return HttpResponse( json.dumps(data), content_type='application/json; charset=utf-8') except Exception as exp: msg = str(exp) exp_doc = exp.__doc__ if api: return print_n_send_error_response(request, msg, True, exp_doc) else: return print_n_send_error_response(request, msg, False, exp_doc)
def delete_scan(request, api=False): """ Delete Scan from DB and remove the scan related files """ try: if request.method == 'POST': if api: md5_hash = request.POST['hash'] else: md5_hash = request.POST['md5'] data = {'deleted': 'no'} if re.match('[0-9a-f]{32}', md5_hash): # Delete DB Entries scan = RecentScansDB.objects.filter(MD5=md5_hash) if scan.exists(): RecentScansDB.objects.filter(MD5=md5_hash).delete() ScopeURLSandTests.objects.filter(MD5=md5_hash).delete() StaticAnalyzerAndroid.objects.filter(MD5=md5_hash).delete() StaticAnalyzerIPA.objects.filter(MD5=md5_hash).delete() StaticAnalyzerIOSZIP.objects.filter(MD5=md5_hash).delete() StaticAnalyzerWindows.objects.filter(MD5=md5_hash).delete() # Delete Upload Dir Contents app_upload_dir = os.path.join(settings.UPLD_DIR, md5_hash) if isDirExists(app_upload_dir): shutil.rmtree(app_upload_dir) # Delete Download Dir Contents dw_dir = settings.DWD_DIR for item in os.listdir(dw_dir): item_path = os.path.join(dw_dir, item) # Delete all related files if isFileExists(item_path) and item.startswith(md5_hash + "-"): os.remove(item_path) # Delete related directories if isDirExists(item_path) and item.startswith(md5_hash + "-"): shutil.rmtree(item_path) data = {'deleted': 'yes'} if api: return data else: return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8') except Exception as exp: msg = str(exp) exp_doc = exp.__doc__ if api: return print_n_send_error_response(request, msg, True, exp_doc) else: return print_n_send_error_response(request, msg, False, exp_doc)
def dex_2_jar(app_path, app_dir, tools_dir): """Run dex2jar.""" try: print "[INFO] DEX -> JAR" working_dir = None args = [] if settings.JAR_CONVERTER == "d2j": print "[INFO] Using JAR converter - dex2jar" if len(settings.DEX2JAR_BINARY) > 0 and isFileExists(settings.DEX2JAR_BINARY): d2j = settings.DEX2JAR_BINARY else: if platform.system() == "Windows": win_fix_java(tools_dir) d2j = os.path.join(tools_dir, 'd2j2/d2j-dex2jar.bat') else: inv = os.path.join(tools_dir, 'd2j2/d2j_invoke.sh') d2j = os.path.join(tools_dir, 'd2j2/d2j-dex2jar.sh') subprocess.call(["chmod", "777", d2j]) subprocess.call(["chmod", "777", inv]) args = [ d2j, app_dir + 'classes.dex', '-f', '-o', app_dir + 'classes.jar' ] elif settings.JAR_CONVERTER == "enjarify": print "[INFO] Using JAR converter - Google enjarify" if len(settings.ENJARIFY_DIRECTORY) > 0 and isDirExists(settings.ENJARIFY_DIRECTORY): working_dir = settings.ENJARIFY_DIRECTORY else: working_dir = os.path.join(tools_dir, 'enjarify/') if platform.system() == "Windows": win_fix_python3(tools_dir) enjarify = os.path.join(working_dir, 'enjarify.bat') args = [enjarify, app_path, "-f", "-o", app_dir + 'classes.jar'] else: if len(settings.PYTHON3_PATH) > 2: python3 = os.path.join(settings.PYTHON3_PATH, "python3") else: python3 = "python3" args = [ python3, "-O", "-m", "enjarify.main", app_path, "-f", "-o", app_dir + 'classes.jar' ] if working_dir: subprocess.call(args, cwd=working_dir) else: subprocess.call(args) except: PrintException("[ERROR] Converting Dex to JAR")
def dex_2_jar(app_path, app_dir, tools_dir): """Run dex2jar.""" try: logger.info("DEX -> JAR") working_dir = None args = [] if settings.JAR_CONVERTER == "d2j": logger.info("Using JAR converter - dex2jar") dexes = get_dex_files(app_dir) for idx, dex in enumerate(dexes): logger.info("Converting " + filename_from_path(dex) + " to JAR") if len(settings.DEX2JAR_BINARY) > 0 and isFileExists( settings.DEX2JAR_BINARY): d2j = settings.DEX2JAR_BINARY else: if platform.system() == "Windows": win_fix_java(tools_dir) d2j = os.path.join(tools_dir, 'd2j2/d2j-dex2jar.bat') else: inv = os.path.join(tools_dir, 'd2j2/d2j_invoke.sh') d2j = os.path.join(tools_dir, 'd2j2/d2j-dex2jar.sh') subprocess.call(["chmod", "777", d2j]) subprocess.call(["chmod", "777", inv]) args = [ d2j, dex, '-f', '-o', app_dir + 'classes' + str(idx) + '.jar' ] subprocess.call(args) elif settings.JAR_CONVERTER == "enjarify": logger.info("Using JAR converter - Google enjarify") if len(settings.ENJARIFY_DIRECTORY) > 0 and isDirExists( settings.ENJARIFY_DIRECTORY): working_dir = settings.ENJARIFY_DIRECTORY else: working_dir = os.path.join(tools_dir, 'enjarify/') if platform.system() == "Windows": win_fix_python3(tools_dir) enjarify = os.path.join(working_dir, 'enjarify.bat') args = [ enjarify, app_path, "-f", "-o", app_dir + 'classes.jar' ] else: if len(settings.PYTHON3_PATH) > 2: python3 = os.path.join(settings.PYTHON3_PATH, "python3") else: python3 = get_python() args = [ python3, "-O", "-m", "enjarify.main", app_path, "-f", "-o", app_dir + 'classes.jar' ] subprocess.call(args, cwd=working_dir) except: PrintException("Converting Dex to JAR")
def dex_2_jar(app_path, app_dir, tools_dir): """Run dex2jar.""" try: print "[INFO] DEX -> JAR" working_dir = None args = [] if settings.JAR_CONVERTER == "d2j": print "[INFO] Using JAR converter - dex2jar" if platform.system() == "Windows": win_fix_java(tools_dir) d2j = os.path.join(tools_dir, 'd2j2/d2j-dex2jar.bat') else: inv = os.path.join(tools_dir, 'd2j2/d2j_invoke.sh') d2j = os.path.join(tools_dir, 'd2j2/d2j-dex2jar.sh') subprocess.call(["chmod", "777", d2j]) subprocess.call(["chmod", "777", inv]) if len(settings.DEX2JAR_BINARY) > 0 and isFileExists( settings.DEX2JAR_BINARY): d2j = settings.DEX2JAR_BINARY args = [ d2j, app_dir + 'classes.dex', '-f', '-o', app_dir + 'classes.jar' ] elif settings.JAR_CONVERTER == "enjarify": print "[INFO] Using JAR converter - Google enjarify" if len(settings.ENJARIFY_DIRECTORY) > 0 and isDirExists( settings.ENJARIFY_DIRECTORY): working_dir = settings.ENJARIFY_DIRECTORY else: working_dir = os.path.join(tools_dir, 'enjarify/') if platform.system() == "Windows": win_fix_python3(tools_dir) enjarify = os.path.join(working_dir, 'enjarify.bat') args = [ enjarify, app_path, "-f", "-o", app_dir + 'classes.jar' ] else: if len(settings.PYTHON3_PATH) > 2: python3 = os.path.join(settings.PYTHON3_PATH, "python3") else: python3 = "python3" args = [ python3, "-O", "-m", "enjarify.main", app_path, "-f", "-o", app_dir + 'classes.jar' ] if working_dir: subprocess.call(args, cwd=working_dir) else: subprocess.call(args) except: PrintException("[ERROR] Converting Dex to JAR")