chemiomani/static-malware-detector
π Static PE Malware Detection
      
π 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
Feature Importance
The model uses 8 key PE header features:
β¨ 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
- Python 3.11+
- Node.js 18+
- Git
- Dataset: Brazilian Malware Dataset
Local Development
# 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:7860Using Docker
# Build the Docker image
docker build -t static-malware-detector .
# Run the container
docker run -p 7860:7860 static-malware-detectorRunning Tests
# 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:
2. Model Pipeline
Input Features β Imputer (Median) β Scaler (Standard) β XGBoost β Prediction3. Prediction Flow
User Input β Flask API β Model Pipeline β Prediction β UI Display4. 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
@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
# 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
π― Preset Configurations
Malware Preset
{
"CheckSum": 0,
"SectionsNb": 6,
"DllCharacteristics": 0,
"AddressOfEntryPoint": 100000,
"SizeOfUninitializedData": 0,
"SizeOfCode": 500000,
"Machine": 332,
"SizeOfOptionalHeader": 224
}Confidence: 88.3%
Goodware Preset
{
"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
# If you get SSH errors, use explicit key
GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_chemiomani" git push origin mainDataset Download Fails
# 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
# Train the model
cd backend && python train.pyπ€ Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- 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
- GitHub: @chemiomani
- Hugging Face: @chemiomani
π 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
  
