def test_run_zipextractor(self): conf = WhatTheFileConfiguration() output_safe_directory = "./tests/examples/safe_directory" conf.parse_string(""" [whatthefile] modules_package = src.modules safe_output_path = """ + output_safe_directory + """ output = list log_output = stdout [module.zipextractor] active = true """) final_file = os.path.abspath(output_safe_directory) + \ "/1/zipextractor/" + \ os.path.abspath("./tests/examples/collie.jpg.zip/collie.jpg").replace(":", "") final_file = os.path.abspath(final_file) if os.path.exists(final_file): os.remove(final_file) self._remove_test_folders(output_safe_directory) self.assertFalse(os.path.exists(final_file)) path = "./tests/examples/collie.jpg.zip" output = OutputFactory.get_output_by_conf(conf) core = Core(conf, output) core.run(path) self.assertTrue(os.path.exists(final_file)) paths = [] for element in output.get_list(): paths.append(element["path"]) self.assertTrue(os.path.abspath(final_file) in paths) os.remove(final_file) self._remove_test_folders(output_safe_directory)
def test_post_decrement_a(): warrior = Warrior(processes=[0]) core = Core(data=[MOV('I', '}', 1, '$', 1), DAT('F', '$', 0, '$', 0)]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert core[1].a_value() == 0 assert core[1].b_value() == 0
def test_sub_x(): warrior = Warrior(processes=[0]) core = Core(data=[SUB('X', '#', '3', '$', '1'), DAT('F', '$', 2, '$', -5)]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() instruction = game.core()[1] assert instruction.a_value() == 1 assert instruction.b_value() == -8
def test_sub_typical(): warrior = Warrior(processes=[0]) core = Core( data=[SUB('AB', '#', '3', '$', '1'), DAT('F', '$', 1, '$', -5)]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert game.core()[1].b_value() == -8
def __init__(self): self.config = Config() self.core = Core() self.logs = Logs() self.database = Database() self.data = {} # Data assets self.running = True
def a_test_run_all(self): conf = WhatTheFileConfiguration() conf.parse_dict({ "whatthefile": { "modules_package": "src.modules", "output": "list", "log_output": "stdout", "safe_output_path": "./tests/examples/safe_directory" }, "module.commentextractor": { "active": True }, "module.entropy": { "active": True }, "module.hashes": { "active": True, 'hashes_to_calculate': "MD5,SHA1,SHA256" }, "module.imagerecognitiontensorflow": { "active": True }, "module.metadata": { "active": True }, "module.ocrtesseract": { "active": True }, "module.qrbcreader": { "active": True }, "module.strings": { "active": True, "char_min": 4 }, "module.virustotal": { "active": True }, "module.zipextractor": { "active": True }, "module.tikaparser": { "active": True }, "module.certificatereader": { "active": True }, "module.browserhisstory": { "active": True } }) path = "./tests/examples/collie.jpg" output = OutputFactory.get_output_by_conf(conf) core = Core(conf, output) core.run(path) self.assertEqual( "collie" in output.get_list()[0]["imagerecognitiontensorflow"])
def startPushButtonEvent(self): if self.working == False: toCheck = [] additional = False if self.ip_v4CheckBox.isChecked(): toCheck.append("ipv4") if self.ip_v6CheckBox.isChecked(): toCheck.append("ipv6") if self.socialSecNoCheckBox.isChecked(): toCheck.append("socialsec") if self.idNoCheckBox.isChecked(): toCheck.append("id_number") if self.macCheckButton.isChecked(): toCheck.append("mac") if self.domainsCheckBox.isChecked(): toCheck.append("domain") if self.emailsCheckBox.isChecked(): toCheck.append("email") if self.passwdsCheckBox.isChecked(): toCheck.append("password") if self.loginsCheckBox.isChecked(): toCheck.append("login") if self.phoneNoCheckBox.isChecked(): toCheck.append("phone_number") if self.additionalCheckBox.isChecked(): additional = True dictPath = None if self.dictCheckBox.isChecked(): dictPath = self.dictPathLineEdit.text() self.progressValue = 0 self.progressBar.setValue(self.progressValue) self.working = True if self.outPathLineEdit.text() == '': inPath = self.inPathLineEdit.text() self.outPathLineEdit.setText( os.path.splitext(inPath)[0] + "_output.json") try: self.core = Core(self.inPathLineEdit.text(), self.outPathLineEdit.text(), expectedRegexes=toCheck, data=self.data, additional=additional, progressEvent=self.progressBarEvent, finishedEvent=self.finishedDataEvent, dictionaryPath=dictPath) except Exception as x: self.displayException(x) self.stopPushButtonEvent() return self.core.start()
def test_mod_zero(): warrior = Warrior(processes=[0]) core = Core(data=[ MOD('I', '$', 1, '$', 2), DAT('F', '$', 0, '$', 0), DAT('F', '$', 0, '$', 0) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert len(warrior.processes()) == 0
def test_seq_i_no(): warrior = Warrior(processes=[0]) core = Core(data=[ SEQ('I', '$', 1, '$', 2), JMP('F', '$', 2, '$', 4), DAT('F', '$', 2, '$', 4) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert warrior.processes()[0] == 1
def test_djn_f_not_zero(): warrior = Warrior(processes=[0]) core = Core(data=[ DJN('B', '$', 2, '$', 0), DAT('F', '$', 0, '$', 1), DAT('F', '$', 0, '$', 1) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert warrior.processes() == [2]
def test_spl_typical(): warrior = Warrior(processes=[0]) core = Core(data=[ SPL('F', '$', 2, '$', 2), DAT('F', '$', 0, '$', 0), DAT('F', '$', 0, '$', 0) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert warrior.processes() == [1, 2]
def test_core_add_cycle_begin_two_times(): warrior = Warrior(processes=[1]) core = Core(data=[ DAT('F', '$', 1, '$', 5), ADD('AB', '#', '3', '$', '-5'), DAT('F', '$', 1, '$', -5) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert game.core()[2].b_value() == -2
def test_jmp_typical(): warrior = Warrior(processes=[2]) core = Core(data=[ DAT('F', '$', 1, '$', -5), DAT('F', '$', 1, '$', -5), JMP('B', '$', -1, '$', 0) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert game.warriors()[0].processes()[0] == 1
def run(self, arguments): if len(arguments) != 3: Console.print_help(arguments) sys.exit() else: conf = WhatTheFileConfiguration() conf.parse_file(arguments[1]) output = OutputFactory.get_output_by_conf(conf) core = Core(conf, output) core.run(arguments[2])
def __init__(self): self.root = Tk() self.actions = Action(root=self.root) self.cores = Core() self.screensize = "400x600" # default screen size self.filename = "" self.savepath = "" self.tabs = None
def test_mov_x(): warrior = Warrior(processes=[0]) core = Core(data=[ MOV('X', '$', '1', '$', '2'), DAT('F', '$', 1, '$', 7), DAT('F', '$', 0, '$', 0) ]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert game.core()[2].a_value() == 7 assert game.core()[2].b_value() == 1
def test_run_hashes(self): conf = WhatTheFileConfiguration() conf.parse_dict({ "whatthefile": { "modules_package": "src.modules", "output": "list", "log_output": "stdout", "safe_output_path": "./tests/examples/safe_directory" }, "module.commentextractor": { "active": True }, "module.entropy": { "active": False }, "module.hashes": { "active": True, 'hashes_to_calculate': "MD5,SHA1,SHA256" }, "module.imagerecognitiontensorflow": { "active": False }, "module.metadata": { "active": False }, "module.ocrtesseract": { "active": False }, "module.qrbcreader": { "active": False }, "module.strings": { "active": False, "char_min": 10 }, "module.virustotal": { "active": False }, "module.zipextractor": { "active": False } }) path = "./tests/examples/collie.jpg.zip" output = OutputFactory.get_output_by_conf(conf) core = Core(conf, output) core.run(path) self.assertTrue("SHA256" in output.get_list()[0]["hashes"]) self.assertTrue("start_module" in output.get_list()[0]["hashes"]) self.assertTrue("end_module" in output.get_list()[0]["hashes"]) self.assertTrue("begin_analysis" in output.get_list()[0]) self.assertTrue("end_analysis" in output.get_list()[0])
def test_run_directory(self): conf = WhatTheFileConfiguration() conf.parse_dict({ "whatthefile": { "modules_package": "src.modules", "output": "list", "log_output": "stdout", "safe_output_path": "./tests/examples/safe_directory" }, "module.commentextractor": { "active": True }, "module.entropy": { "active": True }, "module.hashes": { "active": True, 'hashes_to_calculate': "MD5,SHA1,SHA256" }, "module.imagerecognitiontensorflow": { "active": True }, "module.metadata": { "active": True }, "module.ocrtesseract": { "active": True }, "module.qrbcreader": { "active": True }, "module.strings": { "active": True, "char_min": 4 }, "module.virustotal": { "active": False }, "module.zipextractor": { "active": True } }) path = "./tests/examples/testdirectorydonotinsertmoreitems" output = OutputFactory.get_output_by_conf(conf) core = Core(conf, output) core.run(path) self.assertEqual(len(output.get_list()), 3)
def test_ignore(self): conf = WhatTheFileConfiguration() conf.parse_dict({ "whatthefile": { "modules_package": "src.modules", "output": "list", "log_output": "stdout", "safe_output_path": "./tests/examples/safe_directory" }, "module.hashes": { "active": True, 'hashes_to_calculate': "MD5,SHA1,SHA256" }, "module.ignore": { "active": True, 'file_hashes_md5_to_ignore': './tests/examples/ignoredhashesmd5.txt' }, "module.imagerecognitiontensorflow": { "active": False }, "module.metadata": { "active": False }, "module.ocrtesseract": { "active": False }, "module.qrbcreader": { "active": False }, "module.strings": { "active": True, "char_min": 10 }, "module.virustotal": { "active": False }, "module.zipextractor": { "active": False } }) path = "./tests/examples/collie.jpg" output = OutputFactory.get_output_by_conf(conf) core = Core(conf, output) core.run(path) self.assertEqual(len(output.get_list()), 0)
def __init__(self, warriors, core=None, core_size=8000, init_warriors=True, gui=None, number=0, max_cycles=80000): """ Round constructor :param warriors: Required warriors list :param core: Optional core for testing purposes :param core_size: Other core size than default :param init_warriors: Execute init_warriors() for testing purposes """ self._core = core if core else Core(core_size, gui=gui) self._warriors = warriors if gui: self._gui = gui self._gui.init_game_screen() else: self._gui = MockGUI(core_size) if init_warriors: self.init_warriors() self._number = number self._cycles = 0 self._max_cycles = max_cycles
def test_zipextractor_unzip_with_zip_inside(self): output_safe_directory = "./tests/examples/safe_directory" final_file = os.path.abspath(output_safe_directory) + \ "/2/zipextractor/" + \ os.path.abspath(output_safe_directory).replace(":", "") + \ "/1/zipextractor/" + \ os.path.abspath("./tests/examples/folderzip.zip/folderzip/Surprisezip.txt.zip/Surprisezip.txt").replace(":", "") final_file = os.path.abspath(final_file) temporal_zip = os.path.abspath(output_safe_directory) + \ "/1/zipextractor/" + \ os.path.abspath("./tests/examples/folderzip.zip/folderzip/Surprisezip.txt.zip").replace(":", "") temporal_zip = os.path.abspath(temporal_zip) conf = WhatTheFileConfiguration() conf.parse_string(""" [whatthefile] modules_package = src.modules safe_output_path = """ + output_safe_directory + """ output = list log_output = stdout [module.zipextractor] active = true """) if os.path.exists(final_file): os.remove(final_file) self._remove_test_folders(output_safe_directory) self.assertFalse(os.path.exists(final_file)) path = "./tests/examples/folderzip.zip" output = OutputFactory.get_output_by_conf(conf) core = Core(conf, output) core.run(path) paths = [] for element in output.get_list(): paths.append(os.path.abspath(element["path"])) self.assertTrue(temporal_zip in paths) self._remove_test_folders(output_safe_directory)
def importRoutes(rootpath, app, config_object: Config): """Add user routes to app.""" conf = WhatTheFileConfiguration() conf.parse_file(config_object.WHATTHEFILECONFIGFILE) output = ListOutput() core = Core(conf, output) @app.route(rootpath, methods=['GET', 'POST']) def index_or_upload_file(): if request.method == 'GET': return send_file("pages/index.html", mimetype='text/html') else: if 'fileToUpload' not in request.files: abort(404) else: file = request.files['fileToUpload'] binary = file.read() if len(binary) != 0: path = _write_file(config_object, binary, os.path.basename(file.filename)) output.get_list().clear() core.run(path) _remove_file(path) core.clean_safe_output_path() result = output.get_list() remove_internal_info(result) return Response(json.dumps(result, default=str), 200, mimetype='application/json') else: return Response(json.dumps({"error": "invalid file"}, default=str), 400, mimetype='application/json') @app.route(rootpath + "favicon.ico", methods=['GET']) def get_favicon(): return send_file("images/favicon.png", mimetype='image/png')
""" Modules stucture Activator - check that this plugin should be activated Requester - gwts request and processed it, returns response `future` object Responser - returns data to user """ from src.core import Core if __name__ == "__main__": config_path = '../config.yaml' core = Core(config_path) core.run()
import argparse # LOCALHOST = '127.0.0.1' # # parser = argparse.ArgumentParser() # parser.add_argument('config', help='Config', nargs='?') # parser.add_argument('--client', help='Client mode', action='store_true') # parser.add_argument('--bind-address', help='IP address to bind to', default=LOCALHOST) # options = parser.parse_args() # # print(options) from src.core import Core from src.utils.registry import get_registry core = Core(config_directory='./data') print(get_registry().crops) print(get_registry().configs.to_dict())
def __init__(self, root=None): self.root = root self.cores = Core() self.filetypes = [("All files", "*"), ("Text file", "*.txt")]
def init_server(): core = Core() core.run()
def test_core16_with_ht(self): expected = str(2**30) core = Core(total_num=16, index=15, hyper_threading=True) mask = core.affinity_mask self.assertEqual(expected, mask)
def test_get_cycled_value_begin(): instruction_1 = DAT('F', '$', 1, '$', 5) instruction_2 = ADD('AB', '#', '3', '$', '-2') instruction_3 = DAT('F', '$', 1, '$', -5) core = Core(data=[instruction_1, instruction_2, instruction_3]) assert core[-5] == instruction_2
def test_no_hyperthreading_core_2(self): result = Core(total_num=12, index=1, hyper_threading=False) self.assertEqual(2, result.friendly_number)
def test_core_postincrement_b(): warrior = Warrior(processes=[0]) core = Core(data=[DAT('F', '>', 1, '$', 1), DAT('F', '$', 0, '$', 0)]) game = Round(core=core, warriors=[warrior], init_warriors=False) game.simulation_step() assert game.core()[1].b_value() == 1