How 0xfke/malware-detection-and-analysis-using-machine-learning works
Project Type and Purpose
• This is a full-stack Flask WebApp for Malware Detection and Analysis.
• It combines two primary capabilities:
a. Static Analysis via the VirusTotal API (“VT” component).
b. Machine-Learning-Based Detection of executables using a pre-trained Random Forest model (“ML_model” component).
• There is also scaffolding for future “Dynamic Analysis” and dataset artifacts.
File Structure Analysis
• Top-level files
• app.py / appV1.py: main Flask entry points
• requirements.txt: dependencies list
• README.md, CONTRIBUTING.md, LICENSE
• Directories
• VT/ : static-analysis Blueprint
– app.py: Flask routes for VirusTotal uploads
– templates/: HTML views (index, details, result)
• ML_model/ : serialized model artifacts (.pkl)
• Dataset/ : CSVs for model training and feature filtering
• Dynamic_Analysis/: placeholder for dynamic analysis scripts (config.py)
• templates/: fallback or main app HTML (index.html, result.html)
• Image/, Video/: demo assets
Key Architectural Insights from README
• Two parallel analysis flows managed by the same Flask server:
a. Static Flow: user → VT blueprint → VirusTotal API → results
b. ML Flow: user → ML route in app.py → feature_extraction.py → RandomForest model → results
• No traditional database; results are transient and rendered in templates.
• Model training and dataset preparation steps are offline; model deployment uses joblib-serialized artifacts.
Main Components
a. User Interface
– Browser with two entry points: Static Analysis page and ML Analysis page
– UI templates (index.html, result.html, details.html)
b. Web Server (Flask Monolith)
– app.py (or appV1.py): central server that imports VT blueprint and ML routes
– feature_extraction.py: extracts PE features for ML flow
– Dynamic_Analysis/config.py (future)
c. Static Analysis Module
– VT blueprint: handles file/URL upload, calls VirusTotal API (external service)
– requests library
d. Machine Learning Module
– ML_model directory: holds malwareclassifier.pkl and malwareclassifier-V2.pkl
– scikit-learn, joblib for model loading
e. Dataset & Training (Offline)
– Dataset CSVs used in Jupyter notebook (malware_detection_insa_1.ipynb)
– feature filtering and model training occur outside runtime
f. External Services
Relationships and Data Flows
1. User Browser → Flask Server (HTTP Post /upload-static or /upload-ml)
2. Flask → VirusTotal API → Flask
3. Flask → feature_extraction → load model → Flask
4. Flask → render_template → Browser
Architectural Patterns & Design Principles
• Monolithic MVC:
• Controllers: Flask routes in app.py and VT/app.py
• Views: Jinja2 templates under templates/ and VT/templates/
• Models:
– Statistical model artifacts (joblib/scikit-learn)
– Configuration for dynamic analysis
• Modular separation via Flask Blueprints for static-analysis
• Clear separation of concerns: static API vs. ML detection