def is_valid(self): if not os.path.exists(self.path): return False if not os.path.isfile(self.path): return False if sys.version_info < (3, 0): # on Python2 make sure to only handle ASCII filenames try: self.path.decode('ascii') except UnicodeEncodeError as err: raise Python2UnsupportedUnicode( "Non ASCII character(s) in file name not supported on Python2.\n" "EncodeError: {}\n" "File: {}\n" "Please use Python >= 3.4".format( self.path.encode("utf-8"), err), "error") except UnicodeDecodeError as err: raise Python2UnsupportedUnicode( "Non ASCII character(s) in file name not supported on Python2.\n" "DecodeError: {}\n" "File: {}\n" "Please use Python >= 3.4".format(self.path, err), "error") return True
def add_malwarevt(self, sha256, scan_id, permalink, resource, verbose_msg, scan_date, positives, total): session = self.Session() if sys.version_info < (3, 0): # on Python2 make sure to only handle ASCII try: title.decode('ascii') body.decode('ascii') except UnicodeError as err: raise Python2UnsupportedUnicode( "Non ASCII character(s) in Notes not supported on Python2.\n" "Please use Python >= 3.4".format(err), "error") malware_entry = session.query(Malware).filter( Malware.sha256 == sha256).first() if not malware_entry: return False try: new_malwarevt = MalwareVT(scan_id, permalink, resource, verbose_msg, scan_date, positives, total) malware_entry.malwarevt.append(new_malwarevt) session.commit() self.added_ids.setdefault("malwarevt", []).append(new_malwarevt.id) except SQLAlchemyError as e: print_error("Unable to add virus total register: {0}".format(e)) session.rollback()
def add_note(self, sha256, title, body): session = self.Session() if sys.version_info < (3, 0): # on Python2 make sure to only handle ASCII try: title.decode('ascii') body.decode('ascii') except UnicodeError as err: raise Python2UnsupportedUnicode( "Non ASCII character(s) in Notes not supported on Python2.\n" "Please use Python >= 3.4".format(err), "error") malware_entry = session.query(Malware).filter( Malware.sha256 == sha256).first() if not malware_entry: return try: new_note = Note(title, body) malware_entry.note.append(new_note) session.commit() self.added_ids.setdefault("note", []).append(new_note.id) except SQLAlchemyError as e: print_error("Unable to add note: {0}".format(e)) session.rollback() finally: session.close()
def add_malwareanalysismacros(self, sha256, type, keyword, description): session = self.Session() if sys.version_info < (3, 0): # on Python2 make sure to only handle ASCII try: title.decode('ascii') body.decode('ascii') except UnicodeError as err: raise Python2UnsupportedUnicode( "Non ASCII character(s) in Notes not supported on Python2.\n" "Please use Python >= 3.4".format(err), "error") malware_entry = session.query(Malware).filter( Malware.sha256 == sha256).first() if not malware_entry: return False try: new_malwareanalysismacros = MalwareAnalysisMacros( type, keyword, description) malware_entry.malwareanalysismacros.append( new_malwareanalysismacros) session.commit() self.added_ids.setdefault("malwareanalysismacros", []).append(new_malwareanalysismacros.id) except SQLAlchemyError as e: print_error("Unable to add malware analysis macros: {0}".format(e)) session.rollback()
def add_malwarevtsc(self, sha256, antivirus, detected, version, result, update): session = self.Session() if sys.version_info < (3, 0): # on Python2 make sure to only handle ASCII try: title.decode('ascii') body.decode('ascii') except UnicodeError as err: raise Python2UnsupportedUnicode( "Non ASCII character(s) in Notes not supported on Python2.\n" "Please use Python >= 3.4".format(err), "error") malware_entry = session.query(Malware).filter( Malware.sha256 == sha256).first() if not malware_entry: return False try: new_malwarevtsc = MalwareVTSc(antivirus, detected, version, result, update) malware_entry.malwarevtsc.append(new_malwarevtsc) session.commit() self.added_ids.setdefault("malwarevtsc", []).append(new_malwarevtsc.id) except SQLAlchemyError as e: print_error("Unable to add malware scan: {0}".format(e)) session.rollback()
def get_note(self, note_id): session = self.Session() note = session.query(Note).get(note_id) if sys.version_info < (3, 0): # on Python2 make sure to only handle ASCII filenames try: note.title.decode('ascii') note.body.decode('ascii') except UnicodeError as err: raise Python2UnsupportedUnicode("Non ASCII character(s) in Notes not supported on Python2.\n" "Please use Python >= 3.4".format(err), "error") return note
def get_malwareanalysismacros(self, malwareanalysismacros_id): session = self.Session() malwareanalysismacros = session.query(MalwareAnalysisMacros).get( malwareanalysismacros_id) if sys.version_info < (3, 0): # on Python2 make sure to only handle ASCII filenames try: note.title.decode('ascii') note.body.decode('ascii') except UnicodeError as err: raise Python2UnsupportedUnicode( "Non ASCII character(s) in Notes not supported on Python2.\n" "Please use Python >= 3.4".format(err), "error") return malwareanalysismacros
def update_malware_olevba(self, id, type_olevba): session = self.Session() if sys.version_info < (3, 0): # on Python2 make sure to only handle ASCII try: title.decode('ascii') body.decode('ascii') except UnicodeError as err: raise Python2UnsupportedUnicode( "Non ASCII character(s) in Notes not supported on Python2.\n" "Please use Python >= 3.4".format(err), "error") try: session.query(Malware).get(id).type_olevba = type_olevba session.commit() except SQLAlchemyError as e: print_error("Unable to update type olevba: {0}".format(e)) session.rollback()
def edit_note(self, note_id, body): session = self.Session() if sys.version_info < (3, 0): # on Python2 make sure to only handle ASCII try: body.decode('ascii') except UnicodeError as err: raise Python2UnsupportedUnicode("Non ASCII character(s) in Notes not supported on Python2.\n" "Please use Python >= 3.4".format(err), "error") try: session.query(Note).get(note_id).body = body session.commit() except SQLAlchemyError as e: print_error("Unable to update note: {0}".format(e)) session.rollback() finally: session.close()
def update_malwarevt(self, resource, scan_date, positives, total): session = self.Session() if sys.version_info < (3, 0): # on Python2 make sure to only handle ASCII try: title.decode('ascii') body.decode('ascii') except UnicodeError as err: raise Python2UnsupportedUnicode( "Non ASCII character(s) in Notes not supported on Python2.\n" "Please use Python >= 3.4".format(err), "error") malwarevt_id = session.query(MalwareVT).filter( MalwareVT.resource == resource) try: session.query(MalwareVT).get(malwarevt_id).scan_date = scan_date session.query(MalwareVT).get(malwarevt_id).positives = positives session.query(MalwareVT).get(malwarevt_id).total = total session.commit() except SQLAlchemyError as e: print_error("Unable to update virus total register: {0}".format(e)) session.rollback()