SamSec007 commited on
Commit
d2e6aef
ยท
verified ยท
1 Parent(s): 138ac15

Final model card: full install guide, usage, features, limitations, troubleshooting

Browse files
Files changed (1) hide show
  1. README.md +209 -71
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 tomorrow. See you there!"
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** on 5,000 held-out samples from a 6-corpus benchmark.
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
- > **The only non-transformer phishing detection model on HuggingFace.**
81
 
82
- ## Quick start
83
 
84
- ```python
85
- from phishbyte import PhishByteEngine
86
 
87
- engine = PhishByteEngine.from_pretrained("SamSec007/phishbyte")
88
- verdict = engine.analyze(raw_email_string)
 
 
 
 
 
 
 
 
 
 
89
 
90
- print(verdict.label) # "phishing"
91
- print(verdict.probability) # 0.9735
92
- print(verdict.confidence) # "high"
93
- print(verdict.layer_used) # 2
94
- print(verdict.feature_weights) # 85-feature attribution
 
 
 
 
 
 
95
  ```
96
 
97
- ## Analyse a real email from Gmail
98
 
99
- 1. Open the email in Gmail
100
- 2. Click โ‹ฎ โ†’ **Show original**
101
- 3. Copy all (Ctrl+A, Ctrl+C)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
  ```python
 
 
 
 
104
  engine = PhishByteEngine.from_pretrained("SamSec007/phishbyte")
105
- verdict = engine.analyze(pasted_raw_email)
106
- print(verdict)
 
 
 
 
 
 
 
 
107
  ```
108
 
109
- Or save as `.eml` and run:
110
 
111
  ```bash
 
 
 
 
 
 
 
112
  python cli.py --file suspicious.eml
 
 
 
 
 
 
113
  ```
114
 
115
- ## What changed in v7
 
 
 
 
 
 
 
 
116
 
117
- - **85 features** (was 29) โ€” added 50 TF-IDF unigrams + 3 BDI features + 2 domain features + 1 composite
118
- - **254K parameters** (was 12K) โ€” deeper residual MLP with two ResBlocks and input skip connection
119
- - **6-dataset training** (was CEAS-2008 only) โ€” Enron, SpamAssassin, Ling-Spam, Nazario, Nigerian Fraud
120
- - **TF-IDF vocabulary** โ€” 50 most discriminative unigrams learned from training corpus. No pretrained LM.
121
- - **Body Domain Identification** โ€” most common link domain mismatch, form action mismatch, external link ratio
122
- - **Display name spoofing** โ€” catches "PayPal Security" \<attacker@evil.com\>
123
- - **Calibrated training metrics** โ€” F1 at Youden-optimal threshold, not naive 0.5 cutoff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
 
125
  ## Architecture
126
 
127
  ```
128
  raw email
129
- โ†’ Layer 1 (6 rule scorers, ~1ms) โ†’ veto gate (obvious phishing only)
130
- โ†’ Layer 2 (residual MLP, ~3ms)
131
- 85 โ†’ 360 โ†’ 180 (ร—2 ResBlock) โ†’ 90 โ†’ 48 โ†’ 1 (sigmoid)
132
- + input-to-output skip connection
133
- โ†’ PhishVerdict {label, probability, confidence, layer_used, feature_weights}
 
 
 
 
 
 
 
 
 
 
 
134
  ```
135
 
136
- ## Benchmarks (5,000 held-out, 6-corpus)
137
 
138
- | Metric | Phish_Byte v7 | DistilBERT fine-tuned |
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 | Examples |
152
- |-------|:-----:|---------|
153
- | Domain | 7 | mismatch, Reply-To diff, brand impersonation, display name spoof, suspicious pattern |
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 txn ID |
157
- | BDI | 3 | most common link domain mismatch, form action mismatch, external link ratio |
158
- | TF-IDF | 50 | top-50 discriminative unigrams from training corpus |
159
- | Composite | 5 | per-module layer scores |
 
 
160
 
161
  ## Training data
162
 
163
- CEAS-2008 + Enron + SpamAssassin + Ling-Spam + Nazario + Nigerian Fraud = **~83K emails** (balanced 50/50).
 
 
 
 
 
 
 
 
 
 
164
 
165
- Same 6-corpus benchmark used by the top DistilBERT model on HuggingFace.
166
 
167
- ## Install
 
 
 
 
168
 
169
- ```bash
170
- pip install huggingface_hub safetensors dnspython
171
- ```
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
- ## Limitations
174
 
175
- - ~5% error rate. Use as one signal in defence-in-depth.
176
- - Trained on English-language phishing (2003โ€“2008 era). Modern attacks and non-English emails will degrade recall.
177
- - SPF validation skipped for training (historical domains). Re-enables at inference on live emails.
178
- - TF-IDF vocabulary is corpus-specific. Retrain on your own data for best domain fit.
 
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