def add_comment(self, id): if comments_enabled(): f = File(get_or_404(current_user.files, _id=id)) if current_user.has_permission('add_probable_name'): probable_name = request.form.get('probable_name') else: probable_name = None comment = request.form.get('comment') analysis_id = request.form.get('analysis') notify = request.form.get('notify') if comment: # If there is an analysis ID, make sure it is accessible if analysis_id: get_or_404(current_user.analyses, _id=analysis_id) f.add_comment(current_user['_id'], comment, analysis_id, probable_name) if notify: self.notify_new_comment(f, analysis_id, current_user['_id'], comment) else: flash('Comment should not be empty', 'danger') return redirect(request.referrer)
def get(self, id): """Get the analysis with `id`. .. :quickref: Analysis; Get an analysis Resulting object is in the ``analysis`` field. :param id: id of the analysis. :>json dict _id: ObjectId dict. :>json dict analyst: analyst's ObjectId. :>json dict date: date dict. :>json list executed_modules: list of executed modules. :>json list pending_modules: list of pending modules. :>json list waiting_modules: list of waiting modules. :>json list canceled_modules: list of canceled modules. :>json list executed_modules: list of executed modules. :>json string module: the name of the target module. :>json string status: status of the analysis (one of `pending`, `running`, `finished` or `error`). :>json list tags: the list of tags. :>json list probable_names: the list of probable names. :>json list iocs: list of dict describing observables. :>json dict results: detailed results for each module, with the module name being the key. :>json dict generated_files: a dict of generated files, the key being the file type. :>json list extracted_files: a list of extracted files. :>json dict support_files: a dict of support files, the key being the module name. """ analysis = { 'analysis': clean_analyses(get_or_404(current_user.analyses, _id=id)) } file = current_user.files.find_one( {'_id': analysis['analysis']['file']}) analysis['analysis']['file'] = enrich_comments(clean_files(file)) ti_modules = [m for m in dispatcher.get_threat_intelligence_modules()] av_modules = [m.name for m in dispatcher.get_antivirus_modules()] if 'extracted_files' in analysis['analysis']: files = [] for id in analysis['analysis']['extracted_files']: files.append(current_user.files.find_one({'_id': id})) analysis['analysis']['extracted_files'] = clean_files(files) modules = dict() for module in ModuleInfo.get_collection().find(): modules[module['name']] = ModuleInfo(module) return render(analysis, 'analyses/show.html', ctx={ 'analysis': analysis, 'modules': modules, 'av_modules': av_modules, 'ti_modules': ti_modules, 'comments_enabled': comments_enabled() })
def return_file(file): analyses = list(current_user.analyses.find({'_id': {'$in': file['file']['analysis']}})) file['av_modules'] = [m.name for m in dispatcher.get_antivirus_modules()] for analysis in analyses: if 'analyst' in analysis: analyst = store.users.find_one({'_id': analysis['analyst']}) analysis['analyst'] = clean_users(analyst) file['file']['analysis'] = clean_analyses(analyses) return render(file, 'files/show.html', ctx={ 'data': file, 'options': dispatcher.options, 'comments_enabled': comments_enabled()})
def new(self): # See if Hash submission is available config = Config.get(name="virustotal") hash_capable = False if config: try: config.get_values() hash_capable = True except Exception: hash_capable = False return render_template('analyses/new.html', hash_capable=hash_capable, comments_enabled=comments_enabled(), options=dispatcher.options)
def return_file(file): analyses = list( current_user.analyses.find({"_id": { "$in": file["file"]["analysis"] }})) file["av_modules"] = [m.name for m in dispatcher.get_antivirus_modules()] for analysis in analyses: if "analyst" in analysis: analyst = store.users.find_one({"_id": analysis["analyst"]}) analysis["analyst"] = clean_users(analyst) file["file"]["analysis"] = clean_analyses(analyses) return render( file, "files/show.html", ctx={ "data": file, "options": dispatcher.options, "comments_enabled": comments_enabled() }, )
def add_comment(self, id): if comments_enabled(): f = File(get_or_404(current_user.files, _id=id)) if current_user.has_permission("add_probable_name"): probable_name = request.form.get("probable_name") else: probable_name = None comment = request.form.get("comment") analysis_id = request.form.get("analysis") notify = request.form.get("notify") if comment: # If there is an analysis ID, make sure it is accessible if analysis_id: get_or_404(current_user.analyses, _id=analysis_id) f.add_comment(current_user["_id"], comment, analysis_id, probable_name, notify) else: flash("Comment should not be empty", "danger") return redirect(request.referrer)
def new(self): return render_template('analyses/new.html', options=dispatcher.options, comments_enabled=comments_enabled())