{"id":23564066,"url":"https://github.com/tiarmdhnt/detect-botnets-in-network-traffic","last_synced_at":"2026-04-14T04:01:33.179Z","repository":{"id":269635599,"uuid":"908057558","full_name":"tiarmdhnt/Detect-Botnets-in-Network-Traffic","owner":"tiarmdhnt","description":"Application of Deep Learning to Detect Botnets in Network Traffic Using CTU-13 Dataset","archived":false,"fork":false,"pushed_at":"2024-12-25T02:47:10.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-25T03:20:20.043Z","etag":null,"topics":["botnet-detection","deep-learning","machine-learning","matplotlib","network-security","neural-networks","pandas","python","pytorch","scikit-learn","seaborn","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tiarmdhnt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-25T02:28:42.000Z","updated_at":"2024-12-25T03:01:48.000Z","dependencies_parsed_at":"2024-12-25T03:21:28.513Z","dependency_job_id":"3c2732f7-52bc-4ee8-858f-4678aa35d531","html_url":"https://github.com/tiarmdhnt/Detect-Botnets-in-Network-Traffic","commit_stats":null,"previous_names":["tiarmdhnt/detect-botnets-in-network-traffic"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiarmdhnt%2FDetect-Botnets-in-Network-Traffic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiarmdhnt%2FDetect-Botnets-in-Network-Traffic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiarmdhnt%2FDetect-Botnets-in-Network-Traffic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tiarmdhnt%2FDetect-Botnets-in-Network-Traffic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tiarmdhnt","download_url":"https://codeload.github.com/tiarmdhnt/Detect-Botnets-in-Network-Traffic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239323518,"owners_count":19620032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["botnet-detection","deep-learning","machine-learning","matplotlib","network-security","neural-networks","pandas","python","pytorch","scikit-learn","seaborn","tensorflow"],"created_at":"2024-12-26T17:12:37.143Z","updated_at":"2026-04-14T04:01:28.156Z","avatar_url":"https://github.com/tiarmdhnt.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Detect-Botnets-in-Network-Traffic\nApplication of Deep Learning to Detect Botnets in Network Traffic Using CTU-13 Dataset\n\nThis repository contains code and resources for building a machine learning-based botnet detection system using network traffic data. The project leverages Python libraries for data preprocessing, visualization, and model building.\n\n# **Features**\n\n- Data Preprocessing: Handle missing values, feature scaling, and label encoding.\n- Data Visualization: Analyze label distributions and other key features using Seaborn and Matplotlib.\n- Deep Learning Model: Implementation of a deep learning model using PyTorch for botnet detection.\n\n# **Dataset**\nThe dataset used in this project is publicly available and can be downloaded directly:\n- Source: CTU-Malware-Capture-Botnet-42\n- Download Command:\n  ```bash\n  !wget https://mcfp.felk.cvut.cz/publicDatasets/CTU-Malware-Capture-Botnet-42/detailed-bidirectional-flow-labels/capture20110810.binetflow\n  \n# **Installation**\nTo use this project, ensure you have the following dependencies installed:\n```bash\npip install numpy pandas scikit-learn tensorflow keras matplotlib seaborn torch\n```\n# **Project Workflow**\n**1. Data Preprocessing**\n- Load the dataset using Pandas.\n- Handle missing values.\n- Normalize numerical features using StandardScaler.Encode categorical labels using LabelEncoder.\n\n**2. Data Visualization**\n- Plot label distributions using Seaborn and Matplotlib to understand the data.\n\n**3. Machine Learning Model**\n- Model Architecture:\n- Input layer for network traffic features.\n- Two hidden layers with ReLU activation.\n- Output layer with softmax for multi-class classification.\n- Framework: PyTorch.\n\n**4. Training and Evaluation**\n- Split dataset into training and testing sets.\n- Train the model using the Adam optimizer and CrossEntropyLoss.\n- Evaluate the model using metrics like accuracy, precision, recall, and F1-score.\n\n# **Code Snippets**\n**Data Loading and Preprocessing**\n```bash\nimport pandas as pd\nfrom sklearn.preprocessing import StandardScaler, LabelEncoder\n\n# Load the dataset\nfile_path = \"/content/capture20110810.binetflow\"\ndata = pd.read_csv(file_path, delimiter=',')\ndata = data.dropna()\n\n# Feature scaling\nscaler = StandardScaler()\ndata[['Dur', 'TotPkts', 'TotBytes', 'SrcBytes']] = scaler.fit_transform(data[['Dur', 'TotPkts', 'TotBytes', 'SrcBytes']])\n\n# Label encoding\nle = LabelEncoder()\ndata['Label'] = le.fit_transform(data['Label'])\n```\n**Model Definition**\n```bash\nimport torch\nimport torch.nn as nn\n\nclass BotnetDetectionModel(nn.Module):\n    def __init__(self, input_dim, num_classes):\n        super(BotnetDetectionModel, self).__init__()\n        self.fc1 = nn.Linear(input_dim, 64)\n        self.fc2 = nn.Linear(64, 32)\n        self.fc3 = nn.Linear(32, num_classes)\n        self.dropout = nn.Dropout(0.5)\n\n    def forward(self, x):\n        x = torch.relu(self.fc1(x))\n        x = self.dropout(x)\n        x = torch.relu(self.fc2(x))\n        x = self.fc3(x)\n        return x\n```\n**Training Loop**\n```bash\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score\nfrom torch.utils.data import DataLoader, TensorDataset\n\n# Data preparation\nX = data.drop(columns=['Label'])\ny = data['Label']\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n\n# Convert to tensors\nX_train_tensor = torch.tensor(X_train.values, dtype=torch.float32)\ny_train_tensor = torch.tensor(y_train.values, dtype=torch.long)\n\ntrain_dataset = TensorDataset(X_train_tensor, y_train_tensor)\ntrain_loader = DataLoader(train_dataset, batch_size=32, shuffle=True)\n\n# Model initialization\nmodel = BotnetDetectionModel(input_dim=X_train.shape[1], num_classes=len(y.unique()))\ncriterion = nn.CrossEntropyLoss()\noptimizer = torch.optim.Adam(model.parameters(), lr=0.001)\n\n# Training loop\n```bash\nnum_epochs = 10\nfor epoch in range(num_epochs):\n    model.train()\n    running_loss = 0.0\n\n    for batch_X, batch_y in train_loader:\n        optimizer.zero_grad()\n        outputs = model(batch_X)\n        loss = criterion(outputs, batch_y)\n        loss.backward()\n        optimizer.step()\n        running_loss += loss.item()\n\n    print(f\"Epoch {epoch+1}/{num_epochs}, Loss: {running_loss/len(train_loader):.4f}\")\n```\n\n# **Metrics**\nThe model evaluates the following metrics during training and testing:\n- Accuracy\n- Precision\n- Recall\n- F1-Score\n\n# **Technology Used**\n- Python\n- PyTorch\n- Scikit-learn\n- Pandas\n- Matplotlib\n- Seaborn\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiarmdhnt%2Fdetect-botnets-in-network-traffic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftiarmdhnt%2Fdetect-botnets-in-network-traffic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftiarmdhnt%2Fdetect-botnets-in-network-traffic/lists"}