secml_malware.attack.blackbox package

Subpackages

Submodules

secml_malware.attack.blackbox.c_black_box_format_exploit_evasion module

class secml_malware.attack.blackbox.c_black_box_format_exploit_evasion.CBlackBoxFormatExploitEvasionProblem(model_wrapper: secml_malware.attack.blackbox.c_wrapper_phi.CWrapperPhi, population_size: int, preferable_extension_amount: int = 512, pe_header_extension: int = 512, iterations: int = 100, is_debug: bool = False, penalty_regularizer: float = 0, invalid_value: int = 256)

Bases: secml_malware.attack.blackbox.c_blackbox_problem.CBlackBoxProblem

apply_feasible_manipulations(t, x: secml.array.c_array.CArray) secml.array.c_array.CArray

Apply the format exploit practical manipulation on the input sample

Parameters
  • t (CArray) – the vector of manipulations in [0,1]

  • x (CArray) – the input space sample to perturb

Returns

the adversarial malware

Return type

CArray

init_starting_point(x: secml.array.c_array.CArray) secml.array.c_array.CArray

Initialize the problem, by setting the starting point.

Parameters

x (CArray) – the initial point

Returns

the initial point (padded accordingly to remove trailing invalid values)

Return type

CArray

secml_malware.attack.blackbox.c_black_box_padding_evasion module

class secml_malware.attack.blackbox.c_black_box_padding_evasion.CBlackBoxPaddingEvasionProblem(model_wrapper: secml_malware.attack.blackbox.c_wrapper_phi.CWrapperPhi, population_size: int, how_many_padding_bytes: int, iterations: int = 100, is_debug: bool = False, penalty_regularizer: float = 0, invalid_value: int = 256)

Bases: secml_malware.attack.blackbox.c_blackbox_problem.CBlackBoxProblem

Padding black-box problem

apply_feasible_manipulations(t, x: secml.array.c_array.CArray) secml.array.c_array.CArray

Apply the padding practical manipulation on the input sample :param t: the vector of manipulations in [0,1] :type t: CArray :param x: the input space sample to perturb :type x: CArray

Returns

the adversarial malware

Return type

CArray

secml_malware.attack.blackbox.c_blackbox_header_problem module

class secml_malware.attack.blackbox.c_blackbox_header_problem.CBlackBoxHeaderEvasionProblem(model_wrapper: secml_malware.attack.blackbox.c_wrapper_phi.CWrapperPhi, population_size: int, optimize_all_dos: bool = False, iterations: int = 100, is_debug: bool = False, penalty_regularizer: float = 0, invalid_value: int = 256)

Bases: secml_malware.attack.blackbox.c_blackbox_problem.CBlackBoxProblem

Blackbox attacks that perturbs the DOS header (partially or fully)

apply_feasible_manipulations(t: numpy.ndarray, x: secml.array.c_array.CArray) secml.array.c_array.CArray

Apply the partial / full DOS practical manipulation

Parameters
  • t (numpy array) – the vector of manipulations in [0,1]

  • x (CArray) – the input space sample to perturb

Returns

the adversarial malware

Return type

CArray

init_starting_point(x: secml.array.c_array.CArray) secml.array.c_array.CArray

Initialize the problem, by setting the starting point.

Parameters

x (CArray) – the initial point

Returns

the initial point (padded accordingly to remove trailing invalid values)

Return type

CArray

secml_malware.attack.blackbox.c_blackbox_problem module

class secml_malware.attack.blackbox.c_blackbox_problem.CBlackBoxProblem(model_wrapper: secml_malware.attack.blackbox.c_wrapper_phi.CWrapperPhi, latent_space_size: int, population_size: int, penalty_regularizer: float, iterations: int, seed: Optional[int] = None, is_debug: bool = False, hard_label: bool = False, threshold: float = 0, loss: str = 'l1')

Bases: object

Base class for encapsulating a black box optimization problem.

abstract apply_feasible_manipulations(t: numpy.ndarray, x: secml.array.c_array.CArray) secml.array.c_array.CArray

Applies the manipulation to the malware

