phishlens 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- phishlens-0.1.0/LICENSE +21 -0
- phishlens-0.1.0/PKG-INFO +174 -0
- phishlens-0.1.0/README.md +153 -0
- phishlens-0.1.0/phishlens/__init__.py +12 -0
- phishlens-0.1.0/phishlens/__main__.py +5 -0
- phishlens-0.1.0/phishlens/analyzer.py +135 -0
- phishlens-0.1.0/phishlens/checks.py +319 -0
- phishlens-0.1.0/phishlens/cli.py +91 -0
- phishlens-0.1.0/phishlens/corpus.py +285 -0
- phishlens-0.1.0/phishlens/domains.py +183 -0
- phishlens-0.1.0/phishlens/evaluation.py +74 -0
- phishlens-0.1.0/phishlens/parser.py +149 -0
- phishlens-0.1.0/phishlens.egg-info/PKG-INFO +174 -0
- phishlens-0.1.0/phishlens.egg-info/SOURCES.txt +19 -0
- phishlens-0.1.0/phishlens.egg-info/dependency_links.txt +1 -0
- phishlens-0.1.0/phishlens.egg-info/entry_points.txt +2 -0
- phishlens-0.1.0/phishlens.egg-info/requires.txt +3 -0
- phishlens-0.1.0/phishlens.egg-info/top_level.txt +1 -0
- phishlens-0.1.0/pyproject.toml +35 -0
- phishlens-0.1.0/setup.cfg +4 -0
- phishlens-0.1.0/tests/test_phishlens.py +139 -0
phishlens-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arpita Haque
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
phishlens-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: phishlens
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Explainable, offline phishing email analyzer: SPF/DKIM/DMARC, look-alike domains, link tricks, risky attachments and pressure language, with a plain-English risk report.
|
|
5
|
+
Author-email: Arpita Haque <arpitakaiser@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/arpitahaque/phishlens
|
|
8
|
+
Project-URL: Issues, https://github.com/arpitahaque/phishlens/issues
|
|
9
|
+
Keywords: phishing,email-security,spf,dkim,dmarc,security-awareness,soc
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Topic :: Security
|
|
12
|
+
Classifier: Topic :: Communications :: Email
|
|
13
|
+
Classifier: Intended Audience :: Information Technology
|
|
14
|
+
Classifier: Intended Audience :: System Administrators
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Provides-Extra: test
|
|
19
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# PhishLens
|
|
23
|
+
|
|
24
|
+
[](https://github.com/arpitahaque/phishlens/actions/workflows/tests.yml)
|
|
25
|
+

|
|
26
|
+

|
|
27
|
+
[](https://github.com/arpitahaque/phishlens/blob/main/LICENSE)
|
|
28
|
+
|
|
29
|
+
**An explainable, offline phishing email analyzer.** Give PhishLens a raw email (`.eml`) and it checks the
|
|
30
|
+
sender's authentication, looks for impersonation and deceptive links, inspects attachments and reads the
|
|
31
|
+
language for pressure tactics. It then gives a 0-100 risk score and explains every finding in plain English,
|
|
32
|
+
so a helpdesk analyst, a SOC trainee or an ordinary user can see *why* a message is dangerous.
|
|
33
|
+
|
|
34
|
+

|
|
35
|
+
|
|
36
|
+
## Why
|
|
37
|
+
|
|
38
|
+
Phishing is still the most common way attackers get in, and most of the people who first see a reported
|
|
39
|
+
email are helpdesk staff, not malware analysts. Commercial tools often return a verdict without showing their
|
|
40
|
+
reasoning. PhishLens is small, readable, has no dependencies and never sends the message anywhere, which
|
|
41
|
+
matters when the email may contain patient, student or company data.
|
|
42
|
+
|
|
43
|
+
## What it checks
|
|
44
|
+
|
|
45
|
+
| Category | Signals |
|
|
46
|
+
|---|---|
|
|
47
|
+
| **Authentication** | SPF, DKIM and DMARC results from the receiving server's `Authentication-Results` header |
|
|
48
|
+
| **Sender** | Look-alike sender domains, brand names in the display name, fake addresses inside the display name, Reply-To pointing elsewhere, brand mail sent from free accounts |
|
|
49
|
+
| **Links** | Link text that shows one site but opens another, raw IP links, the `user@host` trick, punycode (`xn--`) domains, look-alike domains, URL shorteners, abused top-level domains, login pages on unrelated sites |
|
|
50
|
+
| **Attachments** | Executables, disguised file types (`invoice.pdf.exe`), HTML forms, macro-enabled Office files, archives that hide executables or come with a password |
|
|
51
|
+
| **Content** | Urgency and threats, requests for passwords or account details, gift cards, wire transfers and bank-detail changes, generic greetings |
|
|
52
|
+
|
|
53
|
+
Look-alike detection catches character swaps (`paypa1`, `rnicrosoft`), small misspellings (`docusiqn`),
|
|
54
|
+
brand names with extra words (`paypal-security.com`), brand names used as a subdomain of another site
|
|
55
|
+
(`paypal.com.account-verify.xyz`) and non-ASCII characters, without flagging real infrastructure such as
|
|
56
|
+
`amazonaws.com` or unrelated names such as `applebees.com`.
|
|
57
|
+
|
|
58
|
+
## Quick start
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
git clone https://github.com/arpitahaque/phishlens.git
|
|
62
|
+
cd phishlens
|
|
63
|
+
pip install -e .
|
|
64
|
+
|
|
65
|
+
phishlens analyze samples/01_paypal_lookalike.eml # readable report
|
|
66
|
+
phishlens analyze samples/*.eml # several messages at once
|
|
67
|
+
phishlens analyze message.eml -f md -o report.md # Markdown report
|
|
68
|
+
phishlens analyze message.eml -f json # JSON for other tools
|
|
69
|
+
phishlens analyze message.eml --exit-code # exit 0 low, 1 suspicious, 2 phishing
|
|
70
|
+
phishlens demo # built-in examples
|
|
71
|
+
phishlens evaluate # accuracy on the held-out split
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
To get an `.eml` file: in Outlook or Thunderbird use *Save As*; in Gmail open the message menu and choose
|
|
75
|
+
*Download message*. Analyze the message as received so the authentication headers are included.
|
|
76
|
+
|
|
77
|
+
Use it from Python:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from phishlens import analyze_file
|
|
81
|
+
|
|
82
|
+
report = analyze_file("message.eml")
|
|
83
|
+
print(report.score, report.label)
|
|
84
|
+
for f in report.findings:
|
|
85
|
+
print(f.points, f.title, "-", f.detail)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
See a full [sample report](https://github.com/arpitahaque/phishlens/blob/main/docs/sample_report.md).
|
|
89
|
+
|
|
90
|
+
## Scoring
|
|
91
|
+
|
|
92
|
+
Each finding adds points (for example DMARC failure +30, look-alike sender domain +35, executable attachment
|
|
93
|
+
+40, pressure language +8 to +15). The total is capped at 100.
|
|
94
|
+
|
|
95
|
+
| Score | Verdict | Advice |
|
|
96
|
+
|---:|---|---|
|
|
97
|
+
| 0-24 | Low risk | No strong warning signs |
|
|
98
|
+
| 25-54 | Suspicious | Do not click; verify with the sender through a known channel |
|
|
99
|
+
| 55-100 | Likely phishing | Do not click, reply or open attachments; report it |
|
|
100
|
+
|
|
101
|
+
Weak signals score low on purpose. A bounce address that differs from the From domain is normal for
|
|
102
|
+
newsletters, so it adds only 5 points, and missing authentication headers are shown as a note, not a penalty.
|
|
103
|
+
|
|
104
|
+
## Evaluation
|
|
105
|
+
|
|
106
|
+
PhishLens was tuned on a synthetic **development** split and measured on a separate **test** split built from
|
|
107
|
+
different templates, brands, domains and wording. Both splits are generated by
|
|
108
|
+
[`phishlens/corpus.py`](https://github.com/arpitahaque/phishlens/blob/main/phishlens/corpus.py) and include hard cases:
|
|
109
|
+
phishing sent from a compromised real account (passes SPF, DKIM and DMARC) and legitimate mail that sounds
|
|
110
|
+
urgent, comes from a mailing service or is sent from a personal Gmail account. A message counts as flagged
|
|
111
|
+
when it is Suspicious or Likely phishing.
|
|
112
|
+
|
|
113
|
+
| Method (test split, 300 emails) | Precision | Recall | F1 | False-positive rate |
|
|
114
|
+
|---|---:|---:|---:|---:|
|
|
115
|
+
| Authentication-only baseline (flag if SPF, DKIM or DMARC fails) | 100.0% | 48.0% | 64.9% | 0.0% |
|
|
116
|
+
| **PhishLens** | **100.0%** | **88.0%** | **93.6%** | **0.0%** |
|
|
117
|
+
|
|
118
|
+
PhishLens catches nearly twice as much phishing as authentication checks alone, with no false alarms on the
|
|
119
|
+
legitimate messages. Every miss is in the *compromised account* family: a real, authenticated sender with a
|
|
120
|
+
plain link and no pressure language. Per-family results are in
|
|
121
|
+
[docs/evaluation.md](https://github.com/arpitahaque/phishlens/blob/main/docs/evaluation.md); reproduce them with
|
|
122
|
+
`phishlens evaluate`.
|
|
123
|
+
|
|
124
|
+
**Read these numbers with care.** The corpus is synthetic and written by the same person who wrote the checks,
|
|
125
|
+
so it is far cleaner than a real inbox. Real-world accuracy will be lower, and the next step is testing on
|
|
126
|
+
public phishing collections and on a set of real reported messages.
|
|
127
|
+
|
|
128
|
+
## Limitations
|
|
129
|
+
|
|
130
|
+
- Works on headers the receiving server already wrote; it does not query DNS or re-verify DKIM signatures.
|
|
131
|
+
- Uses a built-in brand list and a short public-suffix list instead of live threat-intelligence feeds.
|
|
132
|
+
- Does not open links, detonate attachments or run machine learning, so new or very targeted attacks
|
|
133
|
+
(especially from compromised accounts) can score low.
|
|
134
|
+
- English-language content rules only.
|
|
135
|
+
|
|
136
|
+
## Related work
|
|
137
|
+
|
|
138
|
+
PhishLens is a learning and triage tool, not a replacement for a mail gateway. Similar open and free tools
|
|
139
|
+
include [eml_analyzer](https://github.com/ninoseki/eml_analyzer) (web app that parses `.eml` files and looks
|
|
140
|
+
up indicators in threat-intelligence services), [ThePhish](https://github.com/emalderson/ThePhish)
|
|
141
|
+
(automated analysis built on TheHive, Cortex and MISP), Google's
|
|
142
|
+
[Messageheader](https://toolbox.googleapps.com/apps/messageheader/) and Microsoft's Message Header Analyzer
|
|
143
|
+
(header and delivery-path viewers). PhishLens differs by running fully offline with no dependencies,
|
|
144
|
+
combining header, link, attachment and language checks into one scored report, and explaining each finding
|
|
145
|
+
for non-specialists.
|
|
146
|
+
|
|
147
|
+
## Project layout
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
phishlens/
|
|
151
|
+
parser.py raw email -> headers, bodies, links, attachments
|
|
152
|
+
domains.py registrable domains, punycode, look-alike detection
|
|
153
|
+
checks.py the individual checks and their point values
|
|
154
|
+
analyzer.py scoring, verdicts and text / Markdown / JSON reports
|
|
155
|
+
corpus.py synthetic dev and held-out test emails
|
|
156
|
+
evaluation.py precision, recall and baseline comparison
|
|
157
|
+
cli.py command-line interface
|
|
158
|
+
samples/ example .eml files
|
|
159
|
+
tests/ pytest suite
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Citation
|
|
163
|
+
|
|
164
|
+
If you use PhishLens, please cite it using the metadata in
|
|
165
|
+
[CITATION.cff](https://github.com/arpitahaque/phishlens/blob/main/CITATION.cff).
|
|
166
|
+
|
|
167
|
+
## Author
|
|
168
|
+
|
|
169
|
+
**Arpita Haque** - B.S. Computer Information Technology (cybersecurity minor), Minnesota State University
|
|
170
|
+
Moorhead. [GitHub](https://github.com/arpitahaque) · [ORCID](https://orcid.org/0009-0001-7853-3611)
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
MIT
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# PhishLens
|
|
2
|
+
|
|
3
|
+
[](https://github.com/arpitahaque/phishlens/actions/workflows/tests.yml)
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
[](https://github.com/arpitahaque/phishlens/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
**An explainable, offline phishing email analyzer.** Give PhishLens a raw email (`.eml`) and it checks the
|
|
9
|
+
sender's authentication, looks for impersonation and deceptive links, inspects attachments and reads the
|
|
10
|
+
language for pressure tactics. It then gives a 0-100 risk score and explains every finding in plain English,
|
|
11
|
+
so a helpdesk analyst, a SOC trainee or an ordinary user can see *why* a message is dangerous.
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
## Why
|
|
16
|
+
|
|
17
|
+
Phishing is still the most common way attackers get in, and most of the people who first see a reported
|
|
18
|
+
email are helpdesk staff, not malware analysts. Commercial tools often return a verdict without showing their
|
|
19
|
+
reasoning. PhishLens is small, readable, has no dependencies and never sends the message anywhere, which
|
|
20
|
+
matters when the email may contain patient, student or company data.
|
|
21
|
+
|
|
22
|
+
## What it checks
|
|
23
|
+
|
|
24
|
+
| Category | Signals |
|
|
25
|
+
|---|---|
|
|
26
|
+
| **Authentication** | SPF, DKIM and DMARC results from the receiving server's `Authentication-Results` header |
|
|
27
|
+
| **Sender** | Look-alike sender domains, brand names in the display name, fake addresses inside the display name, Reply-To pointing elsewhere, brand mail sent from free accounts |
|
|
28
|
+
| **Links** | Link text that shows one site but opens another, raw IP links, the `user@host` trick, punycode (`xn--`) domains, look-alike domains, URL shorteners, abused top-level domains, login pages on unrelated sites |
|
|
29
|
+
| **Attachments** | Executables, disguised file types (`invoice.pdf.exe`), HTML forms, macro-enabled Office files, archives that hide executables or come with a password |
|
|
30
|
+
| **Content** | Urgency and threats, requests for passwords or account details, gift cards, wire transfers and bank-detail changes, generic greetings |
|
|
31
|
+
|
|
32
|
+
Look-alike detection catches character swaps (`paypa1`, `rnicrosoft`), small misspellings (`docusiqn`),
|
|
33
|
+
brand names with extra words (`paypal-security.com`), brand names used as a subdomain of another site
|
|
34
|
+
(`paypal.com.account-verify.xyz`) and non-ASCII characters, without flagging real infrastructure such as
|
|
35
|
+
`amazonaws.com` or unrelated names such as `applebees.com`.
|
|
36
|
+
|
|
37
|
+
## Quick start
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
git clone https://github.com/arpitahaque/phishlens.git
|
|
41
|
+
cd phishlens
|
|
42
|
+
pip install -e .
|
|
43
|
+
|
|
44
|
+
phishlens analyze samples/01_paypal_lookalike.eml # readable report
|
|
45
|
+
phishlens analyze samples/*.eml # several messages at once
|
|
46
|
+
phishlens analyze message.eml -f md -o report.md # Markdown report
|
|
47
|
+
phishlens analyze message.eml -f json # JSON for other tools
|
|
48
|
+
phishlens analyze message.eml --exit-code # exit 0 low, 1 suspicious, 2 phishing
|
|
49
|
+
phishlens demo # built-in examples
|
|
50
|
+
phishlens evaluate # accuracy on the held-out split
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
To get an `.eml` file: in Outlook or Thunderbird use *Save As*; in Gmail open the message menu and choose
|
|
54
|
+
*Download message*. Analyze the message as received so the authentication headers are included.
|
|
55
|
+
|
|
56
|
+
Use it from Python:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from phishlens import analyze_file
|
|
60
|
+
|
|
61
|
+
report = analyze_file("message.eml")
|
|
62
|
+
print(report.score, report.label)
|
|
63
|
+
for f in report.findings:
|
|
64
|
+
print(f.points, f.title, "-", f.detail)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
See a full [sample report](https://github.com/arpitahaque/phishlens/blob/main/docs/sample_report.md).
|
|
68
|
+
|
|
69
|
+
## Scoring
|
|
70
|
+
|
|
71
|
+
Each finding adds points (for example DMARC failure +30, look-alike sender domain +35, executable attachment
|
|
72
|
+
+40, pressure language +8 to +15). The total is capped at 100.
|
|
73
|
+
|
|
74
|
+
| Score | Verdict | Advice |
|
|
75
|
+
|---:|---|---|
|
|
76
|
+
| 0-24 | Low risk | No strong warning signs |
|
|
77
|
+
| 25-54 | Suspicious | Do not click; verify with the sender through a known channel |
|
|
78
|
+
| 55-100 | Likely phishing | Do not click, reply or open attachments; report it |
|
|
79
|
+
|
|
80
|
+
Weak signals score low on purpose. A bounce address that differs from the From domain is normal for
|
|
81
|
+
newsletters, so it adds only 5 points, and missing authentication headers are shown as a note, not a penalty.
|
|
82
|
+
|
|
83
|
+
## Evaluation
|
|
84
|
+
|
|
85
|
+
PhishLens was tuned on a synthetic **development** split and measured on a separate **test** split built from
|
|
86
|
+
different templates, brands, domains and wording. Both splits are generated by
|
|
87
|
+
[`phishlens/corpus.py`](https://github.com/arpitahaque/phishlens/blob/main/phishlens/corpus.py) and include hard cases:
|
|
88
|
+
phishing sent from a compromised real account (passes SPF, DKIM and DMARC) and legitimate mail that sounds
|
|
89
|
+
urgent, comes from a mailing service or is sent from a personal Gmail account. A message counts as flagged
|
|
90
|
+
when it is Suspicious or Likely phishing.
|
|
91
|
+
|
|
92
|
+
| Method (test split, 300 emails) | Precision | Recall | F1 | False-positive rate |
|
|
93
|
+
|---|---:|---:|---:|---:|
|
|
94
|
+
| Authentication-only baseline (flag if SPF, DKIM or DMARC fails) | 100.0% | 48.0% | 64.9% | 0.0% |
|
|
95
|
+
| **PhishLens** | **100.0%** | **88.0%** | **93.6%** | **0.0%** |
|
|
96
|
+
|
|
97
|
+
PhishLens catches nearly twice as much phishing as authentication checks alone, with no false alarms on the
|
|
98
|
+
legitimate messages. Every miss is in the *compromised account* family: a real, authenticated sender with a
|
|
99
|
+
plain link and no pressure language. Per-family results are in
|
|
100
|
+
[docs/evaluation.md](https://github.com/arpitahaque/phishlens/blob/main/docs/evaluation.md); reproduce them with
|
|
101
|
+
`phishlens evaluate`.
|
|
102
|
+
|
|
103
|
+
**Read these numbers with care.** The corpus is synthetic and written by the same person who wrote the checks,
|
|
104
|
+
so it is far cleaner than a real inbox. Real-world accuracy will be lower, and the next step is testing on
|
|
105
|
+
public phishing collections and on a set of real reported messages.
|
|
106
|
+
|
|
107
|
+
## Limitations
|
|
108
|
+
|
|
109
|
+
- Works on headers the receiving server already wrote; it does not query DNS or re-verify DKIM signatures.
|
|
110
|
+
- Uses a built-in brand list and a short public-suffix list instead of live threat-intelligence feeds.
|
|
111
|
+
- Does not open links, detonate attachments or run machine learning, so new or very targeted attacks
|
|
112
|
+
(especially from compromised accounts) can score low.
|
|
113
|
+
- English-language content rules only.
|
|
114
|
+
|
|
115
|
+
## Related work
|
|
116
|
+
|
|
117
|
+
PhishLens is a learning and triage tool, not a replacement for a mail gateway. Similar open and free tools
|
|
118
|
+
include [eml_analyzer](https://github.com/ninoseki/eml_analyzer) (web app that parses `.eml` files and looks
|
|
119
|
+
up indicators in threat-intelligence services), [ThePhish](https://github.com/emalderson/ThePhish)
|
|
120
|
+
(automated analysis built on TheHive, Cortex and MISP), Google's
|
|
121
|
+
[Messageheader](https://toolbox.googleapps.com/apps/messageheader/) and Microsoft's Message Header Analyzer
|
|
122
|
+
(header and delivery-path viewers). PhishLens differs by running fully offline with no dependencies,
|
|
123
|
+
combining header, link, attachment and language checks into one scored report, and explaining each finding
|
|
124
|
+
for non-specialists.
|
|
125
|
+
|
|
126
|
+
## Project layout
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
phishlens/
|
|
130
|
+
parser.py raw email -> headers, bodies, links, attachments
|
|
131
|
+
domains.py registrable domains, punycode, look-alike detection
|
|
132
|
+
checks.py the individual checks and their point values
|
|
133
|
+
analyzer.py scoring, verdicts and text / Markdown / JSON reports
|
|
134
|
+
corpus.py synthetic dev and held-out test emails
|
|
135
|
+
evaluation.py precision, recall and baseline comparison
|
|
136
|
+
cli.py command-line interface
|
|
137
|
+
samples/ example .eml files
|
|
138
|
+
tests/ pytest suite
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Citation
|
|
142
|
+
|
|
143
|
+
If you use PhishLens, please cite it using the metadata in
|
|
144
|
+
[CITATION.cff](https://github.com/arpitahaque/phishlens/blob/main/CITATION.cff).
|
|
145
|
+
|
|
146
|
+
## Author
|
|
147
|
+
|
|
148
|
+
**Arpita Haque** - B.S. Computer Information Technology (cybersecurity minor), Minnesota State University
|
|
149
|
+
Moorhead. [GitHub](https://github.com/arpitahaque) · [ORCID](https://orcid.org/0009-0001-7853-3611)
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
MIT
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""PhishLens: explainable, offline phishing email analysis."""
|
|
2
|
+
|
|
3
|
+
from .analyzer import Report, analyze, analyze_bytes, analyze_file
|
|
4
|
+
from .checks import Finding
|
|
5
|
+
from .parser import ParsedEmail, parse_bytes, parse_file
|
|
6
|
+
|
|
7
|
+
__version__ = "0.1.0"
|
|
8
|
+
__all__ = [
|
|
9
|
+
"Report", "Finding", "ParsedEmail",
|
|
10
|
+
"analyze", "analyze_bytes", "analyze_file", "parse_bytes", "parse_file",
|
|
11
|
+
"__version__",
|
|
12
|
+
]
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Combine check findings into a score, a verdict and a readable report."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from dataclasses import asdict, dataclass
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from .checks import ALL_CHECKS, Finding, auth_results
|
|
10
|
+
from .parser import ParsedEmail, parse_bytes, parse_file
|
|
11
|
+
|
|
12
|
+
SUSPICIOUS_AT = 25
|
|
13
|
+
PHISHING_AT = 55
|
|
14
|
+
|
|
15
|
+
VERDICTS = {
|
|
16
|
+
"low": "Low risk",
|
|
17
|
+
"suspicious": "Suspicious",
|
|
18
|
+
"phishing": "Likely phishing",
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
ADVICE = {
|
|
22
|
+
"low": "No strong warning signs. Still verify anything unexpected that asks for money or logins.",
|
|
23
|
+
"suspicious": "Be careful. Do not click links or open attachments; contact the sender through a known channel.",
|
|
24
|
+
"phishing": "Treat this as phishing. Do not click, reply or open attachments. Report it to your IT or security team.",
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class Report:
|
|
30
|
+
subject: str
|
|
31
|
+
sender: str
|
|
32
|
+
score: int
|
|
33
|
+
verdict: str
|
|
34
|
+
findings: list[Finding]
|
|
35
|
+
authentication: dict[str, str]
|
|
36
|
+
links: int
|
|
37
|
+
attachments: int
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def label(self) -> str:
|
|
41
|
+
return VERDICTS[self.verdict]
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def advice(self) -> str:
|
|
45
|
+
return ADVICE[self.verdict]
|
|
46
|
+
|
|
47
|
+
def to_dict(self) -> dict:
|
|
48
|
+
d = asdict(self)
|
|
49
|
+
d["label"] = self.label
|
|
50
|
+
d["advice"] = self.advice
|
|
51
|
+
return d
|
|
52
|
+
|
|
53
|
+
def to_json(self) -> str:
|
|
54
|
+
return json.dumps(self.to_dict(), indent=2)
|
|
55
|
+
|
|
56
|
+
def to_text(self) -> str:
|
|
57
|
+
bar = "#" * (self.score // 5) + "." * (20 - self.score // 5)
|
|
58
|
+
lines = [
|
|
59
|
+
f"Subject : {self.subject}",
|
|
60
|
+
f"From : {self.sender}",
|
|
61
|
+
f"Auth : " + (", ".join(f"{k.upper()}={v}" for k, v in self.authentication.items()) or "not available"),
|
|
62
|
+
f"Risk : [{bar}] {self.score}/100 -> {self.label.upper()}",
|
|
63
|
+
"",
|
|
64
|
+
]
|
|
65
|
+
scored = [f for f in self.findings if f.points]
|
|
66
|
+
if not scored:
|
|
67
|
+
lines.append("No warning signs found.")
|
|
68
|
+
for f in sorted(scored, key=lambda x: -x.points):
|
|
69
|
+
lines.append(f" +{f.points:<3} [{f.category}] {f.title}")
|
|
70
|
+
lines.append(f" {f.detail}")
|
|
71
|
+
for f in self.findings:
|
|
72
|
+
if not f.points:
|
|
73
|
+
lines.append(f" note {f.title}: {f.detail}")
|
|
74
|
+
lines += ["", f"Advice : {self.advice}"]
|
|
75
|
+
return "\n".join(lines)
|
|
76
|
+
|
|
77
|
+
def to_markdown(self) -> str:
|
|
78
|
+
lines = [
|
|
79
|
+
f"# PhishLens report: {self.label}",
|
|
80
|
+
"",
|
|
81
|
+
f"| | |", "|---|---|",
|
|
82
|
+
f"| **Subject** | {self.subject} |",
|
|
83
|
+
f"| **From** | {self.sender} |",
|
|
84
|
+
f"| **Authentication** | " + (", ".join(f"{k.upper()} {v}" for k, v in self.authentication.items()) or "not available") + " |",
|
|
85
|
+
f"| **Risk score** | **{self.score}/100** ({self.label}) |",
|
|
86
|
+
f"| **Links / attachments** | {self.links} / {self.attachments} |",
|
|
87
|
+
"",
|
|
88
|
+
"## Findings",
|
|
89
|
+
"",
|
|
90
|
+
]
|
|
91
|
+
scored = sorted((f for f in self.findings if f.points), key=lambda x: -x.points)
|
|
92
|
+
if scored:
|
|
93
|
+
lines += ["| Points | Category | Finding | Why it matters |", "|---:|---|---|---|"]
|
|
94
|
+
lines += [f"| +{f.points} | {f.category} | {f.title} | {f.detail} |" for f in scored]
|
|
95
|
+
else:
|
|
96
|
+
lines.append("No warning signs found.")
|
|
97
|
+
notes = [f for f in self.findings if not f.points]
|
|
98
|
+
if notes:
|
|
99
|
+
lines += ["", "**Notes:** " + " ".join(f"{f.title}. {f.detail}" for f in notes)]
|
|
100
|
+
lines += ["", f"## Advice", "", self.advice, ""]
|
|
101
|
+
return "\n".join(lines)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def verdict_for(score: int) -> str:
|
|
105
|
+
if score >= PHISHING_AT:
|
|
106
|
+
return "phishing"
|
|
107
|
+
if score >= SUSPICIOUS_AT:
|
|
108
|
+
return "suspicious"
|
|
109
|
+
return "low"
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def analyze(email: ParsedEmail) -> Report:
|
|
113
|
+
findings: list[Finding] = []
|
|
114
|
+
for check in ALL_CHECKS:
|
|
115
|
+
findings.extend(check(email))
|
|
116
|
+
score = min(100, sum(f.points for f in findings))
|
|
117
|
+
sender = f"{email.from_name} <{email.from_addr}>" if email.from_name else email.from_addr
|
|
118
|
+
return Report(
|
|
119
|
+
subject=email.subject,
|
|
120
|
+
sender=sender,
|
|
121
|
+
score=score,
|
|
122
|
+
verdict=verdict_for(score),
|
|
123
|
+
findings=findings,
|
|
124
|
+
authentication=auth_results(email),
|
|
125
|
+
links=len(email.links),
|
|
126
|
+
attachments=len(email.attachments),
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def analyze_bytes(raw: bytes) -> Report:
|
|
131
|
+
return analyze(parse_bytes(raw))
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def analyze_file(path: str | Path) -> Report:
|
|
135
|
+
return analyze(parse_file(path))
|