def get_context_from_db_entry(db_entry):
    """Return the context for APPX from DB."""
    try:
        logger.info('Analysis is already Done. Fetching data from the DB...')
        context = {
            'title': 'Static Analysis',
            'version': settings.KENSA_VER,
            'file_name': db_entry[0].FILE_NAME,
            'app_name': db_entry[0].APP_NAME,
            'publisher_name': db_entry[0].PUBLISHER_NAME,
            'size': db_entry[0].SIZE,
            'md5': db_entry[0].MD5,
            'sha1': db_entry[0].SHA1,
            'sha256': db_entry[0].SHA256,
            'app_version': db_entry[0].APP_VERSION,
            'architecture': db_entry[0].ARCHITECTURE,
            'compiler_version': db_entry[0].COMPILER_VERSION,
            'visual_studio_version': db_entry[0].VISUAL_STUDIO_VERSION,
            'visual_studio_edition': db_entry[0].VISUAL_STUDIO_EDITION,
            'target_os': db_entry[0].TARGET_OS,
            'appx_dll_version': db_entry[0].APPX_DLL_VERSION,
            'proj_guid': db_entry[0].PROJ_GUID,
            'opti_tool': db_entry[0].OPTI_TOOL,
            'target_run': db_entry[0].TARGET_RUN,
            'files': python_list(db_entry[0].FILES),
            'strings': python_list(db_entry[0].STRINGS),
            'binary_analysis': python_list(db_entry[0].BINARY_ANALYSIS),
            'binary_warnings': python_list(db_entry[0].BINARY_WARNINGS),
        }
        return context
    except Exception:
        logger.exception('Fetching from DB')
Exemplo n.º 2
0
def get_screenshots(md5_hash, download_dir):
    """Get Screenshots."""
    # Only After Download Process is Done
    result = {}
    imgs = []
    act_imgs = []
    expact_imgs = []
    act = {}
    exp_act = {}
    try:
        screen_dir = os.path.join(download_dir, md5_hash + '-screenshots-apk/')
        sadb = StaticAnalyzerAndroid.objects.filter(MD5=md5_hash)
        if os.path.exists(screen_dir) and sadb.exists():
            for img in os.listdir(screen_dir):
                if img.endswith('.png'):
                    if img.startswith('act'):
                        act_imgs.append(img)
                    elif img.startswith('expact'):
                        expact_imgs.append(img)
                    else:
                        imgs.append(img)
            exported_act = python_list(sadb[0].EXPORTED_ACTIVITIES)
            act_desc = python_list(sadb[0].ACTIVITIES)
            if act_imgs:
                if len(act_imgs) == len(act_desc):
                    act = dict(list(zip(act_imgs, act_desc)))
            if expact_imgs:
                if len(expact_imgs) == len(exported_act):
                    exp_act = dict(list(zip(expact_imgs, exported_act)))
    except Exception:
        logger.exception('Organising screenshots')
    result['screenshots'] = imgs
    result['activities'] = act
    result['exported_activities'] = exp_act
    return result
