CoolFace
Apppublic

chemiomani/static-malware-detector

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
App README

πŸ”’ Static PE Malware Detection

![CI/CD Pipeline](https://github.com/chemiomani/static-malware-detector/actions/workflows/ci-cd.yml) ![Hugging Face Spaces](https://chemiomani-static-malware-detector.hf.space) ![Python 3.11](https://www.python.org/) ![Flask](https://flask.palletsprojects.com/) ![XGBoost](https://xgboost.readthedocs.io/) ![React](https://reactjs.io/) ![License: MIT](https://opensource.org/licenses/MIT)

πŸŽ“ Quantic School of Business and Technology Introduction to Machine Learning - Project

Machine learning-based static malware detection for Windows Portable Executable (PE) files. This application analyzes PE headers to classify files as malware or goodware without executing them.

Author: Chemi Omani

🎯 Live Demo

Try it now: https://chemiomani-static-malware-detector.hf.space

πŸ“Š Model Performance

MetricScore
Accuracy98.56%
AUC-ROC0.9972
Precision98.59%
Recall98.92%
F1 Score98.75%

Feature Importance

The model uses 8 key PE header features:

FeatureImportance
DllCharacteristics56.15%
AddressOfEntryPoint14.96%
SectionsNb9.21%
CheckSum7.46%
SizeOfCode6.95%
SizeOfUninitializedData5.28%
Machine0.00%
SizeOfOptionalHeader0.00%

✨ Features

  • β€”πŸ” Manual PE Inspection - Enter PE header parameters manually or upload a file
  • β€”πŸ“Š Batch CSV Analysis - Upload multiple samples with confusion matrix
  • β€”πŸ€– XGBoost Model - 98.56% accuracy on 50,000+ samples
  • β€”πŸŽ― Real-time Predictions - Instant classification with confidence scores
  • β€”πŸ“ˆ Performance Metrics - Accuracy, AUC-ROC, F1 score, confusion matrix
  • β€”πŸŽ¨ Modern UI - Pink dark theme with responsive design
  • β€”πŸ”„ CI/CD Pipeline - Automated testing and deployment via GitHub Actions

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         USER INTERFACE                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Manual PE Inspector β”‚     β”‚    CSV Batch Profiler           β”‚   β”‚
β”‚  β”‚  - Feature Input     β”‚     β”‚    - File Upload                β”‚   β”‚
β”‚  β”‚  - Preset Selection  β”‚     β”‚    - Batch Predictions          β”‚   β”‚
β”‚  β”‚  - Real-time Results β”‚     β”‚    - Metrics & Confusion Matrix β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚
                                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         FLASK API SERVER                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Endpoints:                                                  β”‚   β”‚
β”‚  β”‚  /api/health        - Health check                          β”‚   β”‚
β”‚  β”‚  /api/predict       - Single prediction                     β”‚   β”‚
β”‚  β”‚  /api/predict-batch - Batch prediction from CSV             β”‚   β”‚
β”‚  β”‚  /api/model-info    - Model information                     β”‚   β”‚
β”‚  β”‚  /api/dataset       - Dataset serving (for training UI)     β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚
                                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         MODEL PIPELINE                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  Input β†’ Imputer (Median) β†’ Scaler (Standard) β†’ XGBoost    β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Training Pipeline

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         TRAINING PIPELINE                           β”‚
β”‚                                                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚   Dataset    │────▢│   80/20      │────▢│  Stratified 5-Fold  β”‚  β”‚
β”‚  β”‚  50,181      β”‚     β”‚   Split      β”‚     β”‚  Cross-Validation   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                                    β”‚                β”‚
β”‚                                                    β–Ό                β”‚
β”‚                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
β”‚                              β”‚  For each fold:                     β”‚β”‚
β”‚                              β”‚  1. Impute missing values (Median) β”‚β”‚
β”‚                              β”‚  2. Scale features (StandardScaler)β”‚β”‚
β”‚                              β”‚  3. Train model on fold            β”‚β”‚
β”‚                              β”‚  4. Evaluate on validation fold    β”‚β”‚
β”‚                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β”‚                                                    β”‚                β”‚
β”‚                                                    β–Ό                β”‚
β”‚                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
β”‚                              β”‚  Select Best Model (XGBoost)       β”‚β”‚
β”‚                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β”‚                                                    β”‚                β”‚
β”‚                                                    β–Ό                β”‚
β”‚                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
β”‚                              β”‚  Train Final Model on Full          β”‚β”‚
β”‚                              β”‚  Training Set (40,144 samples)     β”‚β”‚
β”‚                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β”‚                                                    β”‚                β”‚
β”‚                                                    β–Ό                β”‚
β”‚                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
β”‚                              β”‚  Evaluate on Hold-out Test Set     β”‚β”‚
β”‚                              β”‚  (10,037 samples)                  β”‚β”‚
β”‚                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‚ Project Structure

.
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── ci-cd.yml                 # CI/CD Pipeline
β”œβ”€β”€ backend/                           # ML & API workspace
β”‚   β”œβ”€β”€ app.py                         # Flask API server (port 7860)
β”‚   β”œβ”€β”€ model_pipeline.pkl             # Trained XGBoost model
β”‚   β”œβ”€β”€ requirements.txt               # Python dependencies
β”‚   β”œβ”€β”€ test_app.py                    # Unit & integration tests
β”‚   └── train.py                       # Model training script
β”œβ”€β”€ frontend/                          # React client application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.tsx                    # Main React component
β”‚   β”‚   β”œβ”€β”€ data.ts                    # Presets & configuration
β”‚   β”‚   β”œβ”€β”€ types.ts                   # TypeScript definitions
β”‚   β”‚   β”œβ”€β”€ main.tsx                   # React DOM entry point
β”‚   β”‚   └── index.css                  # Tailwind styles
β”‚   β”œβ”€β”€ index.html                     # HTML entry point
β”‚   β”œβ”€β”€ package.json                   # npm dependencies
β”‚   β”œβ”€β”€ tsconfig.json                  # TypeScript configuration
β”‚   └── vite.config.ts                 # Vite build configuration
β”œβ”€β”€ dist/                              # Built React application
β”‚   β”œβ”€β”€ index.html
β”‚   └── assets/                        # Compiled JS & CSS
β”œβ”€β”€ .gitignore                         # Version control exclusions
β”œβ”€β”€ Dockerfile                         # Hugging Face Spaces deployment
└── README.md                          # Project documentation

πŸš€ Quick Start

Prerequisites

Local Development

bash
# 1. Clone the repository
git clone git@github.com:chemiomani/static-malware-detector.git
cd static-malware-detector

# 2. Set up Python backend
cd backend
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

# 3. Download the dataset
wget -O brazilian-malware.zip https://github.com/fabriciojoc/brazilian-malware-dataset/raw/master/brazilian-malware.zip
unzip -j brazilian-malware.zip "*.csv" -d .
rm -f brazilian-malware.zip

# 4. Train the model
python train.py

# 5. Start Flask server
python app.py

# 6. In another terminal, set up React frontend
cd ../frontend
npm install
npm run build

# 7. Open browser
open http://localhost:7860

Using Docker

bash
# Build the Docker image
docker build -t static-malware-detector .

# Run the container
docker run -p 7860:7860 static-malware-detector

Running Tests

bash
# Python tests
cd backend
pytest test_app.py -v

# Expected output: 15 passed

🧠 How It Works

1. Feature Mapping

The application maps UI feature names to dataset column names:

UI FeatureDataset Column
CheckSumSizeOfImage
SectionsNbNumberOfSections
DllCharacteristicsDllCharacteristics
AddressOfEntryPointImageBase
SizeOfUninitializedDataSizeOfUninitializedData
SizeOfCodeSizeOfCode
MachineMachine
SizeOfOptionalHeaderSizeOfOptionalHeader

2. Model Pipeline

Input Features β†’ Imputer (Median) β†’ Scaler (Standard) β†’ XGBoost β†’ Prediction

3. Prediction Flow

User Input β†’ Flask API β†’ Model Pipeline β†’ Prediction β†’ UI Display

4. Batch Processing Flow

CSV Upload β†’ Parse Features β†’ Batch Predictions β†’ Calculate Metrics β†’ Display Results

πŸ“Š Dataset

The model was trained on the Brazilian Malware Dataset:

  • β€”Samples: 50,181
  • β€”Features: 27 PE header attributes
  • β€”Class Balance: 57.1% Malware, 42.9% Goodware
  • β€”Source: Brazilian Malware Dataset

Citation

bibtex
@ARTICLE{8636415,
  author={F. {Ceschin} and F. {Pinage} and M. {Castilho} and D. {Menotti} and L. S. {Oliveira} and A. {Gregio}},
  journal={IEEE Security Privacy},
  title={The Need for Speed: An Analysis of Brazilian Malware Classifiers},
  year={2018},
  volume={16},
  number={6},
  pages={31-41},
  doi={10.1109/MSEC.2018.2875369}
}

πŸ› οΈ Technology Stack

Backend

  • β€”Flask - Web framework
  • β€”XGBoost - Gradient boosting classifier
  • β€”scikit-learn - Preprocessing and metrics
  • β€”pandas - Data manipulation
  • β€”numpy - Numerical computing

Frontend

  • β€”React - UI framework
  • β€”TypeScript - Type-safe JavaScript
  • β€”Tailwind CSS - Styling
  • β€”Vite - Build tool
  • β€”Lucide React - Icons

Deployment

  • β€”Docker - Containerization
  • β€”Hugging Face Spaces - Hosting
  • β€”GitHub Actions - CI/CD

πŸ”¬ Testing

bash
# Run Python tests
cd backend
pytest test_app.py -v

# Expected output:
# βœ… test_model_loaded PASSED
# βœ… test_predict_goodware PASSED
# βœ… test_predict_malware PASSED
# βœ… test_predict_missing_features PASSED
# βœ… test_health_endpoint PASSED
# βœ… test_model_info_endpoint PASSED
# βœ… test_predict_endpoint_goodware PASSED
# βœ… test_predict_endpoint_malware PASSED
# βœ… test_predict_endpoint_missing_features PASSED
# βœ… test_demo_endpoint PASSED
# βœ… test_predict_batch_endpoint PASSED
# βœ… test_predict_batch_no_file PASSED
# βœ… test_invalid_predict_payload PASSED
# βœ… test_health_endpoint_model_status PASSED
# βœ… test_holdout_demo_endpoint PASSED

πŸ“ˆ Performance Benchmarks

ModelAccuracyAUC-ROCTraining Time
Logistic Regression81.42%0.8770Fast
Decision Tree97.71%0.9761Fast
Random Forest98.73%0.9975Medium
XGBoost98.34%0.9975Medium
LightGBM98.29%0.9974Medium
CatBoost97.82%0.9959Slow

🎯 Preset Configurations

Malware Preset

json
{
  "CheckSum": 0,
  "SectionsNb": 6,
  "DllCharacteristics": 0,
  "AddressOfEntryPoint": 100000,
  "SizeOfUninitializedData": 0,
  "SizeOfCode": 500000,
  "Machine": 332,
  "SizeOfOptionalHeader": 224
}

Confidence: 88.3%

Goodware Preset

json
{
  "CheckSum": 200000,
  "SectionsNb": 4,
  "DllCharacteristics": 50000,
  "AddressOfEntryPoint": 100000,
  "SizeOfUninitializedData": 0,
  "SizeOfCode": 80000,
  "Machine": 34404,
  "SizeOfOptionalHeader": 224
}

Confidence: 47.5%

πŸ”§ Troubleshooting

Common Issues

SSH Authentication Error

bash
# If you get SSH errors, use explicit key
GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_chemiomani" git push origin main

Dataset Download Fails

bash
# Manual download
wget -O backend/brazilian-malware.zip https://github.com/fabriciojoc/brazilian-malware-dataset/raw/master/brazilian-malware.zip
cd backend && unzip -j brazilian-malware.zip "*.csv" -d .

Model Not Found

bash
# Train the model
cd backend && python train.py

🀝 Contributing

Contributions are welcome! Please:

  1. 1.Fork the repository
  2. 2.Create a feature branch
  3. 3.Make your changes
  4. 4.Submit a pull request

πŸ“ License

This project is licensed under the MIT License.

πŸ™ Acknowledgments

  • β€”Quantic School of Business and Technology - For providing the project framework and learning opportunity
  • β€”Brazilian Malware Dataset - For providing the training data
  • β€”Hugging Face - For hosting the application
  • β€”Instructors and Mentors - For guidance throughout the project

πŸ“ž Contact

Chemi Omani


πŸŽ“ This project was completed as a fulfillment of the Quantic School of Business and Technology - Introduction to Machine Learning Project

Made with ❀️ by Chemi Omani

![Hugging Face](https://chemiomani-static-malware-detector.hf.space) ![GitHub](https://github.com/chemiomani/static-malware-detector) ![CI/CD Pipeline](https://github.com/chemiomani/static-malware-detector/actions/workflows/ci-cd.yml)