示例#1
0
 def test_blackbox_header_fields_malconv(self):
     black_box_attack = CBlackBoxHeaderFieldsEvasionProblem(
         CEnd2EndWrapperPhi(self.end2end_classifier),
         iterations=2,
         population_size=2)
     engine = CGeneticAlgorithm(black_box_attack)
     y_pred, _, _, _ = engine.run(self.X, self.Y)
     self.assert_evasion_result(y_pred)
示例#2
0
 def test_blackbox_dos_header_malconv(self):
     black_box_attack = CBlackBoxHeaderEvasionProblem(CEnd2EndWrapperPhi(
         self.end2end_classifier),
                                                      optimize_all_dos=True,
                                                      iterations=5,
                                                      population_size=10)
     engine = CGeneticAlgorithm(black_box_attack)
     y_pred, _, _, _ = engine.run(self.X, self.Y)
     self.assert_evasion_result(y_pred)
示例#3
0
 def test_blackbox_padding_malconv(self):
     black_box_attack = CBlackBoxPaddingEvasionProblem(
         CEnd2EndWrapperPhi(self.end2end_classifier),
         how_many_padding_bytes=1024,
         iterations=5,
         population_size=10)
     engine = CGeneticAlgorithm(black_box_attack)
     y_pred, _, _, _ = engine.run(self.X, self.Y)
     self.assert_evasion_result(y_pred)
示例#4
0
 def test_blackbox_format_exploit_malconv(self):
     black_box_attack = CBlackBoxFormatExploitEvasionProblem(
         CEnd2EndWrapperPhi(self.end2end_classifier),
         preferable_extension_amount=0x200,
         pe_header_extension=0,
         iterations=5,
         population_size=10)
     engine = CGeneticAlgorithm(black_box_attack)
     y_pred, _, _, _ = engine.run(self.X, self.Y)
     self.assert_evasion_result(y_pred)
示例#5
0
 def test_blackbox_gamma_ember(self):
     section_population, _ = CGammaEvasionProblem.create_section_population_from_folder(
         self.goodware_folder, 100)
     gamma = CGammaEvasionProblem(section_population,
                                  CEmberWrapperPhi(self.ember_classifier),
                                  population_size=10,
                                  penalty_regularizer=1e-6,
                                  iterations=5)
     engine = CGeneticAlgorithm(gamma)
     y_pred, _, _, _ = engine.run(self.X, self.Y)
     self.assert_evasion_result(y_pred)
示例#6
0
def blackbox_attack(output_path=None):
	engine = CGeneticAlgorithm(global_state.attack)
	stats = _create_stats()
	for fp in global_state.data_paths:
		with open(fp, 'rb') as handle:
			code = handle.read()
		x = CArray(np.frombuffer(code, dtype=np.uint8)).atleast_2d()
		y = CArray([1])
		try:
			adv_ds = _perform_optimization(engine, fp, stats, x, y)
			if output_path is not None:
				name = os.path.basename(fp)
				new_path = os.path.join(output_path, name + '_adv')
				engine.write_adv_to_file(adv_ds.X[0, :], path=new_path)
				success_prompt(f'Adv malware created at {new_path}')

		except Exception as e:
			crash_prompt("Damn, something went wrong!")
			crash_prompt(f"Exception details: {e}")
			raise e

	print_run_results(stats)