def activity_tester(request):
    """Exported & non exported activity Tester."""
    data = {}
    try:
        env = Environment()
        test = request.POST['test']
        md5_hash = request.POST['hash']
        package = request.POST['package']
        if is_attack_pattern(package) or not is_md5(md5_hash):
            return invalid_params()
        app_dir = os.path.join(settings.UPLD_DIR, md5_hash + '/')
        screen_dir = os.path.join(app_dir, 'screenshots-apk/')
        if not os.path.exists(screen_dir):
            os.makedirs(screen_dir)
        static_android_db = StaticAnalyzerAndroid.objects.filter(MD5=md5_hash)
        if not static_android_db.exists():
            data = {
                'status': 'failed',
                'message': 'App details not found in database'
            }
            return json_response(data)
        iden = ''
        if test == 'exported':
            iden = 'Exported '
            logger.info('Exported activity tester')
            activities = python_list(static_android_db[0].EXPORTED_ACTIVITIES)
        else:
            logger.info('Activity tester')
            activities = python_list(static_android_db[0].ACTIVITIES)
        logger.info('Fetching %sactivities for %s', iden, package)
        if not activities:
            msg = 'No {}Activites found'.format(iden)
            logger.info(msg)
            data = {'status': 'failed', 'message': msg}
            return json_response(data)
        act_no = 0
        logger.info('Starting %sActivity Tester...', iden)
        logger.info('%s %sActivities Identified', str(len(activities)), iden)
        for activity in activities:
            act_no += 1
            logger.info('Launching %sActivity - %s. %s', iden, str(act_no),
                        activity)
            if test == 'exported':
                file_iden = 'expact'
            else:
                file_iden = 'act'
            outfile = ('{}{}-{}.png'.format(screen_dir, file_iden, act_no))
            env.launch_n_capture(package, activity, outfile)
        data = {'status': 'ok'}
    except Exception as exp:
        logger.exception('%sActivity tester', iden)
        data = {'status': 'failed', 'message': str(exp)}
    return json_response(data)
Exemplo n.º 4
0
def base64_decode(args):
    """Decode Base64 Automatically."""
    decoded = ''
    args_list = python_list(args)
    if not is_base64(args_list[0]):
        return decoded
    try:
        decoded = base64.b64decode(args_list[0]).decode('ISO-8859-1')
    except Exception:
        pass
    return decoded
 def android_component(self, bin_hash, comp):
     """Get APK Components."""
     anddb = StaticAnalyzerAndroid.objects.filter(MD5=bin_hash)
     resp = []
     if comp == 'activities':
         resp = python_list(anddb[0].ACTIVITIES)
     elif comp == 'receivers':
         resp = python_list(anddb[0].RECEIVERS)
     elif comp == 'providers':
         resp = python_list(anddb[0].PROVIDERS)
     elif comp == 'services':
         resp = python_list(anddb[0].SERVICES)
     elif comp == 'libraries':
         resp = python_list(anddb[0].LIBRARIES)
     elif comp == 'exported_activities':
         resp = python_list(anddb[0].EXPORTED_ACTIVITIES)
     return '\n'.join(resp)
Exemplo n.º 6
0
def get_context_from_db_entry(db_entry):
    """Return the context for IPA/ZIP from DB."""
    try:
        logger.info('Analysis is already Done. Fetching data from the DB...')
        context = {
            'version':
            settings.KENSA_VER,
            'title':
            'Static Analysis',
            'file_name':
            db_entry[0].FILE_NAME,
            'app_name':
            db_entry[0].APP_NAME,
            'app_type':
            db_entry[0].APP_TYPE,
            'size':
            db_entry[0].SIZE,
            'md5':
            db_entry[0].MD5,
            'sha1':
            db_entry[0].SHA1,
            'sha256':
            db_entry[0].SHA256,
            'build':
            db_entry[0].BUILD,
            'app_version':
            db_entry[0].APP_VERSION,
            'sdk_name':
            db_entry[0].SDK_NAME,
            'platform':
            db_entry[0].PLATFORM,
            'min_os_version':
            db_entry[0].MIN_OS_VERSION,
            'bundle_id':
            db_entry[0].BUNDLE_ID,
            'bundle_url_types':
            python_list(db_entry[0].BUNDLE_URL_TYPES),
            'bundle_supported_platforms':
            python_list(db_entry[0].BUNDLE_SUPPORTED_PLATFORMS),
            'icon_found':
            db_entry[0].ICON_FOUND,
            'info_plist':
            db_entry[0].INFO_PLIST,
            'binary_info':
            python_dict(db_entry[0].MACHO_INFO),
            'permissions':
            python_list(db_entry[0].PERMISSIONS),
            'ats_analysis':
            python_list(db_entry[0].ATS_ANALYSIS),
            'binary_analysis':
            python_list(db_entry[0].BINARY_ANALYSIS),
            'ios_api':
            python_dict(db_entry[0].IOS_API),
            'code_analysis':
            python_dict(db_entry[0].CODE_ANALYSIS),
            'file_analysis':
            python_list(db_entry[0].FILE_ANALYSIS),
            'libraries':
            python_list(db_entry[0].LIBRARIES),
            'files':
            python_list(db_entry[0].FILES),
            'urls':
            python_list(db_entry[0].URLS),
            'domains':
            python_dict(db_entry[0].DOMAINS),
            'emails':
            python_list(db_entry[0].EMAILS),
            'strings':
            python_list(db_entry[0].STRINGS),
            'firebase_urls':
            python_list(db_entry[0].FIREBASE_URLS),
            'appstore_details':
            python_dict(db_entry[0].APPSTORE_DETAILS),
        }
        return context
    except Exception:
        logger.exception('Fetching from DB')
