Live Demo: https://malicious-url-detection-hamim.streamlit.app/
A modern, intelligent web application that uses Random Forest machine learning to detect and classify malicious URLs in real-time. Built with Streamlit, featuring an advanced whitelist override system and beautiful interactive visualizations.
Author: Mohammad Hamim
Student ID: 202280090114
Course: Network Security
- Instant Detection: Analyze URLs in milliseconds with 60 URLs/second throughput
- 4 Threat Categories: Benign, Phishing, Malware, Defacement
- Confidence Scores: Detailed probability breakdown for each category
- 27 Advanced Features: URL patterns, character analysis, domain inspection
- Glassmorphism Design: Beautiful gradient backgrounds with frosted glass effects
- Interactive Visualizations:
- Real-time confidence gauge (Plotly)
- Security score radar chart
- Feature importance bar charts
- Quick Test Buttons: One-click testing with pre-populated URLs
- Responsive Layout: Works seamlessly on desktop and mobile
- Whitelist Override: 150+ trusted domains (Google, GitHub, Microsoft, Netflix, etc.)
- Security Recommendations: Contextual advice based on URL classification
- Debug Mode: Transparent model predictions and override decisions
- Real-Time Stats: Live threat statistics and scanning metrics
- 7-Test Suite: Complete model validation
- Performance Metrics: Speed, accuracy, and throughput analysis
- Beautiful Reports: HTML, JSON, and TXT formats
- 100% Test Coverage: All critical paths validated
- Algorithm: Random Forest Classifier โญ
- Features: 27 URL characteristics
- Training Data: 651,191 URLs
- Classes: 4 (benign, phishing, malware, defacement)
Source: Malicious URLs Dataset
Total Records: 651,191 URLs
Data Sources: ISCX URL 2016, PhishTank, PhishStorm, Malware Domain List
Class Distribution:
- Benign: 428,103 (65.7%)
- Defacement: 96,457 (14.8%)
- Phishing: 94,111 (14.5%)
- Malware: 32,520 (5.0%)
- URL Metrics: Length, hostname length, directory count
- Character Counts: Special characters (@, ?, -, =, etc.)
- Security Indicators: HTTPS, IP address, suspicious words
- Domain Analysis: TLD length, embedded domains, short URL services
- Prediction Speed: ~23ms per URL
- Throughput: ~60 URLs/second
- Feature Extraction: ~1ms
- Model Inference: ~22ms
- Accuracy: ~98%
- F1-Score: ~0.97 (macro average)
- Python 3.12 or higher
- pip package manager
- Virtual environment (recommended)
-
Clone the repository
git clone https://github.com/md-hameem/Malicious-URL-Detection-Using-Machine-Learning.git cd Malicious-URL-Detection-Using-Machine-Learning -
Create and activate virtual environment
# Windows python -m venv .venv .venv\Scripts\activate # Linux/Mac python3 -m venv .venv source .venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Run the application
streamlit run app.py
-
Open your browser Navigate to
http://localhost:8501
Malicious-URL-Detection-Using-Machine-Learning/
โโโ ๐ฑ app.py # Main Streamlit application
โโโ ๐ requirements.txt # Python dependencies
โโโ ๐ README.md # This file
โโโ ๐ LICENSE # MIT License
โ
โโโ ๐ data/ # Dataset storage
โ โโโ raw/
โ โโโ malicious_phish.csv # Training dataset (651K URLs)
โ
โโโ ๐ models/ # Trained ML models
โ # (Model files are not included in this version)
โ
โโโ ๐ notebooks/ # Jupyter notebooks
โ โโโ malicious_url_detection.ipynb # Analysis & training
โ
โโโ ๐ tests/ # Test suite
โ โโโ test_model.py # Comprehensive tests
โ โโโ check_features.py # Feature inspection
โ โโโ README.md # Test documentation
โ
โโโ ๐ scripts/ # Utility scripts
โ โโโ app_old.py # Previous version backup
โ
โโโ ๐ docs/ # Documentation
โ โโโ PROJECT_STRUCTURE.md # Structure overview
โ โโโ README_DETAILED.md # Detailed guide
โ โโโ STREAMLIT_GUIDE.md # App documentation
โ
โโโ ๐ reports/ # Test reports
โโโ test_report_*.html # HTML reports
โโโ test_report_*.json # JSON reports
โโโ test_report_*.txt # Text reports
See docs/PROJECT_STRUCTURE.md for detailed information.
Due to file size limitations, model files are not included in the Git repository.
You can download the pre-trained models from the following secure link:
๐ Download Pre-trained Models (Google Drive)
- Enter URL: Type or paste any URL in the input field
- Quick Test: Use preset buttons for Safe, Suspicious, or Risky URLs
- Scan: Click "๐ Scan Now" to analyze
- Review: See classification, confidence, and recommendations
- Debug: Expand debug section to see detailed model output
# Run comprehensive test suite
python tests/test_model.py
# Check model features
python tests/check_features.pyTest reports are automatically generated in reports/ directory in three formats:
- HTML: Interactive, styled web report (open in browser)
- JSON: Machine-readable data for CI/CD integration
- TXT: Plain text for logging and archiving
# Example: Feature extraction and prediction (model loading code removed)
# See app.py for full implementation details
url = "https://example.com"
features_df = extract_url_features(url) # Returns DataFrame with 27 features
# Model prediction code is not included in this versionThe project includes a robust testing framework with 7 comprehensive tests:
| Test # | Name | Purpose | Status |
|---|---|---|---|
| 1 | Model Loading | Verify models load correctly | โ Pass |
| 2 | Feature Extraction | Validate all 27 features | โ Pass |
| 3 | Safe URL Test | Test legitimate domains | โ Pass |
| 4 | Malicious URL Test | Test phishing domains | โ Pass |
| 5 | Whitelist Override | Test 7 trusted domains | โ Pass |
| 6 | Batch Testing | Test 8 URLs with metrics | โ Pass |
| 7 | Performance Metrics | Measure speed/throughput | โ Pass |
- Total Tests: 7
- Passed: 7 (100%)
- Duration: ~3 seconds
- Throughput: 60 URLs/second
See tests/README.md for detailed test documentation.
The application includes a whitelist of 150+ trusted domains. To modify:
Edit safe_domains list in app.py (around line 643):
safe_domains = [
'google.com', 'github.com', 'microsoft.com',
# Add more trusted domains...
]To retrain with updated data:
- Place new data in
data/raw/ - Update feature extraction if needed
- Run training notebook in
notebooks/ - Save new model to
models/
| Technology | Purpose |
|---|---|
| Streamlit | Modern web application framework |
| scikit-learn | Machine learning models |
| Plotly | Interactive visualizations |
| pandas | Data manipulation and analysis |
| TLD | Domain extraction and parsing |
| Python 3.12 | Core programming language |
Problem: Model predicts google.com, github.com as phishing (98-100% confidence)
Root Cause: Training data labels URLs by content, not domain reputation. Google Docs/Drive used for phishing โ model learns "google.com" = phishing
Solution: Whitelist override system with 150+ trusted domains provides practical workaround
Proper Fix: Retrain model with:
- Domain reputation features
- Distinction between main domain and subdomains
- Platform vs. content classification
See docs/PROJECT_STRUCTURE.md for detailed analysis.
- โ Random Forest ML Model (98% accuracy)
- โ Modern Streamlit Web App with glassmorphism design
- โ Real-time URL Analysis (60 URLs/second)
- โ Interactive Plotly Visualizations
- โ 150+ Domain Whitelist Override
- โ 27 Feature Extraction
- โ Comprehensive Test Suite (7 tests, 100% pass rate)
- โ Automated Report Generation (HTML/JSON/TXT)
- โ Security Recommendations
- โ Debug Mode for transparency
- Deep learning models (LSTM, CNN)
- RESTful API for integration
- Browser extension
- Docker containerization
- CI/CD pipeline
- Database for scan history
- Advanced threat intelligence
- Mobile application
- Real-time threat feeds
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Make your changes
- Run tests:
python tests/test_model.py - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Main README: This file
- Detailed Guide: docs/README_DETAILED.md
- Project Structure: docs/PROJECT_STRUCTURE.md
- Streamlit Guide: docs/STREAMLIT_GUIDE.md
- Test Documentation: tests/README.md
This project is licensed under the MIT License - see the LICENSE file for details.
Mohammad Hamim
- Student ID: 202280090114
- GitHub: @md-hameem
- Repository: Malicious-URL-Detection-Using-Machine-Learning
- Course: Network Security
- Dataset: Malicious URLs Dataset by Siddhant Baldota
- Data Sources: ISCX URL 2016, PhishTank, PhishStorm, Malware Domain List
- Frameworks: Streamlit, scikit-learn, Plotly
- Course: Network Security
For questions, issues, or feedback:
- Open an issue
- Check the documentation
- Review test reports
Last Updated: December 8, 2025
Version: 2.0
Status: โ
Active - Fully Functional
Protect yourself from malicious URLs with ML-powered detection
โญ Star this repository if you find it helpful!