def vote(self, message): nodeID = message["nodeID"] _b = message['data']['blocks'] try: crypto.verifydata(pub=_b['pubkey'], sigdata=_b['signature'], origdata=_b["block"]) except: print("Vote verification failed!") try: block = _b["block"] if self.temp[block]: try: if nodeID not in self.temp[block]["voters"] and not self.temp[block]['agreed']: self.temp[block]["voters"].append(nodeID) if len(self.temp[block]["voters"]) >= self.threshold: print("Consensus reached, broadcasting block...") self.temp[block]['agreed'] = True consensus = {"method":"08", "blocks":self.temp[block]['block']} self.pm.broadcast(consensus) self.temp[block]['block']['hash'] = int(self.temp[block]['block']['hash'],16) Database.createBlock([self.temp[block]['block']], self.db) except KeyError: print("NodeID not from peer!") else: print("Block empty...") except KeyError: print("Block not proposed by this node!")
def manage_index(self, dbname): if not self._db_exist(dbname): redirect("/") db = Database(dbname) data = db.list_sites() template = self.env.get_template('manage.html') return template.render(data=data)
def hola(self): clean_console() self.database = Database("facturas") bill1 = self.database.get_data_in_database() loop = True v = True while loop: try: iden = int(input("Digite el número de factura: ")) print() for i in bill1: if i["No. Factura"] == iden: keys = i.keys() for j in keys: print(str(j) + ": " + str(i[j])) print() v = True loop = False break else: v = False if v == False: print("No existe una factura registrada a este número") except: print("Vuelva a digitar el número de factura")
def getBlockHashes(self, maxBlocks): blockNum = Database.getBlockNumber(self.db) blocks = [] for num in range(maxBlocks, blockNum): block = Database.getBlockByID(num, self.db) blocks.append(block["hash"]) result = {"method": "03", "hash": blocks} return result
def create_tables(self): self.db = Database() for f in self.structure_dir: # TODO check sql_path = os.path.join(self.structure_dir, f) sql = open(sql_path, 'r').read() result = self.db.query(sql) if not result: return False return True
def __init__(self): # Datenbank self.__database = Database() # Kofiguration aus der reporting.conf holen self.__cfgReporting = Config( os.path.join(RAGPICKER_ROOT, 'config', 'reporting.conf')) self.__vxcageEnabled = self.__cfgReporting.getOption( "vxcage", "enabled") self.__vxcageHost = self.__cfgReporting.getOption("vxcage", "host") self.__vxcagePort = self.__cfgReporting.getOption("vxcage", "port")
def get_bills(self,client): self.database = Database("facturas") BD = self.database._count_database() if BD == False: BD = 0 dic = {"No. Factura" : BD} dic.update(client[0]) self.save(dic) print() print("Factura No " + str(BD) + " generada") print()
def run(self, results, objfile): """Writes report. @param results: analysis results dictionary. @param objfile: file object """ database = Database() # Count query using URL hash and file hash count = database.countRagpickerDB(results["Info"]["file"]["md5"], results["Info"]["url"]["md5"]) # If report available for the file and url -> not insert if count == 0: # Create a copy of the dictionary. This is done in order to not modify # the original dictionary and possibly compromise the following # reporting modules. report = dict(results) # Store the report database.insertRagpickerDB(report) count = database.countFamilyDB(objfile.family.parentObjectSHA256) if count == 0: if objfile.family.unpackedObjectSHA256 != "" or len( objfile.family.siblingObjectsSHA256) > 0: log.info(objfile.family) report = dict(objfile.family.__dict__) database.insertFamily(report)
def export_data(metadata: list, tasks: list, config: LightWeightMethodConfig): if config.recursive: config.dest_path.mkdir(exist_ok=True) move_output_files(config) database = Database() for task in tasks: metadata[task['id']][3] = task['success'] metadata[task['id']][4] = task['err_msg'] paper = metadata[task['id']] try: database.update_query(paper[0], paper[3], paper[4]) except Exception as e: continue save_metadata(metadata, str(config.dest_path / "stats.csv"))
def run(self): # initial broadcast of status to receive updates from neighbor print("Sending initial status block...") self.pm.broadcast(self.status) while not self.is_stopped and self.pm.state is State.STARTED: if not self.pm.recv_queue[0].empty(): new_stat = self.pm.recv_queue[0].get() print("Received status block!") print("Version: %s\nBlock num: %s\n" %(new_stat['data']['ver'], new_stat['data']['blockNumber'])) # TODO: update own status and broadcast if new_stat['data']['genesisHash'] == self.status['genesisHash']: if new_stat['data']['blockNumber'] > self.status['blockNumber']: stat = {"method":"03", "from" : self.status['blockNumber'], "to": new_stat['data']['blockNumber'], "maxBlock": self.status['maxBlock']} self.pm.broadcast(stat) elif new_stat['data']['blockNumber'] < self.status['blockNumber']: to = int(self.status['blockNumber']); fro = int(new_stat['data']['blockNumber']) res = [Database.getBlockByID(i, self.db) for i in range(fro+1, to+1)] index = 0; length = to-fro while index < length: if index+int(new_stat['data']['maxBlock']) < length: result = {"method": "04", "blocks": res[index:]} else: result = {"method": "04", "blocks": res[index:index+int(new_stat['data']['maxBlock'])]} index = index + int(new_stat['data']['maxBlock']) self.pm.send(result, new_stat['nodeID']) gevent.sleep()
def _saveReportInMongoDB(self, sha256): database = Database() count = database.countCodeDB(sha256) # If report available for the file and url -> not insert if count == 0: # GetReport from CodeDB by HTTPS report = self._getCodeDBReport(sha256) # Create a copy of the dictionary. This is done in order to not modify # the original dictionary and possibly compromise the following # reporting modules. report = dict(report) # Store the report and retrieve its object id. database.insertCodeDB(report) log.info("Saved CodeDB-Report %s" % sha256)
def placa(self, client): self.database = Database("vehicles") self.get_all() print() bucle = True while bucle: plate = input("Digite la placa del vehiculo que desea realizar el servicio: ") customer_vehicles = self.database.get_multi_by_property("placa", plate) if type(customer_vehicles) == list and len(customer_vehicles) > 0: client[0].update(customer_vehicles[0]) bucle = False else: print() print("No existe un vehiculo asociado a esta placa. ") print()
def deleteAll(self): """Deletes all reports. """ count = Database().deleteCodeDB() print "*** MongoDB (CodeDB)***" print "deleted documents:" + str(count) print ""
def database(self, action): if action == "create": name = request.forms.get("dbname").replace(" ", "_") if name.endswith(".db"): name = name.replace(".db", "") name = "".join([ letter for letter in name if letter.isalnum() or letter == "_" ]) name = name + ".db" name = name.upper() db = Database(database=name) db.create_base() elif action == "delete": file = request.forms.get("dbtodel") if self._db_exist(file): os.remove(str(os.getcwd()) + "/data/" + file) redirect("/")
def main(): #fntdb = Database() currentBlockNum = Database().getBlockNumber() print('getBlockNumber:', currentBlockNum) if currentBlockNum == 0: genesisBlock = Genesis.genesis() Database().createBlock(genesisBlock) else: while True: #for j in range(3): time.sleep(2) newBlock = Block.block() transactions = [] for i in range(5): pendingTran = Database().getPendingTransaction() print(pendingTran) if pendingTran == {}: print('There is no pending transaction now.') continue else: if not Transaction.verifyTransaction(pendingTran): continue #balance verify and nonce if not Database().verifyBalanceAndNonce(pendingTran): print("verify balance and nonce error") continue if not Database().updateBalanceAndNonce(pendingTran): print("update error") continue newBlock = Block.pushTransactionToArray( newBlock, pendingTran) transactions.append(pendingTran) #print("newBlock:", newBlock) parentBlock = Database().getBlockByID(currentBlockNum - 1) key = '97ddae0f3a25b92268175400149d65d6887b9cefaf28ea2c078e05cdc15a3c0a' #print('parent', parentBlock) newBlock = Block.newBlock_POA(newBlock, parentBlock, key) try: Database().createBlock(newBlock) except: print('Error occurs when saving block into db.') continue #fntdb.updateDBAccountStatus(newBlock) #transactions = newBlock['transaction'] if len(transactions) == 0: continue for transaction in transactions: try: Database().createTransaction(transaction) except: print("Error occurs when saving transaction into db.") continue
def __init__(self): # Datenbank self.__database = Database() # Kofiguration aus der reporting.conf holen self.__cfgReporting = Config(os.path.join(RAGPICKER_ROOT, 'config', 'reporting.conf')) self.__vxcageEnabled = self.__cfgReporting.getOption("vxcage", "enabled") self.__vxcageHost = self.__cfgReporting.getOption("vxcage", "host") self.__vxcagePort = self.__cfgReporting.getOption("vxcage", "port")
def run(self, results, objfile): """Writes report. @param results: analysis results dictionary. @param objfile: file object """ database = Database() # Count query using URL hash and file hash count = database.countRagpickerDB(results["Info"]["file"]["md5"], results["Info"]["url"]["md5"]) # If report available for the file and url -> not insert if count == 0: # Create a copy of the dictionary. This is done in order to not modify # the original dictionary and possibly compromise the following # reporting modules. report = dict(results) # Store the report database.insertRagpickerDB(report) count = database.countFamilyDB(objfile.family.parentObjectSHA256) if count == 0: if objfile.family.unpackedObjectSHA256 != "" or len(objfile.family.siblingObjectsSHA256) > 0: log.info(objfile.family) report = dict(objfile.family.__dict__) database.insertFamily(report)
def store_all_class(kindName: str, className: str, db: database.Database, course): for item in course['aaData']: jx0404id = str(item['jx0404id']) xf = int(item['xf']) dwmc = str(item['dwmc']) jx02id = str(item['jx02id']) xkrs = int(item['xkrs']) zxs = int(item['zxs']) sksj = str(item['sksj']) xxrs = int(item['xxrs']) szkcflmc = str(item['szkcflmc']) syrs = int(item['syrs']) kcmc = str(item['kcmc']) skls = str(item['skls']) skdd = str(item['skdd']) db.course_to_db(jx0404id, xf, dwmc, jx02id, xkrs, zxs, sksj, xxrs, szkcflmc, syrs, kcmc, skls, skdd, kindName, className)
def test_creating_table(self): db = Database("db") age = Field("age") name = Field("name") field_name_map = {"age": age, "name": name} table = db.create_table("customer", field_name_map) self.assertEqual(table != None, True) table.add_field("age", age) table.insert({"age": 12}) data = table.search(["age"]) right_data = [[12]] self.assertEqual( all(data[i][j] == right_data[i][j] for i in range(len(right_data)) for j in range(len(right_data[0]))), True)
def serv(self, client): self.database = Database("service") self.get_all() bucle = True while bucle: service1 = int(input("Digite el codigo del servicio que desea: ")) vehicles_service = self.database.get_multi_by_property("numero", service1) if type(vehicles_service) == list and len(vehicles_service) > 0: client[0].update(vehicles_service[0]) bucle = False else: print() print("No existe un servicio asociado a este codigo. ") print() del client[0]["uid"] self.database = Database("service_asked") self.save(client[0]) self.get_bills(client)
def __init__(self, config): super(Yueri, self).__init__() self.config = config self.log = Logger(config['Logging']) self._logger = self.log.get_logger('Client') self._logger.info('Starting up') self.prefix = config['Client']['prefix'] self.db = Database(self) self.plugin_manager = PluginManager(self) self.influx = Influx(self)
def create_database(self, name): if name in self.__database_names: ## todo log return None self.__database_names.append(name) db = Database(name) self.__database_objs[name] = db ##todo just for test here self.__current_db = db return db
def deleteAll(self): """Deletes all reports. """ # Alle Ragpicker-Daten aus der MongoDB loeschen count = Database().deleteRagpickerDB() print "*** MongoDB (Ragpicker)***" print "deleted documents:" + str(count) print "" count = Database().deleteFamilyDB() print "*** MongoDB (Family)***" print "deleted documents:" + str(count) print "" count = Database().deleteSandboxTaskQueueDB() print "*** MongoDB (SandboxTaskQueue)***" print "deleted documents:" + str(count) print ""
def main(): db_file = os.getenv("db_file") database = Database(db_file) items = Items(database) clients = Clients(database) purchases = Purchases(database) create_tables(database) while True: client_barcodes = [] barcode = input().strip().upper() while barcode_enum(barcode) is BarcodeType.Client: client_barcodes.append(barcode) barcode = input().strip().upper() client_list = [] for client_barcode in client_barcodes: client = clients.get_by_barcode(client_barcode) client_list.append(client) if client else None if not len(client_list): continue print("Clients: {}".format(", ".join( [str(client) for client in client_list]))) product = items.get_by_barcode(barcode) print("Scanned product: {}".format(str(product))) if product: price_per_person = product.price if len(client_list) > 1: price_per_person = ceil( product.price * 20 / len(client_list)) / 20 # ceil with 2 decimals print("Price paid per person: {}".format(str(price_per_person))) for client in client_list: purchase = Purchase.create(product, client, price_per_person) purchases.persist(purchase) client.balance += price_per_person clients.persist(client) print(purchase) product.stock -= 1 items.persist(product) print("Purchase registered") else: print("No item scanned")
def __init__(self): self.totalScore = 0 # sum of scores self.numberScores = 0 # number of scores entered self.processName = multiprocessing.current_process().name self.task = dict() self.cfgPreProcessing = Config( os.path.join(RAGPICKER_ROOT, 'config', 'preProcessing.conf')) self.cfgProcessing = Config( os.path.join(RAGPICKER_ROOT, 'config', 'processing.conf')) self.cfgReporting = Config( os.path.join(RAGPICKER_ROOT, 'config', 'reporting.conf')) self.cfgCrawler = Config( os.path.join(RAGPICKER_ROOT, 'config', 'crawler.conf')) self.database = Database() log.info("INIT " + self.processName)
def relation(self): bucle = True self.database = Database("clients") while bucle: print("Digite s en cualquier momento para salir.") client1 = str( input("Digite el numero de identificación del cliente: ")) if client1.lower() != "s": client = int(client1) client4 = self.database.get_multi_by_property("No ID", client) if type(client4) == list and len(client4) > 0: self.placa(client4) self.serv(client4) self.ciclo(client4) print("Transacción confirmada") bucle = False else: print() print("No existe un cliente asociado a este numero de identificación.") print() else: bucle = False
class Bot(discord.Client): last_activity = "" def on_ready(self): self.database = Database() self.welcome() self.timer() def on_message(self, message): # Commands if message.content.startswith('!addjoke'): parse = re.search(r'\!addjokes (\w+) (.*)', message.content) self.database.addJokes(parse.group(1), parse.group(2)) self.send_message(message.channel, 'Piada adicionada com Sucesso! =)') elif message.content.startswith('!addwelcome'): parse = re.search(r'\!addwelcome (\w+) (.*)', message.content) self.database.addWelcome(parse.group(1), parse.group(2)) self.send_message(message.channel, 'Mensagem de boas vindas adicionada com Sucesso! =)') # Mentions else: for user in message.mentions: if user.name == self.user.name: url = requests.get('http://www.osvigaristas.com.br/frases/engracadas/') parser = bs4.BeautifulSoup(url.text) self.send_message(message.channel, random.choice(parser.select('.quote')).q.string) else: jokes = self.database.listJokes(user.name) self.send_message(message.channel, random.choice(jokes)[2]) def on_member_join(self, member): welcome = self.database.listWelcome(member.name) self.send_message(message.channel, random.choice(welcome)[2]) def notify_activity(self): channel = self.get_channel(config['channel']) rss = feedparser.parse("http://www.romhacking.net.br/atividade/feed/") if self.last_activity != rss.entries[0].link: self.send_message(channel, '**Últimas do Fórum: **' + rss.entries[0].title +' - ' + rss.entries[0].link) self.last_activity = rss.entries[0].link def timer(self): self.clock = task.LoopingCall(self.notify_activity) self.clock.start(config['timeout']) def welcome(self): channel = self.get_channel(config['channel']) self.send_message(channel, config['join_message'])
def updateBlkTrans(self, blockData): for _b in blockData: # verify and create transactions #Database.verifyBalanceAndNonce(_b['transactions'], self.db, "run") if _b: for _t in _b['transaction']: if _t: Database.updateBalanceAndNonce(_t, self.db) else: print("transaction is none!") Database.createTransaction(_b['transaction'], self.db) _b['hash'] = int(_b['hash'],16) else: print("block is none!") Database.createBlock(blockData,self.db)
def __init__(self): self.name = "main" self.prompt_session = PromptSession( 'IoTMap > ', auto_suggest=AutoSuggestFromHistory(), enable_history_search=True, complete_in_thread=True, complete_while_typing=True) self.dc = DBController() self.options = self.get_options() self.contexts = [ Sniffing(self.prompt_session, self.dc, self.options['sniffing']), Database(self.prompt_session, self.dc), Modelling(self.prompt_session, self.dc, self.options['modelling']), ] self.prompt_session.completer = WordCompleter( [ctx.name for ctx in self.contexts] + ['exit', 'help'], ignore_case=True) self.prompt_session.contexts = self.contexts self.prompt_session.path_completer = PathCompleter() self.current_context = self
class Statistics(): def __init__(self): # Datenbank self.__database = Database() # Kofiguration aus der reporting.conf holen self.__cfgReporting = Config(os.path.join(RAGPICKER_ROOT, 'config', 'reporting.conf')) self.__vxcageEnabled = self.__cfgReporting.getOption("vxcage", "enabled") self.__vxcageHost = self.__cfgReporting.getOption("vxcage", "host") self.__vxcagePort = self.__cfgReporting.getOption("vxcage", "port") def runStatisticsLong(self): #Pruefen ob VxCage und MongoDB aktiviert sind if self.__database.isRagpickerDBEnabled(): if self.__vxcageEnabled: self.__runStatisticsMongodbLong() if self.__database.isCodeDBEnabled(): self.__runStatisticsCodedb() else: print("vxcage in reporting.conf is not enabled") sys.stdout.flush() else: print("mongodb in reporting.conf is not enabled") sys.stdout.flush() def runStatisticsShort(self): #Pruefen ob VxCage und MongoDB aktiviert sind if self.__database.isRagpickerDBEnabled(): if self.__vxcageEnabled: self.__runStatisticsMongodbShort() if self.__database.isCodeDBEnabled(): self.__runStatisticsCodedb() else: print("vxcage in reporting.conf is not enabled") sys.stdout.flush() else: print("mongodb in reporting.conf is not enabled") sys.stdout.flush() def runStatisticsAV(self): #Pruefen ob VxCage und MongoDB aktiviert sind if self.__database.isRagpickerDBEnabled(): if self.__vxcageEnabled: self.__runStatisticsAV() else: print("vxcage in reporting.conf is not enabled") sys.stdout.flush() else: print("mongodb in reporting.conf is not enabled") sys.stdout.flush() def __runStatisticsMongodbLong(self): print "**************************************" print "*** Statistics MongoDB (Ragpicker) ***" print "**************************************" print "" print "Number of malware samples in database:", self.__database.countReportsRagpickerDB() print "" #Statistiken der eingesetzten AV-Produkte self.__runStatisticsAVProducts() #Liste der letzen 20 Samples, die weder auf VT noch von einem lokalen AV gefunden wurden self.__runStatisticsLast20SamplesNotFoundByAV() #Liste der letzen 20 Samples, die nicht auf VT gefunden wurden self.__runStatisticsLast20SamplesNotFoundByVT() #Liste der letzen 20 Samples, die nicht von einem lokalen AV-Produkt gefunden wurden self.__runStatisticsLast20SamplesNotFoundByLocalAV() #Liste und Haeufigkeit der Filetypes self.__runStatisticsFiletypes() #Haeufigkeit der PE Charakteristiken self.__runStatisticsPeCharacteristics() #Liste und Haeufigkeit der verwendeten Packer/Compiler in der Malware self.__runStatisticsPackerCompiler() #Liste der verwendeten digitalen Signaturen self.__runStatisticsPackerSignatures() sys.stdout.flush() def __runStatisticsMongodbShort(self): print "**************************************" print "*** Statistics MongoDB (Ragpicker) ***" print "**************************************" print "" print "Number of malware samples in database:", self.__database.countReportsRagpickerDB() print "" #Liste und Haeufigkeit der Filetypes self.__runStatisticsFiletypes() #Haeufigkeit der PE Charakteristiken self.__runStatisticsPeCharacteristics() sys.stdout.flush() def __runStatisticsAV(self): print "**************************************" print "*** Statistics MongoDB (Ragpicker) ***" print "**************************************" print "" print "Number of malware samples in database:", self.__database.countReportsRagpickerDB() print "" #Statistiken der eingesetzten AV-Produkte self.__runStatisticsAVProducts() #Liste der letzen 20 Samples, die weder auf VT noch von einem lokalen AV gefunden wurden self.__runStatisticsLast20SamplesNotFoundByAV() #Liste der letzen 20 Samples, die nicht auf VT gefunden wurden self.__runStatisticsLast20SamplesNotFoundByVT() #Liste der letzen 20 Samples, die nicht von einem lokalen AV-Produkt gefunden wurden self.__runStatisticsLast20SamplesNotFoundByLocalAV() sys.stdout.flush() def __runStatisticsFiletypes(self): #Liste und Haeufigkeit der Filetypes print "Filetypes of malware" res = self.__database.getFiletypes() table = PrettyTable(["filetype", "count"]) table.align["filetype"] = "l" table.align["count"] = "c" table.padding_width = 1 try: for values in res['result']: if values.get("_id"): outputPacker = values.get("_id") outputCount = str(values.get("count")) table.add_row([outputPacker, outputCount]) print(table) except KeyError: raise Exception("Dict has no key 'result' ") print "" def __runStatisticsPeCharacteristics(self): #Haeufigkeit der PE Charakteristiken print "PE-Characteristics of malware" peC = self.__database.getStatisticsPeCharacteristics() table = PrettyTable(["pe-characteristics", "count"]) table.align["pe-characteristics"] = "l" table.align["count"] = "c" table.padding_width = 1 table.add_row(["EXE", peC.get("exe")]) table.add_row(["DLL", peC.get("dll")]) table.add_row(["Driver", peC.get("driver")]) table.add_row(["DLL/Driver", peC.get("dllDriver")]) table.add_row(["No PE File", peC.get("noPe")]) print (table) print "" def __runStatisticsPackerCompiler(self): #Liste und Haeufigkeit der verwendeten Packer/Compiler in der Malware print "Packer/compiler used in malware" res = self.__database.getStatisticsPackerCompiler() table = PrettyTable(["packer/compiler", "count"]) table.align["packer/compiler"] = "l" table.align["count"] = "c" table.padding_width = 1 try: for values in res['result']: if values.get("_id"): outputPacker = values.get("_id")[0] outputCount = str(values.get("count")) table.add_row([outputPacker, outputCount]) print(table) except KeyError: raise Exception("Dict has no key 'result' ") print " " def __runStatisticsPackerSignatures(self): #Liste der verwendeten digitalen Signaturen print "Signatures used by malware" res = self.__database.getStatisticsPackerSignatures() table = PrettyTable(["publisher", "issuer", "count"]) table.align["publisher"] = "l" table.align["issuer"] = "l" table.align["count"] = "c" table.padding_width = 1 try: for values in res['result']: if values.get("_id"): outputPublisher = values.get("_id").get("PublisherO") if values.get("_id").get("Issuer"): outputIssuer = values.get("_id").get("Issuer") else: outputIssuer = " " outputCount = str(values.get("count")) table.add_row([outputPublisher, outputIssuer, outputCount]) print(table) except KeyError: raise Exception("Dict has no key 'result' ") print "" def __runStatisticsLast20SamplesNotFoundByAV(self): #Liste der letzen 20 Samples, die weder auf VT noch von einem lokalen AV gefunden wurden print "Last 20 samples not found by VirusTotal and local AV-Products" res = sorted(self.__database.getSamplesNotFoundByAV(), reverse=True) table = PrettyTable(["timestamp of crawling", "sha256"]) table.align["timestamp of crawling"] = "c" table.align["sha256"] = "c" table.padding_width = 1 try: for values in res: sha256 = values.get("Info").get("file").get("sha256") timestamp = values.get("Info").get("analyse").get("started") table.add_row([timestamp, sha256]) print(table.get_string(start=0, end=20)) except KeyError: raise Exception("Dict has no key 'Info' ") print "" def __runStatisticsLast20SamplesNotFoundByVT(self): #Liste der letzen 20 Samples, die nicht auf VirusTotal gefunden wurden print "Last 20 samples not found by VirusTotal" res = sorted(self.__database.getSamplesNotFoundByVT(), reverse=True) table = PrettyTable(["timestamp of crawling", "sha256"]) table.align["timestamp of crawling"] = "c" table.align["sha256"] = "c" table.padding_width = 1 try: for values in res: sha256 = values.get("Info").get("file").get("sha256") timestamp = values.get("Info").get("analyse").get("started") table.add_row([timestamp, sha256]) print(table.get_string(start=0, end=20)) except KeyError: raise Exception("Dict has no key 'Info' ") print "" def __runStatisticsLast20SamplesNotFoundByLocalAV(self): #Liste der letzen 20 Samples, die nicht von einem lokalen AV-Produkt gefunden wurden print "Last 20 samples not found by local AV-Products" res = sorted(self.__database.getSamplesNotFoundByLocalAV(), reverse=True) table = PrettyTable(["timestamp of crawling", "sha256"]) table.align["timestamp of crawling"] = "c" table.align["sha256"] = "c" table.padding_width = 1 try: for values in res: sha256 = values.get("Info").get("file").get("sha256") timestamp = values.get("Info").get("analyse").get("started") table.add_row([timestamp, sha256]) print(table.get_string(start=0, end=20)) except KeyError: raise Exception("Dict has no key 'Info' ") print "" def __runStatisticsAVProducts(self): #Statistiken der eingesetzten AV-Produkte #VirusTotal und lokale AV-Produkte print "VirusTotal and local AV-Products" print " Samples rated as none-malware by all AV-Products at time of crawling:", \ self.__database.getStatisticsNoneMalwareByAV() print "" #VirusTotal ret = self.__database.getStatisticsVirusTotal() print "VirusTotal" print " Samples analyzed at time of crawling:", ret.get("analyzed") print " Samples not analyzed at time of crawling:", ret.get("notAnalyzed") print " Samples found at time of crawling:", ret.get("samplesFound") print " Samples not found at time of crawling:", ret.get("SamplesNotFound") print "" #Lokale AV-Produkte print "Local AV-Products" print " analyzed => Samples analyzed at time of crawling" print " not analyzed => Samples not analyzed at time of crawling" print " malware => Samples rated as malware at time of crawling" print " none-malware => Samples rated as none-malware at time of crawling" table = PrettyTable(["product", "analyzed", "not analyzed", "malware", "none-malware", "detection rate"]) table.align["product"] = "l" table.align["analyzed"] = "r" table.align["not analyzed"] = "r" table.align["malware"] = "r" table.align["none-malware"] = "r" table.align["detection rate"] = "r" table.padding_width = 1 # Statistik Daten holen ret = self.__database.getStatisticsAntivirus() # Table-Body zusammenbauen for av in ret: table.add_row([av.get("product"), av.get("analyzed"), av.get("notanalyzed"), av.get("malware"), av.get("nonemalware"), av.get("rate")]) print(table) print ""
import graphene from graphene import resolve_only_args from core.database import Database from core.schemas.encounter import Encounter from core.schemas.facility import Facility from core.schemas.obs import Obs from core.schemas.patient_identifier import PatientIdentifier from core.schemas.person_address import PersonAddress from core.schemas.person_attribute import PersonAttribute from core.schemas.person_name import PersonName db = Database() class Patient(graphene.ObjectType): def __init__(self, **entries): self.__dict__.update(entries) id = graphene.ID() gender = graphene.String() birthdate = graphene.String() birthdate_estimated = graphene.String() dead = graphene.String() death_date = graphene.String() cause_of_death = graphene.String() creator = graphene.String() date_created = graphene.String() changed_by = graphene.String() date_changed = graphene.String()
def on_ready(self): self.database = Database() self.welcome() self.timer()
def __init__(self, bot): super().__init__(bot) db_user = getenv('DB_USER') db_passwd = getenv('DB_PASSWORD') self.db = Database(db_user, db_passwd) self.db.cur.execute("USE nextbot;")
from datetime import datetime from random import choice from core.ffmpeg import vidmark, take_screen_shot from core.clean import delete_all, delete_trash from pyrogram import Client, filters from configs import Config from core.database import Database from core.display_progress import progress_for_pyrogram, humanbytes from humanfriendly import format_timespan from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery from pyrogram.errors import InputUserDeactivated, UserIsBlocked from pyrogram.errors.exceptions.flood_420 import FloodWait from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant, UsernameNotOccupied, ChatAdminRequired, PeerIdInvalid, MessageNotModified AHBot = Client(Config.BOT_USERNAME, bot_token=Config.BOT_TOKEN, api_id=Config.API_ID, api_hash=Config.API_HASH) db = Database(Config.DATABASE_URL, Config.BOT_USERNAME) broadcast_ids = {} async def send_msg(user_id, message): try: await message.forward(chat_id=user_id) return 200, None except FloodWait as e: await asyncio.sleep(e.x) return send_msg(user_id, message) except InputUserDeactivated: return 400, f"{user_id} : deactivated\n" except UserIsBlocked: return 400, f"{user_id} : blocked the bot\n" except PeerIdInvalid: return 400, f"{user_id} : user id invalid\n"
headers = {"Authorization" : "Basic %s" % base64.encodestring("%s:%s" % (config.get("user"), config.get("password"))).replace('\n', '')} data = dict(sha256=sha256, tags=tags) h = httplib2.Http(".cache", disable_ssl_certificate_validation=True) response, content = h.request(CODE_DB_URL_TAG % (config.get("host"), config.get("port")), "POST", body=urlencode(data), headers=headers) if not "'status': '200'" in str(response) : log.error("%s --> %s = %s" % (sha256, tags, str(content))) data = json.loads(content) log.info("%s --> %s = %s" % (sha256, tags, data.get("Status"))) if __name__ == '__main__': # Datenbank database = Database() # VxCage-Handler vxCage = VxCageHandler() vxcageEnabled = cfgReporting.getOption("vxcage", "enabled") parser = argparse.ArgumentParser(description='Ragpicker Manager') subparsers = parser.add_subparsers(title='subcommands', description='valid subcommands', help='additional help') parser_stop = subparsers.add_parser('stop', help='Stops a running Ragpicker instance') parser_stop.set_defaults(which='stop') parser_export = subparsers.add_parser('export', help='Export Ragpicker-Data') parser_export.set_defaults(which='export') parser_export.add_argument('-d','--dirname', required=True, help='Export-Directory') parser_export.add_argument('-f','--sha256_file', required=True, help='SHA256-File') parser_export.add_argument('--json', default=False, help='File in json-format? Default=False') parser_vxcage = subparsers.add_parser('vxcage', help='Exports only the malware files from the VxCage') parser_vxcage.set_defaults(which='vxcage')
# # This program is free software and it's distributed under the terms of # the Creative Commons Attribution-ShareAlike 4.0 International License. # # For more details, see the toplevel file COPYING or # http://creativecommons.org/licenses/by-sa/4.0/ # # Authors: # Eugenio "g7" Paolantonio <*****@*****.**> # import core.database from core.database import Database, OrCondition, AndCondition, AttributeEqualCondition, EqualCondition db = Database("/home/g7/tesina/src/database.db") db.select( ["Accounts", "ServerType"], attributes=["Accounts.Name", "ServerType.Type"], conditions=OrCondition( AttributeEqualCondition("Accounts.Type", "ServerType.ID"), EqualCondition("Accounts.Username", "g7") ) ) db.select( ["Tabella1", "Tabella2"], attributes=["Column1", "Column2", "Column3"], conditions=core.database.AndCondition( core.database.AttributeEqualCondition("Tabella2.ID_Tabella1", "Tabella1.ID"),
def __init__(self): load_dotenv() Database().connect()
def run(self, objfile): self.key = "BlueCoatMAA" self.score = -1 host = self.options.get("host") port = self.options.get("port") timeout = self.options.get("timeout", 120) apikey = self.options.get("apikey") owner = self.options.get("user") https = self.options.get("https") database = Database() returnValue = {} if not host or not port or not apikey or not owner: raise Exception("BlueCoatMAA is not configured correctly") try: fileName = objfile.file.get_fileSha256() file_data = objfile.file.file_data message = MultiPartForm() message.add_file_data('unused', filename=fileName, file_data=file_data, mimetype='application/octet-stream') message.add_field('owner', owner) headers = {'Content-type': message.get_content_type()} h = httplib2.Http() protocol = "http" if https: protocol = "https" h = httplib2.Http(".cache", disable_ssl_certificate_validation=True) response, content = h.request('%s://%s:%s/rapi/samples/basic?token=%s' % (protocol, host, port, apikey), "PUT", body=message.toBlueCoatString(), headers=headers) if not "'status': '200'" in str(response) : log.error(str(content)) raise Exception(str(content)) data = json.loads(content) sample_id = data['results'][0]['samples_sample_id'] log.info("%s upload as new sample_id %d" % (fileName, sample_id)) headers = {'Content-Type': 'application/x-www-form-urlencoded'} parameters = {} parameters["sample_id"] = sample_id parameters["env"] = 'ivm' parameters["log_task"] = 1 parameters["tp_IVM.TIMEOUT"] = timeout response, content = h.request('%s://%s:%s/rapi/tasks?token=%s' % (protocol, host, port, apikey), 'PUT', body=urllib.urlencode(parameters), headers=headers) if not "'status': '200'" in str(response) : log.error(str(content)) raise Exception(str(content)) data = json.loads(content) task_id = data['results'][0]['tasks_task_id'] log.info("new task_id %d" % task_id) returnValue = {"sample_id":sample_id, "task_id":task_id} #Insert Task-State-Report database.insertSandboxTaskStatus(sandboxName=MAA_SANDBOX_NAME, sha256=objfile.file.get_fileSha256(), taskID=task_id, sampleID=sample_id, taskState=MAA_TASK_STATE_START) except Exception as e: raise Exception("Failed to send the file to the BlueCoatMAA: %s" % e) return returnValue