Exemplo n.º 7
0
def get_context_from_db_entry(db_entry: QuerySet) -> dict:
    """Return the context for APK/ZIP from DB."""
    try:
        logger.info('Analysis is already Done. Fetching data from the DB...')
        context = {
            'version': settings.KENSA_VER,
            'title': 'Static Analysis',
            'file_name': db_entry[0].FILE_NAME,
            'app_name': db_entry[0].APP_NAME,
            'app_type': db_entry[0].APP_TYPE,
            'size': db_entry[0].SIZE,
            'md5': db_entry[0].MD5,
            'sha1': db_entry[0].SHA1,
            'sha256': db_entry[0].SHA256,
            'package_name': db_entry[0].PACKAGE_NAME,
            'main_activity': db_entry[0].MAIN_ACTIVITY,
            'exported_activities': db_entry[0].EXPORTED_ACTIVITIES,
            'browsable_activities':
            python_dict(db_entry[0].BROWSABLE_ACTIVITIES),
            'activities': python_list(db_entry[0].ACTIVITIES),
            'receivers': python_list(db_entry[0].RECEIVERS),
            'providers': python_list(db_entry[0].PROVIDERS),
            'services': python_list(db_entry[0].SERVICES),
            'libraries': python_list(db_entry[0].LIBRARIES),
            'target_sdk': db_entry[0].TARGET_SDK,
            'max_sdk': db_entry[0].MAX_SDK,
            'min_sdk': db_entry[0].MIN_SDK,
            'version_name': db_entry[0].VERSION_NAME,
            'version_code': db_entry[0].VERSION_CODE,
            'icon_hidden': db_entry[0].ICON_HIDDEN,
            'icon_found': db_entry[0].ICON_FOUND,
            'permissions': python_dict(db_entry[0].PERMISSIONS),
            'certificate_analysis':
            python_dict(db_entry[0].CERTIFICATE_ANALYSIS),
            'manifest_analysis': python_list(db_entry[0].MANIFEST_ANALYSIS),
            'binary_analysis': python_list(db_entry[0].BINARY_ANALYSIS),
            'file_analysis': python_list(db_entry[0].FILE_ANALYSIS),
            'android_api': python_dict(db_entry[0].ANDROID_API),
            'code_analysis': python_dict(db_entry[0].CODE_ANALYSIS),
            'urls': python_list(db_entry[0].URLS),
            'domains': python_dict(db_entry[0].DOMAINS),
            'emails': python_list(db_entry[0].EMAILS),
            'strings': python_list(db_entry[0].STRINGS),
            'firebase_urls': python_list(db_entry[0].FIREBASE_URLS),
            'files': python_list(db_entry[0].FILES),
            'exported_count': python_dict(db_entry[0].EXPORTED_COUNT),
            'apkid': python_dict(db_entry[0].APKID),
            'trackers': python_dict(db_entry[0].TRACKERS),
            'playstore_details': python_dict(db_entry[0].PLAYSTORE_DETAILS),
        }
        return context
    except Exception:
        logger.exception('Fetching from DB')