Parameters
  • t (numpy array) – the vector of parameters

  • x (CArray) – the original malware sample

Returns

the adversarial malware

Return type

CArray

clear_results()

Reset the internal state after computing an attack

compute_penalty_term(original_x: secml.array.c_array.CArray, adv_x: secml.array.c_array.CArray, par: float) float

Computes the size penalty term

Parameters
  • original_x (CArray) – the original malware sample

  • adv_x (CArray) – the adversarial malware

  • par (float) – the regularization parameter

Returns

the size penalty term, multiplied by the regularization parameter

Return type

flaot

fitness(t: numpy.ndarray) list

Compute the objective function.

Parameters

t (numpy array) – the vector of parameter to test

Returns

the score attributed by the target combined with the the penalty term

Return type

list

get_bounds() -> (<class 'list'>, <class 'list'>)

Gets the bounds for the genetic algorithm :returns: lower bounds and upper bounds :rtype: list, list

init_starting_point(x: secml.array.c_array.CArray) secml.array.c_array.CArray

Initialize the problem, by setting the starting point.

Parameters

x (CArray) – the initial point

Returns

the initial point (padded accordingly to remove trailing invalid values)

Return type

CArray

score_step(x: secml.array.c_array.CArray, penalty_term: float) float

Computes the objective function, combining the penalty term

Parameters
  • x (CArray) – the original sample

  • penalty_term (float) – the penalty term

Return type

float, float

secml_malware.attack.blackbox.c_gamma_evasion module

class secml_malware.attack.blackbox.c_gamma_evasion.CGammaEvasionProblem(section_population: list, model_wrapper: secml_malware.attack.blackbox.c_wrapper_phi.CWrapperPhi, population_size: int, penalty_regularizer: float, iterations: int, seed: Optional[int] = None, is_debug: bool = False, hard_label: bool = False, threshold: float = 0.5, loss: str = 'l1')

Bases: secml_malware.attack.blackbox.c_blackbox_problem.CBlackBoxProblem

GAMMA padding attack

apply_feasible_manipulations(t: numpy.ndarray, x: secml.array.c_array.CArray) secml.array.c_array.CArray

Applies the padding manipulation.

Parameters
  • t (np.ndarray) – the vector of parameters specifying how much content must be included

  • x (CArray) – the original malware

Returns

the adversarial malware

Return type

CArray

classmethod create_section_population_from_folder(folder: str, how_many: int, sections_to_extract: typing.Optional[list] = None, cache_file: typing.Optional[str] = None, size_lower_bound: typing.Optional[int] = None) -> (<class 'list'>, <class 'list'>)

Extract sections from a given folder

Parameters
  • folder (str) – the folder containing programs used for extracting sections

  • how_many (int) – how many sections to extract in general

  • sections_to_extract (list, optional, default None) – the list of section names to use. If None, it will extract only .data sections

  • cache_file (str, optional, default None) – if set, it stores which section from what program has been used inside a pickled object, stored in path

  • size_lower_bound (int, optional, default None) – if set, it will discard all the sections whose content length is less that such parameter

Returns

the section population and what has been extracted from who

Return type

list, list

classmethod create_section_population_from_list(folder: str, what_from_who: list) list

Create the section population from files contained in a specified folder

Parameters
  • folder (str) – the folder containing the file to open

  • what_from_who (list) – a list of file (section name, file names) that specifies what extract from who

Returns

the section population list

Return type

list

secml_malware.attack.blackbox.c_gamma_sections_evasion module

class secml_malware.attack.blackbox.c_gamma_sections_evasion.CGammaSectionsEvasionProblem(section_population: list, model_wrapper: secml_malware.attack.blackbox.c_wrapper_phi.CWrapperPhi, population_size: int, penalty_regularizer: float, iterations: int, seed: Optional[int] = None, is_debug: bool = False, hard_label: bool = False, threshold: float = 0.5, loss: str = 'l1', random_names: bool = True)

Bases: secml_malware.attack.blackbox.c_gamma_evasion.CGammaEvasionProblem

GAMMA section injection attack class

apply_feasible_manipulations(t, x: secml.array.c_array.CArray) secml.array.c_array.CArray

