Cyber threats are a growing concern for organizations worldwide. These threats take many forms, including malware, phishing, and denial-of-service (DOS) attacks, compromising sensitive information and disrupting operations. The increasing sophistication and frequency of these attacks make it imperative for organizations to adopt advanced security measures. Traditional threat detection methods often fall short due to their inability to adapt to new and evolving threats. This is where deep learning models come into play.
Deep learning models can analyze vast amounts of data and identify patterns that may not be immediately obvious to human analysts. By leveraging these models, organizations can proactively detect and mitigate cyber threats, safeguarding their sensitive information and ensuring operational continuity.
As a cybersecurity analyst, you identify and mitigate these threats. In this project, you will design and implement a deep learning model to detect cyber threats. The BETH dataset simulates real-world logs, providing a rich source of information for training and testing your model. The data has already undergone preprocessing, and we have a target label, sus_label, indicating whether an event is malicious (1) or benign (0).
By successfully developing this model, you will contribute to enhancing cybersecurity measures and protecting organizations from potentially devastating cyber attacks.
The Data
| Column | Description |
|---|---|
processId | The unique identifier for the process that generated the event - int64 |
threadId | ID for the thread spawning the log - int64 |
parentProcessId | Label for the process spawning this log - int64 |
userId | ID of user spawning the log |
mountNamespace | Mounting restrictions the process log works within - int64 |
argsNum | Number of arguments passed to the event - int64 |
returnValue | Value returned from the event log (usually 0) - int64 |
sus_label | Binary label as suspicous event (1 is suspicious, 0 is not) - int64 |
More information on the dataset: BETH dataset (Invalid URL)
# Import required libraries
import pandas as pd
from sklearn.preprocessing import StandardScaler
import torch
import torch.nn as nn
import torch.nn.functional as functional
from torch.utils.data import DataLoader, TensorDataset
import torch.optim as optim
from torchmetrics import Accuracy
# from sklearn.metrics import accuracy_score # uncomment to use sklearn# Load preprocessed data
train_df = pd.read_csv('labelled_train.csv')
test_df = pd.read_csv('labelled_test.csv')
val_df = pd.read_csv('labelled_validation.csv')
# View the first 5 rows of training set
train_df.head()X_train_df = train_df.drop('sus_label',axis=1)
y_train_df = train_df['sus_label'].values.reshape(-1,1)scaler = StandardScaler()
scaler.fit(X_train_df)
X_train_df_scaled = scaler.transform(X_train_df)X_val_df = val_df.drop('sus_label',axis=1)
y_val_df = val_df['sus_label'].values.reshape(-1,1)
X_val_df_scaled = scaler.transform(X_val_df)
X_test_df = test_df.drop('sus_label',axis=1)
X_test_df_scaled = scaler.transform(X_test_df)
y_test_df = test_df['sus_label'].values.reshape(-1,1)test_dfX_train_scaled_tensor = torch.tensor(X_train_df_scaled,dtype=torch.float32)
y_train_tensor = torch.tensor(y_train_df,dtype=torch.float32)
X_val_scaled_tensor = torch.tensor(X_val_df_scaled,dtype=torch.float32)
y_val_tensor = torch.tensor(y_val_df,dtype=torch.float32)
X_test_scaled_tensor = torch.tensor(X_test_df_scaled,dtype=torch.float32)
y_test_tensor = torch.tensor(y_test_df,dtype=torch.float32)model_batch_training = nn.Sequential(
nn.Linear(7,32),
nn.ReLU(),
nn.Linear(32,32),
nn.ReLU(),
nn.Linear(32,1),
nn.Sigmoid()
)
model_no_batch_training = nn.Sequential(
nn.Linear(7,32),
nn.ReLU(),
nn.Linear(32,32),
nn.ReLU(),
nn.Linear(32,1),
nn.Sigmoid()
)Batch Training
train_data = TensorDataset(X_train_scaled_tensor,y_train_tensor)
train_loader = DataLoader(train_data,batch_size=32,shuffle=True)criterion = nn.BCELoss()
optimizer = optim.SGD(model_batch_training.parameters(),lr=0.001, weight_decay=0.0001)num_epochs=10
for epoch in range(num_epochs):
model_batch_training.train()
running_loss = 0.0
for input, label in train_loader:
optimizer.zero_grad()
preds = model_batch_training(input)
loss = criterion(preds, label)
loss.backward()
optimizer.step()
running_loss += loss.item()
epoch_loss = running_loss/len(train_data)
print(f"Epoch loss is {epoch_loss}")