This project detects malicious and phishing URLs using Machine Learning. It extracts key structural, domain, and behavioral features from a URL and passes them to trained ML models to determine the probability of the URL being a phishing attempt. The project includes a robust training pipeline, a fast API for inference, and integrated logging for Power BI dashboards.
Phishing attacks are one of the most common cyber threats, tricking users into revealing sensitive information through deceptive URLs. A reliable, real-time ML-based URL classifier can significantly mitigate these risks by predicting the probability that a given link is malicious.
We extract 20 specific features to ensure strong performance without unnecessary complexity.
- url_length: The total character length of the URL.
- hostname_length: Length of the domain name.
- count.: Number of dots (
.) in the URL. - count-digits: Total number of numeric digits in the URL.
- count-: Number of hyphens (
-). Phishing sites often use hyphens to mimic legitimate domains. - count@: Number of
@symbols. Often used to hide the actual domain. - count%: Number of
%symbols. Indicates URL encoding, often used to obfuscate.
- subdomain_count: The number of subdomains. Phishers use long subdomains to trick users.
- suspicious_tld: Checks if the Top-Level Domain (TLD) is commonly associated with spam (e.g.,
.xyz,.top). - use_of_ip: Checks if the domain is directly an IP address instead of a standard hostname.
- has_https:
1if the URL uses secure HTTPS,0otherwise.
- path_length: Length of the URL path (everything after the domain).
- fd_length: Length of the first directory in the path.
- path_depth: The number of directories in the path (slashes
/). - query_param_count: The number of parameters passed in the URL (separated by
&). - tld_in_path: Checks if a domain extension (like
.com) is hiding in the path (e.g.,google.com/login.com).
- double_extension: Detects suspicious files with double extensions (e.g.,
.pdf.exe). - has_fragment: Checks for
#fragment identifiers in the URL. - short_url: Detects if the URL uses a link shortener service like
bit.lyortinyurl.com.
- phish_keyword: Checks if common phishing words (like
login,verify,secure,bank) are present in the URL.
We test and compare four machine learning algorithms on the dataset:
- Decision Tree (DT) - Baseline
- Random Forest (RF) β Our Best Performer
- Logistic Regression (LR) - Linear baseline
- XGBoost (Extreme Gradient Boosting) - Gradient boosting approach
Random Forest outperforms XGBoost on this specific task because:
-
Feature Independence: The 20 URL features (TLD, hostname length, keywords, etc.) are structurally independent. They don't have complex interactions that require XGBoost's sequential refinement.
-
Clean Classification Boundary: Phishing URLs follow predictable patterns. Ensemble voting naturally captures these patterns without needing iterative refinement.
-
High Recall: Catching phishing attempts is critical. RF's ensemble voting achieves superior recall - multiple trees must agree, ensuring fewer missed threats.
-
Scale Efficiency: With 450k training samples, RF's parallel tree building is more efficient and robust than XGBoost's sequential approach.
-
Interpretability: Feature importance directly shows which URL characteristics are most suspicious, helping understand model decisions.
-
Production Simplicity: Fewer hyperparameters to tune; robust across different URL distributions without constant retraining.
We compare models using:
- Accuracy: Overall correctness of the model.
- Precision: Accuracy of positive predictions.
- Recall: Ability to find all actual positive cases.
- F1-Score: The balance between Precision and Recall.
The results and feature importances are automatically displayed as graphs inside the Jupyter Notebook.
python -m pip install -r requirements.txtIf you want to retrain the models, ensure urldata.csv is in the project directory, then open and run the Jupyter Notebook:
jupyter notebook Training_Pipeline.ipynbThis will extract 20 features in parallel, train all 4 models on the full 450k+ dataset, perform Hyperparameter Tuning, and save the best model (Random Forest) inside models/best_model.pkl.
python -m uvicorn API:app --reloadThe API will be available at http://127.0.0.1:8000.
cd frontend
npm install
npm run devOpens interactive web interface at http://localhost:5173 with real-time URL analysis, dark/light theme, and detailed feature visualization.
- Navigate to
phishing-extension/directory - Open Chrome/Firefox and go to extensions page
- Enable "Developer Mode"
- Click "Load unpacked" and select the
phishing-extension/folder - The extension will appear in your toolbar for real-time URL checking
python predict.py "http://suspicious-login-update.com"Detailed Mode (Shows extracted features):
python predict.py "http://suspicious-login-update.com" --mode detailedEndpoint: POST /predict
{
"url": "http://secure-update-login.xyz",
"mode": "fast"
}{
"probability": 98.4,
"message": "The URL has a phishing probability of 98.4%. You may consider a threshold like 50% to classify.",
"timestamp": "2026-04-21T21:00:00.000000"
}{
"url": "http://secure-update-login.xyz",
"mode": "detailed"
}{
"probability": 98.4,
"message": "The URL has a phishing probability of 98.4%. You may consider a threshold like 50% to classify.",
"features": {
"url_length": 31,
"hostname_length": 25,
"count.": 1,
"count-digits": 0,
"count-": 2,
"count@": 0,
"count%": 0,
"subdomain_count": 0,
"suspicious_tld": 1,
"use_of_ip": 0,
"has_https": 0,
"path_length": 0,
"fd_length": 0,
"path_depth": 0,
"query_param_count": 0,
"tld_in_path": 0,
"double_extension": 0,
"has_fragment": 0,
"short_url": 0,
"phish_keyword": 1
},
"timestamp": "2026-04-21T21:00:00.000000"
}Every prediction made by the API is automatically logged into predictions_log.csv for business intelligence.
Logged fields include:
timestamp- When the prediction was madeurl- The analyzed URLprobability- Phishing probability (0-100)- All 20 extracted features
How to integrate with Power BI:
- Open Power BI Desktop
- Select Get Data > Text/CSV and choose
predictions_log.csv - Build dashboards to:
- Track daily phishing detection counts
- Monitor average phishing probability trends
- Analyze feature patterns across detected phishing attempts
- Create alerts for anomalies in detection rates
βββ API.py # FastAPI inference server
βββ feature_extraction.py # 20-feature engineering engine
βββ predict.py # CLI tool for URL testing
βββ evaluate.py # Model evaluation functions
βββ Training_Pipeline.ipynb # Model training notebook
βββ requirements.txt # Python dependencies
β
βββ models/
β βββ best_model.pkl # Trained XGBoost model
β
βββ frontend/ # React Web UI
β βββ src/
β β βββ App.jsx # Main application
β β βββ api.js # API integration
β β βββ components/ # UI components
β β βββ SearchBar.jsx
β β βββ ResultCard.jsx
β β βββ ThemeToggle.jsx
β β βββ ModeSelector.jsx
β βββ package.json
β βββ vite.config.js
β
βββ phishing-extension/ # Browser Extension (Manifest V3)
β βββ manifest.json
β βββ background.js # Service worker
β βββ popup.html
β βββ popup.js
β
βββ Docs/ # Documentation
β βββ Architecture.md # System architecture
β βββ HLD.md # High-level design
β βββ LLD.md # Low-level design
β βββ DPR.md # Detailed project report
β βββ PROJECT_ANALYSIS.md # Project overview
β
βββ README.md # This file
- Python: 3.8 or higher (3.11+ recommended)
- RAM: Minimum 4GB (8GB+ recommended for training)
- CPU: Multi-core processor (for parallel feature extraction)
- Disk: At least 500MB free space
- Node.js: 16+
- npm/yarn: Latest version
- Modern Browser: Chrome, Firefox, Safari, or Edge
- Chrome: Version 88+
- Firefox: Version 89+
- fastapi - REST API framework
- uvicorn - ASGI application server
- scikit-learn - ML models (DT, RF, LR)
- xgboost - Gradient boosting model
- pandas - Data manipulation
- numpy - Numerical computations
- tldextract - URL TLD extraction
- joblib - Model serialization
- tqdm - Progress bars
- requests - HTTP client
- matplotlib, seaborn - Visualization
- react - UI framework
- vite - Build tool
- framer-motion - Animations
- lucide-react - Icons
- recharts - Charts and visualization
| Operation | Time | Hardware |
|---|---|---|
| Single URL prediction | 10-30ms | Intel i7, 16GB RAM |
| 450k URL batch extraction | 5-10 min | 8-core CPU, 16GB RAM |
| Model training (XGBoost) | 15-30 min | 8-core CPU, 16GB RAM |
| API throughput | 100+ req/s | Single instance |
- CORS Policy: Currently set to
"*". In production, restrict to specific domains. - Input Validation: All URLs validated before processing.
- Model Safety: Models stored as pickle files - only load from trusted sources.
- Privacy: URLs are logged to CSV - implement data retention policies as needed.
- Rate Limiting: Consider adding rate limiting for production deployment.
For detailed information, see:
- Architecture.md - System design and components
- HLD.md - High-level design and workflows
- LLD.md - Low-level module specifications
- DPR.md - Detailed project report with technical deep-dive
- PROJECT_ANALYSIS.md - Project overview and feature analysis
To contribute improvements:
- Test changes thoroughly with multiple URL samples
- Update documentation if architecture changes
- Maintain consistent code style
- Add unit tests for new features
This project is licensed under the MIT License - see the LICENSE file for details.
- Dataset: Public phishing URL datasets from Kaggle and research sources
- XGBoost: https://xgboost.readthedocs.io
- FastAPI: https://fastapi.tiangolo.com
- React: https://react.dev
- Power BI: https://powerbi.microsoft.com
For issues, questions, or suggestions:
- Open an issue on GitHub
- Check existing documentation
- Review the API logs in
predictions_log.csv
Last Updated: May 15, 2026
Version: 1.0.0
Status: Production Ready