Text Classification
Safetensors
PyTorch
English
phishbyte
phishing-detection
email-security
cybersecurity
security
from-scratch
no-pretrained-weights
cascading-inference
lightweight
explainable-ai
nlp
phishing
spam-detection
malware-detection
threat-detection
email-classification
feature-engineering
interpretable-ml
tfidf
residual-network
Eval Results (legacy)
Final model card: full install guide, usage, features, limitations, troubleshooting
Browse files
README.md
CHANGED
|
@@ -62,120 +62,258 @@ model-index:
|
|
| 62 |
name: Recall
|
| 63 |
widget:
|
| 64 |
- text: "From: PayPal Security <security@paypa1-alert.tk>\nReply-To: attacker@evil-domain.ru\nSubject: URGENT: Your account will be suspended\n\nDear Customer, your PayPal account has been suspended. Verify now at http://paypal-login.tk/verify"
|
| 65 |
-
example_title: "Phishing email"
|
| 66 |
-
- text: "From: alice@company.com\nReply-To: alice@company.com\nSubject: Team lunch tomorrow\n\nHi everyone, lunch is at noon
|
| 67 |
-
example_title: "Legitimate email"
|
| 68 |
---
|
| 69 |
|
| 70 |
# Phish_Byte v7
|
| 71 |
|
| 72 |
-
A from-scratch PyTorch model for **email phishing detection**.
|
| 73 |
|
| 74 |
-
**F1 0.950**
|
| 75 |
-
**254K parameters** (โ260ร smaller than DistilBERT).
|
| 76 |
-
**995 emails/sec** on a laptop GPU.
|
| 77 |
-
**85 engineered features** (35 rule-based + 50 TF-IDF learned from corpus).
|
| 78 |
-
Every verdict explains itself with full per-feature attribution.
|
| 79 |
|
| 80 |
-
|
| 81 |
|
| 82 |
-
##
|
| 83 |
|
| 84 |
-
|
| 85 |
-
from phishbyte import PhishByteEngine
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
```
|
| 96 |
|
| 97 |
-
##
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
engine = PhishByteEngine.from_pretrained("SamSec007/phishbyte")
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
```
|
| 108 |
|
| 109 |
-
|
| 110 |
|
| 111 |
```bash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
python cli.py --file suspicious.eml
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
```
|
| 114 |
|
| 115 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
## Architecture
|
| 126 |
|
| 127 |
```
|
| 128 |
raw email
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
โ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
```
|
| 135 |
|
| 136 |
-
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|--------|:------------:|:---------------------:|
|
| 140 |
-
| F1 score | **0.950** | ~0.967 |
|
| 141 |
-
| Accuracy | **94.94%** | ~97% |
|
| 142 |
-
| Parameters | **254K** | 66,000,000 |
|
| 143 |
-
| Model size | **~1 MB** | ~263 MB |
|
| 144 |
-
| Throughput (GPU) | **995/sec** | ~50/sec |
|
| 145 |
-
| GPU required | **No** | Practically yes |
|
| 146 |
-
| Header + SPF analysis | **Yes** | No |
|
| 147 |
-
| Per-feature attribution | **85 features** | Token-level SHAP |
|
| 148 |
|
| 149 |
## Feature groups (85 total)
|
| 150 |
|
| 151 |
-
| Group | Count |
|
| 152 |
-
|-------|:-----:|---------|
|
| 153 |
-
| Domain | 7 |
|
| 154 |
-
| URL + Body | 10 | HTTPS ratio, anchor mismatch, urgency (normalized), caps ratio, digit ratio |
|
| 155 |
-
| SPF | 3 | fail, no record, no IP |
|
| 156 |
-
| Subject | 7 | urgency, security theme, brand, currency, all caps, fake RE, fake
|
| 157 |
-
| BDI | 3 |
|
| 158 |
-
| TF-IDF | 50 |
|
| 159 |
-
| Composite | 5 |
|
|
|
|
|
|
|
| 160 |
|
| 161 |
## Training data
|
| 162 |
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
-
|
| 166 |
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
-
##
|
| 174 |
|
| 175 |
-
-
|
| 176 |
-
-
|
| 177 |
-
-
|
| 178 |
-
-
|
|
|
|
| 179 |
|
| 180 |
## Citation
|
| 181 |
|
|
|
|
| 62 |
name: Recall
|
| 63 |
widget:
|
| 64 |
- text: "From: PayPal Security <security@paypa1-alert.tk>\nReply-To: attacker@evil-domain.ru\nSubject: URGENT: Your account will be suspended\n\nDear Customer, your PayPal account has been suspended. Verify now at http://paypal-login.tk/verify"
|
| 65 |
+
example_title: "Phishing email example"
|
| 66 |
+
- text: "From: alice@company.com\nReply-To: alice@company.com\nSubject: Team lunch tomorrow\n\nHi everyone, lunch is at noon in the usual spot. See you there!"
|
| 67 |
+
example_title: "Legitimate email example"
|
| 68 |
---
|
| 69 |
|
| 70 |
# Phish_Byte v7
|
| 71 |
|
| 72 |
+
A from-scratch PyTorch model for **email phishing detection** โ no pretrained weights, no transformers, no fine-tuning.
|
| 73 |
|
| 74 |
+
**F1 0.950** ยท **254K parameters** (260ร smaller than DistilBERT) ยท **995 emails/sec** on a laptop GPU ยท **85 engineered features** ยท every verdict explains itself.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
+
---
|
| 77 |
|
| 78 |
+
## What makes this different
|
| 79 |
|
| 80 |
+
Every other phishing detection model on HuggingFace fine-tunes a transformer (DistilBERT, BERT, RoBERTa). Phish_Byte is the only one built from scratch:
|
|
|
|
| 81 |
|
| 82 |
+
| | Phish_Byte v7 | DistilBERT fine-tuned |
|
| 83 |
+
|---|:---:|:---:|
|
| 84 |
+
| F1 score | 0.950 | ~0.967 |
|
| 85 |
+
| Parameters | **254K** | 66,000,000 |
|
| 86 |
+
| Model size | **~1 MB** | ~263 MB |
|
| 87 |
+
| Throughput (GPU) | **995/sec** | ~50/sec |
|
| 88 |
+
| GPU required | **No** | Practically yes |
|
| 89 |
+
| Header + SPF analysis | **Yes** | No |
|
| 90 |
+
| Explainability | **85 features** | Token-level SHAP |
|
| 91 |
+
| Pretrained weights | **None** | DistilBERT |
|
| 92 |
+
|
| 93 |
+
The F1 gap is ~1.7 points. The size and throughput advantage is 260ร and 20ร respectively. The header analysis (SPF, display-name spoofing, most-common link domain) is unique to Phish_Byte.
|
| 94 |
|
| 95 |
+
---
|
| 96 |
+
|
| 97 |
+
## โ ๏ธ Install โ read this first
|
| 98 |
+
|
| 99 |
+
**`pip install phishbyte` does not work.** There is no PyPI package yet (it is on the roadmap). The only working path is cloning the source repository.
|
| 100 |
+
|
| 101 |
+
### Step 1 โ Clone
|
| 102 |
+
|
| 103 |
+
```bash
|
| 104 |
+
git clone https://github.com/AnonymousSingh-007/Phish_Byte.git
|
| 105 |
+
cd Phish_Byte
|
| 106 |
```
|
| 107 |
|
| 108 |
+
### Step 2 โ Create environment
|
| 109 |
|
| 110 |
+
```bash
|
| 111 |
+
python -m venv venv
|
| 112 |
+
|
| 113 |
+
# Windows:
|
| 114 |
+
.\venv\Scripts\Activate.ps1
|
| 115 |
+
|
| 116 |
+
# Mac / Linux:
|
| 117 |
+
source venv/bin/activate
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
### Step 3 โ Install dependencies
|
| 121 |
+
|
| 122 |
+
```bash
|
| 123 |
+
pip install -r requirements.txt
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
Minimal deps: `torch`, `huggingface_hub`, `safetensors`, `dnspython`, `numpy`, `pandas`.
|
| 127 |
+
|
| 128 |
+
For GPU acceleration (RTX 50-series / Blackwell):
|
| 129 |
+
```bash
|
| 130 |
+
pip install torch --index-url https://download.pytorch.org/whl/cu128
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
### Step 4 โ Verify everything works
|
| 134 |
+
|
| 135 |
+
```bash
|
| 136 |
+
python verify_install.py
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
This checks every dependency and every source file, then does a live test-download from this Hub repo. **Run this before reporting any issue** โ it tells you exactly what is missing.
|
| 140 |
+
|
| 141 |
+
Expected output (all green):
|
| 142 |
+
```
|
| 143 |
+
โ
Python 3.11.x
|
| 144 |
+
โ
torch
|
| 145 |
+
โ
huggingface_hub
|
| 146 |
+
โ
safetensors
|
| 147 |
+
โ
dns
|
| 148 |
+
โ
numpy
|
| 149 |
+
โ
pandas
|
| 150 |
+
โ
phishbyte/__init__.py
|
| 151 |
+
... (all source files)
|
| 152 |
+
โ
from phishbyte import PhishByteEngine โ works
|
| 153 |
+
โ
Model loaded from Hub successfully
|
| 154 |
+
โ
INSTALLATION VERIFIED
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
---
|
| 158 |
+
|
| 159 |
+
## Usage
|
| 160 |
+
|
| 161 |
+
### Run from Python (inside the cloned folder)
|
| 162 |
|
| 163 |
```python
|
| 164 |
+
from phishbyte import PhishByteEngine
|
| 165 |
+
|
| 166 |
+
# Downloads ~1 MB of weights from this Hub repo on first call
|
| 167 |
+
# Cached locally after that โ instant on every subsequent call
|
| 168 |
engine = PhishByteEngine.from_pretrained("SamSec007/phishbyte")
|
| 169 |
+
|
| 170 |
+
# Analyze any raw email string (headers + body)
|
| 171 |
+
verdict = engine.analyze(raw_email_string)
|
| 172 |
+
|
| 173 |
+
print(verdict.label) # "phishing" or "legitimate"
|
| 174 |
+
print(verdict.probability) # P(phish) in [0.0, 1.0]
|
| 175 |
+
print(verdict.confidence) # "high" / "medium" / "low"
|
| 176 |
+
print(verdict.layer_used) # 1 = rules decided, 2 = MLP decided
|
| 177 |
+
print(verdict.feature_weights) # dict of 85 feature scores
|
| 178 |
+
print(verdict) # formatted terminal display
|
| 179 |
```
|
| 180 |
|
| 181 |
+
### CLI
|
| 182 |
|
| 183 |
```bash
|
| 184 |
+
# Demo on a known phishing sample from training data
|
| 185 |
+
python cli.py --demo phish
|
| 186 |
+
|
| 187 |
+
# Demo on a known legitimate sample
|
| 188 |
+
python cli.py --demo legit
|
| 189 |
+
|
| 190 |
+
# Analyze a .eml file
|
| 191 |
python cli.py --file suspicious.eml
|
| 192 |
+
|
| 193 |
+
# Paste raw email interactively
|
| 194 |
+
python cli.py
|
| 195 |
+
|
| 196 |
+
# JSON output (for scripting)
|
| 197 |
+
python cli.py --demo --json
|
| 198 |
```
|
| 199 |
|
| 200 |
+
### Analyze a real email from Gmail
|
| 201 |
+
|
| 202 |
+
1. Open the email in Gmail
|
| 203 |
+
2. Click **โฎ** โ **Show original**
|
| 204 |
+
3. Select all (Ctrl+A), copy (Ctrl+C)
|
| 205 |
+
4. Run `python cli.py`, paste when prompted
|
| 206 |
+
5. Press Enter then **Ctrl+Z** (Windows) or **Ctrl+D** (Mac/Linux) to submit
|
| 207 |
+
|
| 208 |
+
### Understanding the verdict
|
| 209 |
|
| 210 |
+
```python
|
| 211 |
+
PhishVerdict(
|
| 212 |
+
label = "phishing",
|
| 213 |
+
probability = 0.9735, # how confident the model is
|
| 214 |
+
confidence = "high", # high โฅ 0.795, low โค 0.695, medium in-between
|
| 215 |
+
layer_used = 2, # 1 = rules veto, 2 = MLP decision
|
| 216 |
+
feature_weights = {
|
| 217 |
+
# Which signals fired and how strongly
|
| 218 |
+
"display_name_mismatch": 1.00, # "PayPal" in name, attacker domain
|
| 219 |
+
"mcld_mismatch": 1.00, # most common link domain โ sender
|
| 220 |
+
"spf_fail": 1.00, # SPF DNS check failed
|
| 221 |
+
"tfidf_verify": 0.82, # high TF-IDF score for "verify"
|
| 222 |
+
"external_link_ratio": 0.90, # 90% of links go to external domains
|
| 223 |
+
"urgency_score": 0.65, # urgency keywords in body
|
| 224 |
+
...
|
| 225 |
+
},
|
| 226 |
+
detail = "MLP probability: 97.35%. Layer 1 score: 19.76%.",
|
| 227 |
+
)
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
---
|
| 231 |
|
| 232 |
## Architecture
|
| 233 |
|
| 234 |
```
|
| 235 |
raw email
|
| 236 |
+
โ
|
| 237 |
+
โผ
|
| 238 |
+
Layer 1 โ 6 rule scorers (~1 ms)
|
| 239 |
+
domain ยท URL+body ยท SPF ยท subject ยท BDI ยท TF-IDF
|
| 240 |
+
โ 85-dimensional feature vector
|
| 241 |
+
โ composite score โฅ 0.85? โ fast PHISHING verdict (obvious cases)
|
| 242 |
+
โ
|
| 243 |
+
โผ (everything else โ ~100% of real traffic)
|
| 244 |
+
Layer 2 โ residual MLP (~3 ms)
|
| 245 |
+
85 โ 360 โ 180 (ร2 ResBlock) โ 90 โ 48 โ 1 (sigmoid)
|
| 246 |
+
254K parameters ยท randomly initialized ยท trained from scratch
|
| 247 |
+
+ input-to-output skip connection
|
| 248 |
+
โ
|
| 249 |
+
โผ
|
| 250 |
+
PhishVerdict
|
| 251 |
+
{ label ยท probability ยท confidence ยท layer_used ยท feature_weights }
|
| 252 |
```
|
| 253 |
|
| 254 |
+
The Layer 1 โ Layer 2 routing is intentional: cheap signals handle the clear cases, the neural network handles the ambiguous ones. `layer_used` tells you which path ran for each email โ useful for latency auditing and cost accounting at scale.
|
| 255 |
|
| 256 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
|
| 258 |
## Feature groups (85 total)
|
| 259 |
|
| 260 |
+
| Group | Count | What it captures |
|
| 261 |
+
|-------|:-----:|-----------------|
|
| 262 |
+
| Domain | 7 | From/Reply-To/Return-Path mismatch, freemail, brand impersonation, display name spoof, suspicious domain pattern |
|
| 263 |
+
| URL + Body | 10 | HTTPS ratio, anchor mismatch, suspicious TLD, urgency (normalized per 100 words), link density, caps ratio, digit ratio, special chars, avg word length, HTML/text ratio |
|
| 264 |
+
| SPF | 3 | SPF fail, no record, no sending IP |
|
| 265 |
+
| Subject | 7 | urgency, security theme, brand name, currency, all caps, fake RE prefix, fake transaction ID |
|
| 266 |
+
| BDI | 3 | Most common link domain mismatch, form action domain mismatch, external link ratio |
|
| 267 |
+
| TF-IDF | 50 | Top-50 discriminative unigrams learned from training corpus (no pretrained embeddings) |
|
| 268 |
+
| Composite | 5 | Per-module layer scores |
|
| 269 |
+
|
| 270 |
+
---
|
| 271 |
|
| 272 |
## Training data
|
| 273 |
|
| 274 |
+
| Dataset | Emails | Era |
|
| 275 |
+
|---------|-------:|-----|
|
| 276 |
+
| CEAS-2008 | 39,154 | 2008 |
|
| 277 |
+
| Enron | ~29K | 1999โ2002 |
|
| 278 |
+
| SpamAssassin | ~10K | 2002โ2003 |
|
| 279 |
+
| Nigerian Fraud | ~3.3K | 2000s |
|
| 280 |
+
| Nazario | ~1.5K | 2000s |
|
| 281 |
+
| Ling-Spam | ~2.8K | 1990sโ2000s |
|
| 282 |
+
| **Total (after dedup)** | **~83K** | **balanced ~50/50** |
|
| 283 |
+
|
| 284 |
+
---
|
| 285 |
|
| 286 |
+
## Limitations โ read before deploying
|
| 287 |
|
| 288 |
+
- **Training data is 15+ years old.** These corpora predate OAuth phishing, QR code lures, redirect chains through Google Docs / Dropbox / OneDrive, and modern adversarial HTML. Recall on 2020s-era attacks is untested and likely degraded.
|
| 289 |
+
- **TF-IDF vocabulary is era-locked.** Learned from 2000s corpora. Modern phishing vocabulary is not represented.
|
| 290 |
+
- **No adversarial robustness testing has been performed.** An attacker aware of the feature set could craft bypasses. Use as one signal in a defence-in-depth stack, not a standalone gate.
|
| 291 |
+
- **F1 0.950 is self-reported** on a held-out split of the training corpus, not independently verified.
|
| 292 |
+
- **English-language only.**
|
| 293 |
|
| 294 |
+
---
|
| 295 |
+
|
| 296 |
+
## Troubleshooting
|
| 297 |
+
|
| 298 |
+
Run `python verify_install.py` first โ it catches nearly every issue below automatically.
|
| 299 |
+
|
| 300 |
+
| Error | Fix |
|
| 301 |
+
|-------|-----|
|
| 302 |
+
| `ModuleNotFoundError: No module named 'phishbyte'` | Not in cloned folder or venv not activated |
|
| 303 |
+
| `ImportError: cannot import name 'X'` | `git pull origin main` |
|
| 304 |
+
| `pip install phishbyte` fails | No PyPI package yet โ clone the repo |
|
| 305 |
+
| `NameError: save_model_as_safetensor` | `pip install safetensors` |
|
| 306 |
+
| Windows symlink warning | Harmless โ ignore or enable Developer Mode |
|
| 307 |
+
|
| 308 |
+
---
|
| 309 |
|
| 310 |
+
## Roadmap
|
| 311 |
|
| 312 |
+
- [ ] Retrain on 2020โ2024 phishing data (PhishTank, OpenPhish, APWG eCrime)
|
| 313 |
+
- [ ] Adversarial robustness test suite
|
| 314 |
+
- [ ] HuggingFace Space demo (zero-install browser trial)
|
| 315 |
+
- [ ] PyPI package (`pip install phishbyte`)
|
| 316 |
+
- [ ] arXiv preprint
|
| 317 |
|
| 318 |
## Citation
|
| 319 |
|