Applies the section injection manipulation.

Parameters
  • t (np.ndarray) – the vector of parameters specifying how much content must be included

  • x (CArray) – the original malware

Returns

the adversarial malware

Return type

CArray

init_starting_point(x: secml.array.c_array.CArray) secml.array.c_array.CArray

Initialize the problem, by setting the starting point.

Parameters

x (CArray) – the initial point

Returns

the initial point (padded accordingly to remove trailing invalid values)

Return type

CArray

secml_malware.attack.blackbox.c_gamma_shift_problem module

class secml_malware.attack.blackbox.c_gamma_shift_problem.CGammaShiftEvasionProblem(section_population: list, model_wrapper: secml_malware.attack.blackbox.c_wrapper_phi.CWrapperPhi, population_size: int, penalty_regularizer: float, iterations: int, seed: Optional[int] = None, is_debug: bool = False, hard_label: bool = False, threshold: float = 0.5, loss: str = 'l1')

Bases: secml_malware.attack.blackbox.c_gamma_evasion.CGammaEvasionProblem

apply_feasible_manipulations(t, x: secml.array.c_array.CArray) secml.array.c_array.CArray

Applies the padding manipulation.

Parameters
  • t (np.ndarray) – the vector of parameters specifying how much content must be included

  • x (CArray) – the original malware

Returns

the adversarial malware

Return type

CArray

secml_malware.attack.blackbox.c_gammapi_evasion module

class secml_malware.attack.blackbox.c_gammapi_evasion.CGammaAPIEvasionProblem(api_list: list, model_wrapper: secml_malware.attack.blackbox.c_wrapper_phi.CWrapperPhi, population_size: int, penalty_regularizer: float, iterations: int, seed: Optional[int] = None, is_debug: bool = False)

Bases: secml_malware.attack.blackbox.c_blackbox_problem.CBlackBoxProblem

apply_feasible_manipulations(t, x: secml.array.c_array.CArray) secml.array.c_array.CArray

Applies the manipulation to the malware

Parameters
  • t (numpy array) – the vector of parameters

  • x (CArray) – the original malware sample

Returns

the adversarial malware

Return type

CArray

secml_malware.attack.blackbox.c_wrapper_phi module

class secml_malware.attack.blackbox.c_wrapper_phi.CEmberWrapperPhi(model: secml_malware.models.c_classifier_ember.CClassifierEmber)

Bases: secml_malware.attack.blackbox.c_wrapper_phi.CWrapperPhi

Class that wraps a GBDT classifier with EMBER feature set.

extract_features(x)

It extracts the EMBER hand-crafted features

Parameters

x (CArray) – The sample in the input space.

Returns

The feature space representation of the input sample.

Return type

CArray

class secml_malware.attack.blackbox.c_wrapper_phi.CEnd2EndWrapperPhi(model: secml_malware.models.c_classifier_end2end_malware.CClassifierEnd2EndMalware)

Bases: secml_malware.attack.blackbox.c_wrapper_phi.CWrapperPhi

Class that wraps an end-to-end model

extract_features(x)

Crops and pads the input sample for being passed to the network.

Parameters

x (CArray) – The sample in the input space.

Returns

The feature space representation of the input sample.

Return type

CArray

class secml_malware.attack.blackbox.c_wrapper_phi.CWrapperPhi(model: secml.ml.classifiers.c_classifier.CClassifier)

Bases: object

Abstract class that encapsulates a model for being used in a black-box way.

abstract extract_features(x: secml.array.c_array.CArray)

It maps the input sample inside the feature space of the wrapped model.

Parameters

x (CArray) – The sample in the input space.

Returns

The feature space representation of the input sample.

Return type

CArray

predict(x: secml.array.c_array.CArray, return_decision_function: bool = True)

Returns the prediction of the sample (in input space).

Parameters
  • x (CArray) – The input sample in input space.

  • return_decision_function (bool, default True) – If True, it also returns the decision function value, rather than only the label. Default is True.

Returns

Returns the label of the sample. If return_decision_function is True, it also returns the output of the decision function.

Return type

CArray, (CArray)

Module contents