Skip to content

Commit

Permalink
Merge pull request #50 from Critical-Infrastructure-Systems-Lab/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
afmurillo authored Jul 10, 2024
2 parents a46580c + b60a115 commit 3bdc4f4
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 145 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
���ʫ���h������ۮ������� ��������(������2
������ƙ5�é������������ ���ȕ���(������2

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 16 additions & 10 deletions dhalsim/network_attacks/concealment_ae_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from sklearn.model_selection import train_test_split

import joblib
import numpy as np

# This module is based on the implementation by Alessandro Erba, original is found here:
# https://github.com/scy-phy/ICS-Evasion-Attacks/blob/master/Adversarial_Attacks/Black_Box_Attack/adversarial_AE.py
Expand Down Expand Up @@ -72,23 +73,22 @@ def load_scaler(self, scaler_path):
print('Scaler loaded')

# Saves the model and the scaler used to train the model
def save_model(self, filename):
print('saving trained model at: ', str(filename))
self.generator.save(str(model_path))
def save_model(self, model_filename, scaler_filename):
print('saving trained model at: ', str(model_filename))
self.generator.save(str(model_filename))

scaler_path = Path.cwd()
print('saved scaler model at: ', filename)
joblib.dump(self.attacker_scaler, 'ctown_attacker_scaler.gz')
print('saved scaler model at: ', scaler_filename)
joblib.dump(self.attacker_scaler, scaler_filename)

def init_generator(self, training_path):
# Load and preprocess training data
training_path = Path(__file__).parent/training_path/'training_data.csv'
#training_path = Path(__file__).parent/training_path/'training_data.csv'
training_path = Path(__file__).parent/training_path/'ground_truth_dataset.csv'
# print('Reading training data from: ' + str(training_path))
self.physical_pd = self.preprocess_physical(training_path)

# Adversarial model for concealment
# toDo: Ask about this parameter
hide_layers = 39
hide_layers = 160
self.hide_layers = hide_layers
self.generator_layers = [self.feature_dims,
int(self.hide_layers / 2),
Expand Down Expand Up @@ -130,14 +130,19 @@ def fix_sample(self, gen_examples):
return gen_examples

def predict(self, received_values_df):
print('Attempting to predict concealment values')
#print('Attempting to predict concealment values')
# print('Features received to predict: ' + str(received_values_df.columns))
# print('Features received to train: ' + str(self.sensor_cols))

gen_examples = self.generator.predict(self.attacker_scaler.transform(received_values_df))
#print('nan predicted values: ')
# print(gen_examples)
#print(np.isnan(gen_examples))
gen_examples = self.fix_sample(pd.DataFrame(columns=self.sensor_cols,
data=self.attacker_scaler.inverse_transform(gen_examples)))

#print('Model fixed values')
#print(gen_examples)
return gen_examples

def __init__(self, features_list):
Expand All @@ -146,3 +151,4 @@ def __init__(self, features_list):
self.sensor_cols = [col for col in features_list if
col not in ['Unnamed: 0', 'iteration', 'timestamp', 'Attack']]
self.feature_dims = len(self.sensor_cols)
print(f'Model has {self.feature_dims } input features' )
2 changes: 1 addition & 1 deletion dhalsim/network_attacks/mitm_netfilter_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def capture(self, packet):
del p[TCP].chksum

packet.set_payload(bytes(p))
self.logger.debug(f"Value of network packet for {p[IP].dst} overwritten.")
# self.logger.debug(f"Value of network packet for {p[IP].dst} overwritten.")

packet.accept()
except Exception as exc:
Expand Down
Loading

0 comments on commit 3bdc4f4

Please sign in to comment.